11// Copyright (c) 2018 Senseye Ltd. All rights reserved.
22// Use of this source code is governed by the MIT License that can be found in the LICENSE file.
33
4+ //go:build integration
45// +build integration
56
67package mbgo_test
@@ -138,7 +139,7 @@ func TestClient_Create_Integration(t *testing.T) {
138139 Predicates : []mbgo.Predicate {
139140 {
140141 Operator : "equals" ,
141- Request : mbgo.HTTPRequest {
142+ Request : & mbgo.HTTPRequest {
142143 Method : http .MethodGet ,
143144 Path : "/foo" ,
144145 Query : map [string ][]string {
@@ -153,7 +154,7 @@ func TestClient_Create_Integration(t *testing.T) {
153154 Responses : []mbgo.Response {
154155 {
155156 Type : "is" ,
156- Value : mbgo.HTTPResponse {
157+ Value : & mbgo.HTTPResponse {
157158 StatusCode : http .StatusOK ,
158159 Headers : map [string ][]string {
159160 "Content-Type" : {"application/json" },
@@ -214,7 +215,7 @@ func TestClient_Create_Integration(t *testing.T) {
214215 Responses : []mbgo.Response {
215216 {
216217 Type : "is" ,
217- Value : mbgo.TCPResponse {
218+ Value : & mbgo.TCPResponse {
218219 Data : "c2Vjb25kIHJlc3BvbnNl" ,
219220 },
220221 },
@@ -223,6 +224,129 @@ func TestClient_Create_Integration(t *testing.T) {
223224 },
224225 },
225226 },
227+ {
228+ Description : "should support nested logical predicates" ,
229+ Input : mbgo.Imposter {
230+ Proto : "http" ,
231+ Port : 8080 ,
232+ Name : "create_test_predicate_nested_logical" ,
233+ Stubs : []mbgo.Stub {
234+ {
235+ Predicates : []mbgo.Predicate {
236+ {
237+ Operator : "or" ,
238+ Request : []mbgo.Predicate {
239+ {
240+ Operator : "equals" ,
241+ Request : mbgo.HTTPRequest {
242+ Method : http .MethodPost ,
243+ Path : "/foo" ,
244+ },
245+ },
246+ {
247+ Operator : "equals" ,
248+ Request : mbgo.HTTPRequest {
249+ Method : http .MethodPost ,
250+ Path : "/bar" ,
251+ },
252+ },
253+ {
254+ Operator : "and" ,
255+ Request : []mbgo.Predicate {
256+ {
257+ Operator : "equals" ,
258+ Request : mbgo.HTTPRequest {
259+ Method : http .MethodPost ,
260+ Path : "/baz" ,
261+ },
262+ },
263+ {
264+ Operator : "equals" ,
265+ Request : mbgo.HTTPRequest {
266+ Body : "foo" ,
267+ },
268+ },
269+ },
270+ },
271+ },
272+ },
273+ },
274+ Responses : []mbgo.Response {
275+ {
276+ Type : "is" ,
277+ Value : mbgo.HTTPResponse {
278+ StatusCode : http .StatusOK ,
279+ },
280+ },
281+ },
282+ },
283+ },
284+ },
285+ Before : func (t * testing.T , mb * mbgo.Client ) {
286+ _ , err := mb .Delete (newContext (time .Second ), 8080 , false )
287+ assert .MustOk (t , err )
288+ },
289+ After : func (t * testing.T , mb * mbgo.Client ) {
290+ _ , err := mb .Delete (newContext (time .Second ), 8080 , false )
291+ assert .MustOk (t , err )
292+ },
293+ Expected : & mbgo.Imposter {
294+ Proto : "http" ,
295+ Port : 8080 ,
296+ Name : "create_test_predicate_nested_logical" ,
297+ Stubs : []mbgo.Stub {
298+ {
299+ Predicates : []mbgo.Predicate {
300+ {
301+ Operator : "or" ,
302+ Request : []mbgo.Predicate {
303+ {
304+ Operator : "equals" ,
305+ Request : & mbgo.HTTPRequest {
306+ Method : http .MethodPost ,
307+ Path : "/foo" ,
308+ },
309+ },
310+ {
311+ Operator : "equals" ,
312+ Request : & mbgo.HTTPRequest {
313+ Method : http .MethodPost ,
314+ Path : "/bar" ,
315+ },
316+ },
317+ {
318+ Operator : "and" ,
319+ Request : []mbgo.Predicate {
320+ {
321+ Operator : "equals" ,
322+ Request : & mbgo.HTTPRequest {
323+ Method : http .MethodPost ,
324+ Path : "/baz" ,
325+ },
326+ },
327+ {
328+ Operator : "equals" ,
329+ Request : & mbgo.HTTPRequest {
330+ Body : "foo" ,
331+ },
332+ },
333+ },
334+ },
335+ },
336+ },
337+ },
338+ Responses : []mbgo.Response {
339+ {
340+ Type : "is" ,
341+ Value : & mbgo.HTTPResponse {
342+ StatusCode : http .StatusOK ,
343+ },
344+ },
345+ },
346+ },
347+ },
348+ },
349+ },
226350 }
227351
228352 for _ , c := range cases {
@@ -325,15 +449,15 @@ func TestClient_Imposter_Integration(t *testing.T) {
325449 Predicates : []mbgo.Predicate {
326450 {
327451 Operator : "endsWith" ,
328- Request : mbgo.TCPRequest {
452+ Request : & mbgo.TCPRequest {
329453 Data : "SGVsbG8sIHdvcmxkIQ==" ,
330454 },
331455 },
332456 },
333457 Responses : []mbgo.Response {
334458 {
335459 Type : "is" ,
336- Value : mbgo.TCPResponse {
460+ Value : & mbgo.TCPResponse {
337461 Data : "Z2l0aHViLmNvbS9zZW5zZXllaW8vbWJnbw==" ,
338462 },
339463 },
@@ -449,15 +573,15 @@ func TestClient_AddStub_Integration(t *testing.T) {
449573 Predicates : []mbgo.Predicate {
450574 {
451575 Operator : "endsWith" ,
452- Request : mbgo.TCPRequest {
576+ Request : & mbgo.TCPRequest {
453577 Data : "foo" ,
454578 },
455579 },
456580 },
457581 Responses : []mbgo.Response {
458582 {
459583 Type : "is" ,
460- Value : mbgo.TCPResponse {
584+ Value : & mbgo.TCPResponse {
461585 Data : "bar" ,
462586 },
463587 },
@@ -467,15 +591,15 @@ func TestClient_AddStub_Integration(t *testing.T) {
467591 Predicates : []mbgo.Predicate {
468592 {
469593 Operator : "endsWith" ,
470- Request : mbgo.TCPRequest {
594+ Request : & mbgo.TCPRequest {
471595 Data : "SGVsbG8sIHdvcmxkIQ==" ,
472596 },
473597 },
474598 },
475599 Responses : []mbgo.Response {
476600 {
477601 Type : "is" ,
478- Value : mbgo.TCPResponse {
602+ Value : & mbgo.TCPResponse {
479603 Data : "Z2l0aHViLmNvbS9zZW5zZXllaW8vbWJnbw==" ,
480604 },
481605 },
@@ -593,15 +717,15 @@ func TestClient_OverwriteStub_Integration(t *testing.T) {
593717 Predicates : []mbgo.Predicate {
594718 {
595719 Operator : "endsWith" ,
596- Request : mbgo.TCPRequest {
720+ Request : & mbgo.TCPRequest {
597721 Data : "foo" ,
598722 },
599723 },
600724 },
601725 Responses : []mbgo.Response {
602726 {
603727 Type : "is" ,
604- Value : mbgo.TCPResponse {
728+ Value : & mbgo.TCPResponse {
605729 Data : "bar" ,
606730 },
607731 },
@@ -737,15 +861,15 @@ func TestClient_OverwriteAllStubs_Integration(t *testing.T) {
737861 Predicates : []mbgo.Predicate {
738862 {
739863 Operator : "endsWith" ,
740- Request : mbgo.TCPRequest {
864+ Request : & mbgo.TCPRequest {
741865 Data : "foo" ,
742866 },
743867 },
744868 },
745869 Responses : []mbgo.Response {
746870 {
747871 Type : "is" ,
748- Value : mbgo.TCPResponse {
872+ Value : & mbgo.TCPResponse {
749873 Data : "bar" ,
750874 },
751875 },
@@ -755,15 +879,15 @@ func TestClient_OverwriteAllStubs_Integration(t *testing.T) {
755879 Predicates : []mbgo.Predicate {
756880 {
757881 Operator : "endsWith" ,
758- Request : mbgo.TCPRequest {
882+ Request : & mbgo.TCPRequest {
759883 Data : "bar" ,
760884 },
761885 },
762886 },
763887 Responses : []mbgo.Response {
764888 {
765889 Type : "is" ,
766- Value : mbgo.TCPResponse {
890+ Value : & mbgo.TCPResponse {
767891 Data : "baz" ,
768892 },
769893 },
0 commit comments