forked from durmaze/gobank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stub_test.go
97 lines (68 loc) · 2.54 KB
/
stub_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package gobank_test
import (
"encoding/json"
"github.com/durmaze/gobank"
"github.com/durmaze/gobank/predicates"
"github.com/durmaze/gobank/responses"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"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() {
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))
})
It("should create a Stub that has \"Is\" Response", func() {
resps := actualStubAsMap["responses"].([]interface{})
Expect(resps[0]).To(HaveKey(responses.Is().Build().Type()))
})
It("should create a Stub that has two Predicates", func() {
predicates := actualStubAsMap["predicates"]
Expect(predicates).To(HaveLen(2))
})
It("should create a Stub that has an \"Equals\" Predicate", func() {
preds := actualStubAsMap["predicates"].([]interface{})
Expect(preds[0]).To(HaveKey(predicates.Equals().Build().Type()))
})
It("should create a Stub that has a \"Contains\" Predicate", func() {
preds := actualStubAsMap["predicates"].([]interface{})
Expect(preds[1]).To(HaveKey(predicates.Contains().Build().Type()))
})
})
})