import (
	. "github.com/frodenas/brokerapi"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/frodenas/brokerapi/matchers"
)

var _ = Describe("Error Response", func() {
	Describe("JSON encoding", func() {
		It("has a description field", func() {
			errorResponse := ErrorResponse{}
			json := `{"description":""}`

			Expect(errorResponse).To(matchers.MarshalToJSON(json))
		})

		Context("when an error is present", func() {
			It("has an error field", func() {
				errorResponse := ErrorResponse{
					Error:       "an error happened",
					Description: "a bad thing happened",
				}
				json := `{"error":"an error happened","description":"a bad thing happened"}`

				Expect(errorResponse).To(matchers.MarshalToJSON(json))
			})
		})
	})
})
Пример #2
0
		service1 = Service{ID: "Service-1", Plans: []ServicePlan{plan1}}
		service2 = Service{ID: "Service-2", Plans: []ServicePlan{plan2}}

		catalog Catalog
	)

	Describe("JSON encoding", func() {
		BeforeEach(func() {
			catalog = Catalog{}
		})

		It("uses the correct keys", func() {
			json := `{"services":null}`

			Expect(catalog).To(matchers.MarshalToJSON(json))
		})
	})

	Describe("Validate", func() {
		BeforeEach(func() {
			catalog = Catalog{}
		})

		It("does not return error if all fields are valid", func() {
			err := catalog.Validate()

			Expect(err).ToNot(HaveOccurred())
		})

		It("returns error if Services are not valid", func() {