예제 #1
0
파일: and_test.go 프로젝트: durmaze/gobank
import (
	"encoding/json"
	"sync"

	"github.com/durmaze/gobank/predicates"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("And Predicate Builder Tests", func() {
	Describe("When building a Predicate of type \"And\"", func() {

		var (
			actualPredicateAsMap map[string]interface{}
			predicate1           = predicates.Equals().Build()
			predicate2           = predicates.Contains().Build()
			predicate3           = predicates.Equals().Build()

			once sync.Once
		)
		BeforeEach(func() {
			once.Do(func() {
				actualPredicate := predicates.And().Predicates(predicate1, predicate2, predicate3).Build()

				jsonBytes, _ := json.Marshal(actualPredicate)

				actualPredicateAsMap = map[string]interface{}{}
				json.Unmarshal(jsonBytes, &actualPredicateAsMap)

			})
예제 #2
0
		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)
			})
		})

		It("should have the Imposter installed on Mountebank", func() {
예제 #3
0
파일: stub_test.go 프로젝트: durmaze/gobank
			Expect(responses).To(HaveLen(1))
		})
	})

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

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

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

				expectedPredicate1 := predicates.Equals().Path("/test-path").Build()
				expectedPredicate2 := predicates.Contains().Method("POST").Build()

				actualStub := gobank.Stub().Responses(expectedResponse).Predicates(expectedPredicate1, expectedPredicate2).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))
		})
예제 #4
0
			actualPredicateAsMap map[string]interface{}

			expectedPath            = "/testing/path"
			expectedMethod          = "GET"
			expectedHeader          = "Content-Type"
			expectedHeaderValue     = "application/json"
			expectedBody            = "{ \"greeting\": \"Hello GoBank\" }"
			expectedQueryParam      = "qp"
			expectedQueryParamValue = "testValue"

			once sync.Once
		)

		BeforeEach(func() {
			once.Do(func() {
				actualPredicate := predicates.Equals().
					Path(expectedPath).
					Method(expectedMethod).
					Header(expectedHeader, expectedHeaderValue).
					Query(expectedQueryParam, expectedQueryParamValue).
					Body(expectedBody).
					Build()

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

				// marshalResult := NewMarshaller(actualPredicate).ToJson()
				// actualPredicateAsMap = marshalResult.ToMap()
			})
		})
예제 #5
0
파일: not_test.go 프로젝트: durmaze/gobank
import (
	"encoding/json"
	"sync"

	"github.com/durmaze/gobank/predicates"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Not Predicate Builder Tests", func() {
	Describe("When building a Predicate of type \"Not\"", func() {

		var (
			actualPredicateAsMap map[string]interface{}
			predicate            = predicates.Equals().Build()

			once sync.Once
		)
		BeforeEach(func() {
			once.Do(func() {
				actualPredicate := predicates.Not().Predicate(predicate).Build()

				jsonBytes, _ := json.Marshal(actualPredicate)

				actualPredicateAsMap = map[string]interface{}{}
				json.Unmarshal(jsonBytes, &actualPredicateAsMap)

			})
		})