Ejemplo n.º 1
0
	"sync"
)

var _ = Describe("Stub Builder Tests", func() {

	Describe("When building a Stub with single Response", func() {
		var (
			actualStubAsMap map[string]interface{}
			once            sync.Once
		)

		BeforeEach(func() {
			once.Do(func() {

				expectedResponse := responses.Is().StatusCode(200).Body("{ \"greeting\": \"Hello GoBank\" }").Build()
				actualStub := gobank.Stub().Responses(expectedResponse).Build()

				jsonBytes, _ := json.Marshal(actualStub)
				actualStubAsMap = map[string]interface{}{}
				json.Unmarshal(jsonBytes, &actualStubAsMap)
			})
		})

		It("should create a Stub that has one Response", func() {
			responses := actualStubAsMap["responses"]

			Expect(responses).To(HaveLen(1))
		})
	})
Ejemplo n.º 2
0
	Describe("When createImposter request is sent to Mountebank", func() {

		var (
			protocol         = "http"
			port             = 4546
			createdImposter  map[string]interface{}
			expectedImposter gobank.ImposterElement
			err              error

			once sync.Once
		)

		BeforeEach(func() {
			once.Do(func() {
				okResponse := responses.Is().StatusCode(200).Body("{ \"greeting\": \"Hello GoBank\" }").Build()

				equals := predicates.Equals().Path("/test-path").Build()
				contains := predicates.Contains().Header("Accept", "application/json").Build()
				exists := predicates.Exists().Method(true).Query("q", false).Body(false).Build()
				or := predicates.Or().Predicates(equals, contains, exists).Build()

				stub := gobank.Stub().Responses(okResponse).Predicates(or).Build()

				expectedImposter = gobank.NewImposterBuilder().Protocol(protocol).Port(port).Name("Greeting Imposter").Stubs(stub).Build()

				client := gobank.NewClient(MountebankUri)
				createdImposter, err = client.CreateImposter(expectedImposter)
				log.Println("ActualImposter: ", createdImposter)
			})
		})
Ejemplo n.º 3
0
	Describe("When building a Response of type \"Is\"", func() {

		var (
			actualResponseAsMap map[string]interface{}

			expectedStatusCode  = http.StatusOK
			expectedHeader      = "Content-Type"
			expectedHeaderValue = "application/json"
			expectedBody        = "{ \"greeting\": \"Hello GoBank\" }"

			once sync.Once
		)

		BeforeEach(func() {
			once.Do(func() {
				actualResponse := responses.Is().StatusCode(expectedStatusCode).Header(expectedHeader, expectedHeaderValue).Body(expectedBody).Build()

				jsonBytes, _ := json.Marshal(actualResponse)
				actualResponseAsMap = map[string]interface{}{}
				json.Unmarshal(jsonBytes, &actualResponseAsMap)
			})
		})

		It("should create an \"Is\" response", func() {
			Expect(actualResponseAsMap).To(HaveKey("is"))
		})

		It("should create a Response with the correct StatusCode", func() {
			isResponse := actualResponseAsMap["is"]

			// golang converts numbers to float64 when unmarshalling json to map[string]interface{}