@@ -66,6 +66,69 @@ var _ = Describe("Running Hoverfly in various modes", func() {
66
66
})
67
67
})
68
68
69
+ Context ("When running in spy mode" , func () {
70
+
71
+ var fakeServer * httptest.Server
72
+
73
+ Context ("Without middleware" , func () {
74
+
75
+ BeforeEach (func () {
76
+ hoverfly .Start ()
77
+
78
+ fakeServer = httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
79
+ w .Header ().Set ("Content-Type" , "text/plain" )
80
+ w .Header ().Set ("Date" , "date" )
81
+ w .Write ([]byte ("Hello world" ))
82
+ }))
83
+
84
+ hoverfly .SetMode ("spy" )
85
+ hoverfly .ImportSimulation (`{
86
+ "data": {
87
+ "pairs": [
88
+ {
89
+ "request" : {
90
+ "headers" : {
91
+ "X-API-TEST" : [ {
92
+ "value" : "test",
93
+ "matcher" : "exact"
94
+ } ]
95
+ }
96
+ },
97
+ "response": {
98
+ "status": 200,
99
+ "body": "Simulated"
100
+ }
101
+ }
102
+ ]
103
+ },
104
+ "meta": {
105
+ "schemaVersion": "v5"
106
+ }
107
+ }` )
108
+ })
109
+
110
+ AfterEach (func () {
111
+ fakeServer .Close ()
112
+ })
113
+
114
+ It ("Should forward the request and get response from destination if match not found" , func () {
115
+ resp := hoverfly .Proxy (sling .New ().Get (fakeServer .URL ))
116
+ Expect (resp .StatusCode ).To (Equal (http .StatusOK ))
117
+ body , err := ioutil .ReadAll (resp .Body )
118
+ Expect (err ).To (BeNil ())
119
+ Expect (string (body )).To (Equal ("Hello world" ))
120
+ })
121
+
122
+ It ("Should simulate if match found" , func () {
123
+ resp := hoverfly .Proxy (sling .New ().Get (fakeServer .URL ).Set ("X-API-TEST" , "test" ))
124
+ Expect (resp .StatusCode ).To (Equal (http .StatusOK ))
125
+ body , err := ioutil .ReadAll (resp .Body )
126
+ Expect (err ).To (BeNil ())
127
+ Expect (string (body )).To (Equal ("Simulated" ))
128
+ })
129
+ })
130
+ })
131
+
69
132
Context ("When running in synthesise mode" , func () {
70
133
71
134
Context ("With middleware" , func () {
0 commit comments