diff --git a/core/matching/matchers/negation_match.go b/core/matching/matchers/negation_match.go index 41b22f2cb..d983f3eef 100644 --- a/core/matching/matchers/negation_match.go +++ b/core/matching/matchers/negation_match.go @@ -1,6 +1,6 @@ package matchers -var Negation = "negation" +var Negation = "negate" func NegationMatch(match interface{}, toMatch string) bool { matchString, ok := match.(string) diff --git a/functional-tests/core/ft_simulation_matching_test.go b/functional-tests/core/ft_simulation_matching_test.go index 9116a333e..3f3a2d61a 100644 --- a/functional-tests/core/ft_simulation_matching_test.go +++ b/functional-tests/core/ft_simulation_matching_test.go @@ -438,4 +438,30 @@ var _ = Describe(" When using different matchers", func() { }) }) + + Context("Using negate match", func() { + + BeforeEach(func() { + hoverfly.ImportSimulation(testdata.NegationMatch) + }) + + It("path should not match with different path passed", func() { + req := sling.New().Get("http://test.com/path2") + + response := hoverfly.Proxy(req) + Expect(response.StatusCode).To(Equal(200)) + + Expect(io.ReadAll(response.Body)).Should(Equal([]byte("destination matched"))) + }) + + It("path should not match with no path passed", func() { + req := sling.New().Get("http://test.com") + + response := hoverfly.Proxy(req) + Expect(response.StatusCode).To(Equal(200)) + + Expect(io.ReadAll(response.Body)).Should(Equal([]byte("destination matched"))) + }) + + }) }) diff --git a/functional-tests/testdata/negation_match.go b/functional-tests/testdata/negation_match.go new file mode 100644 index 000000000..4ad4d8a5b --- /dev/null +++ b/functional-tests/testdata/negation_match.go @@ -0,0 +1,68 @@ +package testdata + +var NegationMatch = `{ + "data": { + "pairs": [ + { + "request": { + "path": [ + { + "matcher": "negate", + "value": "/path1" + } + ], + "method": [ + { + "matcher": "exact", + "value": "GET" + } + ], + "destination": [ + { + "matcher": "exact", + "value": "test.com" + } + ], + "scheme": [ + { + "matcher": "exact", + "value": "http" + } + ], + "deprecatedQuery": [ + { + "matcher": "exact", + "value": "" + } + ], + "body": [ + { + "matcher": "exact", + "value": "" + } + ] + }, + "response": { + "status": 200, + "body": "destination matched", + "encodedBody": false, + "headers": { + "Header": [ + "value1" + ] + }, + "templated": false + } + } + ], + "globalActions": { + "delays": [], + "delaysLogNormal": [] + } + }, + "meta": { + "schemaVersion": "v5", + "hoverflyVersion": "v0.17.0", + "timeExported": "2018-05-03T12:12:46+01:00" + } +}`