Exemple #1
0
	"github.com/durmaze/gobank"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

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

	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() {
Exemple #2
0
			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)
			})
		})

		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))
Exemple #3
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))
		})
	})

	Describe("When building a Stub with single Response and multiple, different Predicates", func() {