Ejemplo n.º 1
0
			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)
			})
		})

		It("should have the Imposter installed on Mountebank", func() {
			imposterUri := MountebankUri + "/imposters/" + strconv.Itoa(port)
			resp, body, _ := gorequest.New().Get(imposterUri).End()

			log.Println("Imposter from Mountebank. Body: ", body)
			Expect(resp.StatusCode).To(Equal(http.StatusOK))
		})
Ejemplo n.º 2
0
	Describe("When building an imposter with protocol, port, name, mode and a single stub", func() {
		var (
			actualImposterAsMap map[string]interface{}

			expectedProtocol = "http"
			expectedPort     = 4546
			expectedName     = "TestImposter"
			expectedMode     = "text"
			expectedStub     = gobank.Stub().Build()

			once sync.Once
		)

		BeforeEach(func() {
			once.Do(func() {
				actualImposter := gobank.NewImposterBuilder().Protocol(expectedProtocol).Port(expectedPort).Name(expectedName).Mode(expectedMode).Stubs(expectedStub).Build()

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

		It("should create the Imposter with the correct Protocol", func() {
			Expect(actualImposterAsMap).To(HaveKeyWithValue("protocol", expectedProtocol))
		})

		It("should create the Imposter with the correct Port", func() {
			// golang converts numbers to float64 when unmarshalling json to map[string]interface{}
			Expect(actualImposterAsMap).To(HaveKeyWithValue("port", float64(expectedPort)))
		})