From cda74d6234f5581c69ee3fb54e6f3447b26202ba Mon Sep 17 00:00:00 2001 From: Tommy Situ Date: Sun, 25 Feb 2024 18:00:30 +0000 Subject: [PATCH] Remove support for deprecatedQuery --- core/handlers/v2/simulation_views.go | 10 --- core/handlers/v2/simulation_views_test.go | 23 +++-- core/handlers/v2/simulation_views_upgrade.go | 47 +++++----- .../v2/simulation_views_upgrade_test.go | 46 ---------- core/handlers/v2/simulation_views_v5.go | 17 ++-- core/hoverfly_service_test.go | 1 - core/import.go | 4 - core/import_test.go | 30 ------- core/journal/journal.go | 17 ++-- core/journal/journal_test.go | 22 ----- core/matching/cache_matcher_test.go | 18 ---- core/matching/first_match_strategy_test.go | 50 +++-------- core/matching/matching_strategy_runner.go | 2 - .../matching/strongest_match_strategy_test.go | 85 ++++++------------- core/models/payload.go | 2 +- core/models/request_matcher.go | 72 ++++++---------- core/models/request_matcher_test.go | 34 +------- core/models/simulation_test.go | 16 ---- .../core/api/simulation_api_v2_test.go | 13 --- functional-tests/hoverctl/import_test.go | 78 ----------------- 20 files changed, 112 insertions(+), 475 deletions(-) diff --git a/core/handlers/v2/simulation_views.go b/core/handlers/v2/simulation_views.go index 880dfbdc5..9f8c1f8cd 100644 --- a/core/handlers/v2/simulation_views.go +++ b/core/handlers/v2/simulation_views.go @@ -168,8 +168,6 @@ func BuildSimulationView( } } -const deprecatedQueryMessage = "Usage of deprecated field `deprecatedQuery` on data.pairs[%v].request.deprecatedQuery, please update your simulation to use `query` field" -const deprecatedQueryDocs = "https://hoverfly.readthedocs.io/en/latest/pages/troubleshooting/troubleshooting.html#why-does-my-simulation-have-a-deprecatedquery-field" const ContentLengthAndTransferEncodingMessage = "Response contains both Content-Length and Transfer-Encoding headers on data.pairs[%v].response, please remove one of these headers" const BodyAndBodyFileMessage = "Response contains both `body` and `bodyFile` in data.pairs[%v].response, please remove one of them otherwise `body` is used if non empty" const ContentLengthMismatchMessage = "Response contains incorrect Content-Length header on data.pairs[%v].response, please correct or remove header" @@ -193,14 +191,6 @@ func (s SimulationImportResult) GetError() error { return s.Err } -func (s *SimulationImportResult) AddDeprecatedQueryWarning(requestNumber int) { - warning := fmt.Sprintf("WARNING: %s", fmt.Sprintf(deprecatedQueryMessage, requestNumber)) - if s.WarningMessages == nil { - s.WarningMessages = []SimulationImportWarning{} - } - s.WarningMessages = append(s.WarningMessages, SimulationImportWarning{Message: warning, DocsLink: deprecatedQueryDocs}) -} - func (s *SimulationImportResult) AddContentLengthAndTransferEncodingWarning(requestNumber int) { warning := fmt.Sprintf("WARNING: %s", fmt.Sprintf(ContentLengthAndTransferEncodingMessage, requestNumber)) if s.WarningMessages == nil { diff --git a/core/handlers/v2/simulation_views_test.go b/core/handlers/v2/simulation_views_test.go index ff3c7ef50..02408728f 100644 --- a/core/handlers/v2/simulation_views_test.go +++ b/core/handlers/v2/simulation_views_test.go @@ -56,7 +56,6 @@ func Test_NewSimulationViewFromRequestBody_CanCreateSimulationFromV3Payload(t *t Expect(simulation.RequestResponsePairs[0].RequestMatcher.Headers).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Method).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Path).To(HaveLen(0)) - Expect(simulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Scheme).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].Response.Body).To(Equal("exact match")) @@ -123,7 +122,6 @@ func Test_NewSimulationViewFromRequestBody_CanCreateSimulationFromV2Payload(t *t Expect(simulation.RequestResponsePairs[0].RequestMatcher.Headers).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Method).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Path).To(HaveLen(0)) - Expect(simulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Scheme).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].Response.Body).To(Equal("exact match")) @@ -221,7 +219,6 @@ func Test_NewSimulationViewFromRequestBody_CanCreateSimulationFromV1Payload(t *t Expect(simulation.RequestResponsePairs[0].RequestMatcher.Headers).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Method).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Path).To(HaveLen(0)) - Expect(simulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Scheme).To(HaveLen(0)) Expect(simulation.RequestResponsePairs[0].Response.Body).To(Equal("exact match")) @@ -326,28 +323,28 @@ func Test_NewSimulationViewFromRequestBody_WontCreateSimulationFromInvalidJson(t Expect(simulation.GlobalActions.DelaysLogNormal).To(HaveLen(0)) } -func Test_SimulationImportResult_AddDeprecatedQueryWarning_AddsWarning(t *testing.T) { +func Test_SimulationImportResult_AddPairIgnoredWarning_AddsWarning(t *testing.T) { RegisterTestingT(t) unit := v2.SimulationImportResult{} - unit.AddDeprecatedQueryWarning(15) + unit.AddPairIgnoredWarning(15) Expect(unit.WarningMessages).To(HaveLen(1)) Expect(unit.WarningMessages[0].Message).To(ContainSubstring("WARNING")) - Expect(unit.WarningMessages[0].Message).To(ContainSubstring("deprecatedQuery")) - Expect(unit.WarningMessages[0].Message).To(ContainSubstring("data.pairs[15].request.deprecatedQuery")) + Expect(unit.WarningMessages[0].Message).To(ContainSubstring("conflict with the existing simulation")) + Expect(unit.WarningMessages[0].Message).To(ContainSubstring("data.pairs[15]")) } func Test_SimulationImportResult_WriteResponse_IncludesMultipleWarnings(t *testing.T) { RegisterTestingT(t) unit := v2.SimulationImportResult{} - unit.AddDeprecatedQueryWarning(15) - unit.AddDeprecatedQueryWarning(30) - unit.AddDeprecatedQueryWarning(45) + unit.AddPairIgnoredWarning(15) + unit.AddPairIgnoredWarning(30) + unit.AddPairIgnoredWarning(45) - Expect(unit.WarningMessages[0].Message).To(ContainSubstring("data.pairs[15].request.deprecatedQuery")) - Expect(unit.WarningMessages[1].Message).To(ContainSubstring("data.pairs[30].request.deprecatedQuery")) - Expect(unit.WarningMessages[2].Message).To(ContainSubstring("data.pairs[45].request.deprecatedQuery")) + Expect(unit.WarningMessages[0].Message).To(ContainSubstring("data.pairs[15]")) + Expect(unit.WarningMessages[1].Message).To(ContainSubstring("data.pairs[30]")) + Expect(unit.WarningMessages[2].Message).To(ContainSubstring("data.pairs[45]")) } diff --git a/core/handlers/v2/simulation_views_upgrade.go b/core/handlers/v2/simulation_views_upgrade.go index 545ac0e47..f85f13bdb 100644 --- a/core/handlers/v2/simulation_views_upgrade.go +++ b/core/handlers/v2/simulation_views_upgrade.go @@ -110,14 +110,13 @@ func upgradeV1(originalSimulation SimulationViewV1) SimulationViewV5 { pair := RequestMatcherResponsePairViewV5{ RequestMatcher: RequestMatcherViewV5{ - Scheme: schemeMatchers, - Method: methodMatchers, - Destination: destinationMatchers, - Path: pathMatchers, - Body: bodyMatchers, - Headers: headersWithMatchers, - RequiresState: nil, - DeprecatedQuery: queryMatchers, + Scheme: schemeMatchers, + Method: methodMatchers, + Destination: destinationMatchers, + Path: pathMatchers, + Body: bodyMatchers, + Headers: headersWithMatchers, + RequiresState: nil, }, Response: ResponseDetailsViewV5{ Body: pairV1.Response.Body, @@ -178,14 +177,13 @@ func upgradeV2(originalSimulation SimulationViewV2) SimulationViewV5 { requestResponsePair := RequestMatcherResponsePairViewV5{ RequestMatcher: RequestMatcherViewV5{ - Destination: destinationMatchers, - Headers: headersWithMatchers, - Method: methodMatchers, - Path: pathMatchers, - Scheme: schemeMatchers, - Body: bodyMatchers, - RequiresState: nil, - DeprecatedQuery: queryMatchers, + Destination: destinationMatchers, + Headers: headersWithMatchers, + Method: methodMatchers, + Path: pathMatchers, + Scheme: schemeMatchers, + Body: bodyMatchers, + RequiresState: nil, }, Response: ResponseDetailsViewV5{ Body: requestResponsePairV2.Response.Body, @@ -265,15 +263,14 @@ func upgradeV4(originalSimulation SimulationViewV4) SimulationViewV5 { requestResponsePair := RequestMatcherResponsePairViewV5{ RequestMatcher: RequestMatcherViewV5{ - Destination: destinationMatchers, - Method: methodMatchers, - Path: pathMatchers, - Scheme: schemeMatchers, - Body: bodyMatchers, - Headers: headersWithMatchers, - Query: queriesWithMatchers, - RequiresState: requestResponsePairV2.RequestMatcher.RequiresState, - DeprecatedQuery: queryMatchers, + Destination: destinationMatchers, + Method: methodMatchers, + Path: pathMatchers, + Scheme: schemeMatchers, + Body: bodyMatchers, + Headers: headersWithMatchers, + Query: queriesWithMatchers, + RequiresState: requestResponsePairV2.RequestMatcher.RequiresState, }, Response: ResponseDetailsViewV5{ Body: requestResponsePairV2.Response.Body, diff --git a/core/handlers/v2/simulation_views_upgrade_test.go b/core/handlers/v2/simulation_views_upgrade_test.go index 5a28629c3..1fd5b7652 100644 --- a/core/handlers/v2/simulation_views_upgrade_test.go +++ b/core/handlers/v2/simulation_views_upgrade_test.go @@ -77,10 +77,6 @@ func Test_upgradeV1_ReturnsAnUpgradedSimulation(t *testing.T) { Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path[0].Matcher).To(Equal(matchers.Exact)) Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path[0].Value).To(Equal("/path")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal(matchers.Exact)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("query=query")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Headers).To(HaveKeyWithValue("Test", []MatcherViewV5{ { Matcher: matchers.Glob, @@ -153,10 +149,6 @@ func Test_upgradeV1_HandlesTemplates(t *testing.T) { Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path[0].Matcher).To(Equal(matchers.Glob)) Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path[0].Value).To(Equal("/path")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal(matchers.Glob)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("query=query")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Headers).To(BeEmpty()) } func Test_upgradeV1_HandlesIncompleteRequest(t *testing.T) { @@ -191,7 +183,6 @@ func Test_upgradeV1_HandlesIncompleteRequest(t *testing.T) { Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Body).To(HaveLen(0)) Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Destination).To(HaveLen(0)) Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path).To(HaveLen(0)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(0)) Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Method).To(HaveLen(1)) Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Method[0].Matcher).To(Equal(matchers.Exact)) @@ -231,9 +222,6 @@ func Test_upgradeV1_Upgrade_UnescapesRequestQueryParameters(t *testing.T) { upgradedSimulation := upgradeV1(v1Simulation) Expect(upgradedSimulation.RequestResponsePairs).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal("exact")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("q=10 Downing Street London")) } func Test_upgradeV2_ReturnsAnUpgradedSimulation(t *testing.T) { @@ -304,10 +292,6 @@ func Test_upgradeV2_ReturnsAnUpgradedSimulation(t *testing.T) { Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path[0].Matcher).To(Equal("json")) Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path[0].Value).To(Equal("*")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal(matchers.Exact)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("query=query")) - Expect(upgradedSimulation.RequestResponsePairs[0].Response.BodyFile).To(Equal("")) Expect(upgradedSimulation.RequestResponsePairs[0].Response.Status).To(Equal(200)) Expect(upgradedSimulation.RequestResponsePairs[0].Response.Templated).To(BeFalse()) @@ -349,9 +333,6 @@ func Test_upgradeV2_UnescapesExactMatchRequestQueryParameters(t *testing.T) { upgradedSimulation := upgradeV2(v2Simulation) Expect(upgradedSimulation.RequestResponsePairs).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal(matchers.Exact)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("q=10 Downing Street London")) } func Test_upgradeV2_UnescapesGlobMatchRequestQueryParameters(t *testing.T) { @@ -383,10 +364,6 @@ func Test_upgradeV2_UnescapesGlobMatchRequestQueryParameters(t *testing.T) { upgradedSimulation := upgradeV2(v2Simulation) Expect(upgradedSimulation.RequestResponsePairs).To(HaveLen(1)) - - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal(matchers.Glob)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("q=* London")) } func Test_upgradeV2_Upgrade_KeepsEncodedResponsesEncoded(t *testing.T) { @@ -453,12 +430,6 @@ func Test_upgradeV2_HandlesMultipleMatchers(t *testing.T) { upgradedSimulation := upgradeV2(v2Simulation) Expect(upgradedSimulation.RequestResponsePairs).To(HaveLen(1)) - - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(2)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal(matchers.Exact)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("testexact")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[1].Matcher).To(Equal(matchers.Glob)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[1].Value).To(Equal("testglob")) } func Test_upgradeV4_ReturnsAnUpgradedSimulation(t *testing.T) { @@ -529,10 +500,6 @@ func Test_upgradeV4_ReturnsAnUpgradedSimulation(t *testing.T) { Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path[0].Matcher).To(Equal("json")) Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.Path[0].Value).To(Equal("*")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal("exact")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("query=query")) - Expect(upgradedSimulation.RequestResponsePairs[0].Response.BodyFile).To(Equal("")) Expect(upgradedSimulation.RequestResponsePairs[0].Response.Status).To(Equal(200)) Expect(upgradedSimulation.RequestResponsePairs[0].Response.Templated).To(BeFalse()) @@ -608,9 +575,6 @@ func Test_upgradeV4_UnescapesExactMatchRequestQueryParameters(t *testing.T) { upgradedSimulation := upgradeV4(v4Simulation) Expect(upgradedSimulation.RequestResponsePairs).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal("exact")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("q=10 Downing Street London")) } func Test_upgradeV4_UnescapesGlobMatchRequestQueryParameters(t *testing.T) { @@ -642,10 +606,6 @@ func Test_upgradeV4_UnescapesGlobMatchRequestQueryParameters(t *testing.T) { upgradedSimulation := upgradeV4(v4Simulation) Expect(upgradedSimulation.RequestResponsePairs).To(HaveLen(1)) - - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(1)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal("glob")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("q=* London")) } func Test_upgradeV4_HandlesMultipleMatchers(t *testing.T) { @@ -678,12 +638,6 @@ func Test_upgradeV4_HandlesMultipleMatchers(t *testing.T) { upgradedSimulation := upgradeV4(v4Simulation) Expect(upgradedSimulation.RequestResponsePairs).To(HaveLen(1)) - - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(HaveLen(2)) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal("exact")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("testexact")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[1].Matcher).To(Equal("glob")) - Expect(upgradedSimulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery[1].Value).To(Equal("testglob")) } func Test_upgradeV4_HandlesNewHeaders(t *testing.T) { diff --git a/core/handlers/v2/simulation_views_v5.go b/core/handlers/v2/simulation_views_v5.go index f7879cfd4..4b5579994 100644 --- a/core/handlers/v2/simulation_views_v5.go +++ b/core/handlers/v2/simulation_views_v5.go @@ -23,15 +23,14 @@ type RequestMatcherResponsePairViewV5 struct { // RequestDetailsView is used when marshalling and unmarshalling RequestDetails type RequestMatcherViewV5 struct { - Path []MatcherViewV5 `json:"path,omitempty"` - Method []MatcherViewV5 `json:"method,omitempty"` - Destination []MatcherViewV5 `json:"destination,omitempty"` - Scheme []MatcherViewV5 `json:"scheme,omitempty"` - Body []MatcherViewV5 `json:"body,omitempty"` - Headers map[string][]MatcherViewV5 `json:"headers,omitempty"` - Query *QueryMatcherViewV5 `json:"query,omitempty"` - RequiresState map[string]string `json:"requiresState,omitempty"` - DeprecatedQuery []MatcherViewV5 `json:"deprecatedQuery,omitempty"` + Path []MatcherViewV5 `json:"path,omitempty"` + Method []MatcherViewV5 `json:"method,omitempty"` + Destination []MatcherViewV5 `json:"destination,omitempty"` + Scheme []MatcherViewV5 `json:"scheme,omitempty"` + Body []MatcherViewV5 `json:"body,omitempty"` + Headers map[string][]MatcherViewV5 `json:"headers,omitempty"` + Query *QueryMatcherViewV5 `json:"query,omitempty"` + RequiresState map[string]string `json:"requiresState,omitempty"` } type QueryMatcherViewV5 map[string][]MatcherViewV5 diff --git a/core/hoverfly_service_test.go b/core/hoverfly_service_test.go index 395758410..81efcbb9c 100644 --- a/core/hoverfly_service_test.go +++ b/core/hoverfly_service_test.go @@ -162,7 +162,6 @@ func Test_Hoverfly_GetSimulation_ReturnsASingleRequestResponsePair(t *testing.T) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Destination[0].Value).To(Equal("test.com")) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Path).To(BeNil()) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Method).To(BeNil()) - Expect(simulation.RequestResponsePairs[0].RequestMatcher.DeprecatedQuery).To(BeNil()) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Scheme).To(BeNil()) Expect(simulation.RequestResponsePairs[0].RequestMatcher.Headers).To(HaveLen(0)) diff --git a/core/import.go b/core/import.go index 6ef9f8e1c..efaa1af9e 100644 --- a/core/import.go +++ b/core/import.go @@ -156,10 +156,6 @@ func (hf *Hoverfly) importRequestResponsePairViewsWithCustomData(pairViews []v2. importResult.AddPairIgnoredWarning(i) } - if pairView.RequestMatcher.DeprecatedQuery != nil && len(pairView.RequestMatcher.DeprecatedQuery) != 0 { - importResult.AddDeprecatedQueryWarning(i) - } - if len(pairView.Response.Headers["Content-Length"]) > 0 && len(pairView.Response.Headers["Transfer-Encoding"]) > 0 { importResult.AddContentLengthAndTransferEncodingWarning(i) } diff --git a/core/import_test.go b/core/import_test.go index 2e0eb7c3c..36331d8ee 100644 --- a/core/import_test.go +++ b/core/import_test.go @@ -729,36 +729,6 @@ func TestImportImportRequestResponsePairsMultipleTimes_SetsAllStates(t *testing. }).Should(Equal("1")) } -func TestImportImportRequestResponsePairs_ReturnsWarningsIfDeprecatedQuerytSet(t *testing.T) { - RegisterTestingT(t) - - cache := cache.NewDefaultLRUCache() - cfg := Configuration{Webserver: false} - cacheMatcher := matching.CacheMatcher{RequestCache: cache, Webserver: cfg.Webserver} - hv := Hoverfly{Cfg: &cfg, CacheMatcher: cacheMatcher, Simulation: models.NewSimulation(), templator: templating.NewTemplator(), PostServeActionDetails: action.NewPostServeActionDetails()} - - encodedPair := v2.RequestMatcherResponsePairViewV5{ - Response: v2.ResponseDetailsViewV5{ - Status: 200, - Body: base64String("hello_world"), - EncodedBody: true, - Headers: map[string][]string{"Content-Encoding": {"gzip"}}}, - RequestMatcher: v2.RequestMatcherViewV5{ - DeprecatedQuery: []v2.MatcherViewV5{ - { - Matcher: "exact", - Value: "deprecated", - }, - }, - }, - } - - result := hv.importRequestResponsePairViewsWithCustomData([]v2.RequestMatcherResponsePairViewV5{encodedPair}, []v2.GlobalLiteralViewV5{}, []v2.GlobalVariableViewV5{}) - - Expect(result.WarningMessages).To(HaveLen(1)) - Expect(result.WarningMessages[0].Message).To(ContainSubstring("data.pairs[0].request.deprecatedQuery")) -} - func TestImportImportRequestResponsePairs_ReturnsWarningsContentLengthAndTransferEncodingSet(t *testing.T) { RegisterTestingT(t) diff --git a/core/journal/journal.go b/core/journal/journal.go index 8b63e66fa..7368bee61 100644 --- a/core/journal/journal.go +++ b/core/journal/journal.go @@ -169,20 +169,19 @@ func (this *Journal) GetFilteredEntries(journalEntryFilterView v2.JournalEntryFi } requestMatcher := models.RequestMatcher{ - Path: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Path), - Method: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Method), - Destination: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Destination), - Scheme: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Scheme), - DeprecatedQuery: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.DeprecatedQuery), - Body: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Body), - Query: models.NewQueryRequestFieldMatchersFromMapView(journalEntryFilterView.Request.Query), - Headers: models.NewRequestFieldMatchersFromMapView(journalEntryFilterView.Request.Headers), + Path: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Path), + Method: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Method), + Destination: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Destination), + Scheme: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Scheme), + Body: models.NewRequestFieldMatchersFromView(journalEntryFilterView.Request.Body), + Query: models.NewQueryRequestFieldMatchersFromMapView(journalEntryFilterView.Request.Query), + Headers: models.NewRequestFieldMatchersFromMapView(journalEntryFilterView.Request.Headers), } for _, entry := range this.entries { if requestMatcher.Body == nil && requestMatcher.Destination == nil && requestMatcher.Headers == nil && requestMatcher.Method == nil && - requestMatcher.Path == nil && requestMatcher.DeprecatedQuery == nil && + requestMatcher.Path == nil && requestMatcher.Scheme == nil && requestMatcher.Query == nil { continue } diff --git a/core/journal/journal_test.go b/core/journal/journal_test.go index 76bebdb05..c9907ce0a 100644 --- a/core/journal/journal_test.go +++ b/core/journal/journal_test.go @@ -703,28 +703,6 @@ func Test_Journal_GetFilteredEntries_WillFilterOnRequestFields(t *testing.T) { }, })).To(HaveLen(0)) - Expect(unit.GetFilteredEntries(v2.JournalEntryFilterView{ - Request: &v2.RequestMatcherViewV5{ - DeprecatedQuery: []v2.MatcherViewV5{ - { - Matcher: matchers.Exact, - Value: "one=1&two=2", - }, - }, - }, - })).To(HaveLen(1)) - - Expect(unit.GetFilteredEntries(v2.JournalEntryFilterView{ - Request: &v2.RequestMatcherViewV5{ - DeprecatedQuery: []v2.MatcherViewV5{ - { - Matcher: matchers.Glob, - Value: "one=1*", - }, - }, - }, - })).To(HaveLen(1)) - // Scheme Expect(unit.GetFilteredEntries(v2.JournalEntryFilterView{ diff --git a/core/matching/cache_matcher_test.go b/core/matching/cache_matcher_test.go index a2c0ea6da..5d58a2986 100644 --- a/core/matching/cache_matcher_test.go +++ b/core/matching/cache_matcher_test.go @@ -133,12 +133,6 @@ func Test_CacheMatcher_PreloadCache_WillPreemptivelyCacheFullExactMatchRequestMa Value: "path", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "query", - }, - }, Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -301,12 +295,6 @@ func Test_CacheMatcher_PreloadCache_WillCheckAllRequestMatchersInSimulation(t *t Value: "path", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "query", - }, - }, Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -383,12 +371,6 @@ func Test_CacheMatcher_PreloadCache_WillNotCacheMatchersWithHeaders(t *testing.T Value: "path", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "query", - }, - }, Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, diff --git a/core/matching/first_match_strategy_test.go b/core/matching/first_match_strategy_test.go index 511800294..8c228b380 100644 --- a/core/matching/first_match_strategy_test.go +++ b/core/matching/first_match_strategy_test.go @@ -306,12 +306,6 @@ func Test_FirstMatchStrategy_EndpointMatchWithHeaders(t *testing.T) { Value: "GET", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "q=test", - }, - }, }, Response: testResponse, }) @@ -374,12 +368,6 @@ func Test_FirstMatchStrategy_EndpointMismatchWithHeadersReturnsNil(t *testing.T) Value: "GET", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "q=test", - }, - }, }, Response: testResponse, }) @@ -427,12 +415,6 @@ func Test_FirstMatchStrategy_AbleToMatchAnEmptyPathInAReasonableWay(t *testing.T Value: "GET", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "q=test", - }, - }, }, Response: testResponse, }) @@ -637,12 +619,6 @@ func Test_FirstMatchShouldNotBeCacheableIfMatchedOnEverythingApartFromHeadersAtL Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "foo=bar", - }, - }, Path: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -724,10 +700,12 @@ func Test_FirstMatchShouldBeCacheableIfMatchedOnEverythingApartFromHeadersZeroTi Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "?foo=bar", + Query: &models.QueryRequestFieldMatchers{ + "foo": []models.RequestFieldMatchers{ + { + Matcher: matchers.Exact, + Value: "bar", + }, }, }, Path: []models.RequestFieldMatchers{ @@ -915,12 +893,6 @@ func Test_FirstMatchShouldNotBeCacheableIfMatchedOnEverythingApartFromStateAtLea Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "foo=bar", - }, - }, Path: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -994,10 +966,12 @@ func Test_FirstMatchShouldBeCacheableIfMatchedOnEverythingApartFromStateZeroTime Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "?foo=bar", + Query: &models.QueryRequestFieldMatchers{ + "foo": []models.RequestFieldMatchers{ + { + Matcher: matchers.Exact, + Value: "bar", + }, }, }, Path: []models.RequestFieldMatchers{ diff --git a/core/matching/matching_strategy_runner.go b/core/matching/matching_strategy_runner.go index e4404ea4a..dfc2cc866 100644 --- a/core/matching/matching_strategy_runner.go +++ b/core/matching/matching_strategy_runner.go @@ -29,8 +29,6 @@ func MatchingStrategyRunner(req models.RequestDetails, webserver bool, simulatio strategy.Matching(FieldMatcher(requestMatcher.Path, req.Path), "path") - strategy.Matching(FieldMatcher(requestMatcher.DeprecatedQuery, req.QueryString()), "query") - strategy.Matching(FieldMatcher(requestMatcher.Method, req.Method), "method") strategy.Matching(HeaderMatching(requestMatcher, req.Headers), "headers") diff --git a/core/matching/strongest_match_strategy_test.go b/core/matching/strongest_match_strategy_test.go index 7899fb784..46da201d5 100644 --- a/core/matching/strongest_match_strategy_test.go +++ b/core/matching/strongest_match_strategy_test.go @@ -303,12 +303,6 @@ func Test_ClosestRequestMatcherRequestMatcher_EndpointMatchWithHeaders(t *testin Value: "GET", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "q=test", - }, - }, }, Response: testResponse, }) @@ -371,12 +365,6 @@ func Test_ClosestRequestMatcherRequestMatcher_EndpointMismatchWithHeadersReturns Value: "GET", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "q=test", - }, - }, }, Response: testResponse, }) @@ -424,12 +412,6 @@ func Test_ClosestRequestMatcherRequestMatcher_AbleToMatchAnEmptyPathInAReasonabl Value: "GET", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "q=test", - }, - }, }, Response: testResponse, }) @@ -807,12 +789,6 @@ func Test__NotBeCacheableIfMatchedOnEverythingApartFromHeadersAtLeastOnce(t *tes Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "foo=bar", - }, - }, Path: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -894,10 +870,12 @@ func Test__ShouldBeCacheableIfMatchedOnEverythingApartFromHeadersZeroTimes(t *te Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "?foo=bar", + Query: &models.QueryRequestFieldMatchers{ + "foo": []models.RequestFieldMatchers{ + { + Matcher: matchers.Exact, + Value: "bar", + }, }, }, Path: []models.RequestFieldMatchers{ @@ -1271,13 +1249,14 @@ func Test_ShouldReturnFieldsMissedInClosestMiss(t *testing.T) { Value: "hit", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "miss", + Query: &models.QueryRequestFieldMatchers{ + "foo": []models.RequestFieldMatchers{ + { + Matcher: matchers.Exact, + Value: "bar", + }, }, }, - Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -1312,7 +1291,7 @@ func Test_ShouldReturnFieldsMissedInClosestMiss(t *testing.T) { Expect(result.Pair).To(BeNil()) Expect(result.Error.ClosestMiss).ToNot(BeNil()) //TODO: Scheme matching? - Expect(result.Error.ClosestMiss.MissedFields).To(ConsistOf(`body`, `path`, `query`)) + Expect(result.Error.ClosestMiss.MissedFields).To(ConsistOf(`body`, `path`, `queries`)) } func Test_ShouldReturnFieldsMissedInClosestMissAgain(t *testing.T) { @@ -1346,12 +1325,6 @@ func Test_ShouldReturnFieldsMissedInClosestMissAgain(t *testing.T) { Value: "miss", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "hit=", - }, - }, Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -1600,12 +1573,6 @@ func Test_StrongestMatch_ShouldNotBeCacheableIfMatchedOnEverythingApartFromHeade Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "foo=bar", - }, - }, Path: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -1687,10 +1654,12 @@ func Test_StrongestMatch__ShouldBeCacheableIfMatchedOnEverythingApartFromHeaders Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "?foo=bar", + Query: &models.QueryRequestFieldMatchers{ + "foo": []models.RequestFieldMatchers{ + { + Matcher: matchers.Exact, + Value: "bar", + }, }, }, Path: []models.RequestFieldMatchers{ @@ -1878,12 +1847,6 @@ func Test_StrongestMatch_ShouldNotBeCacheableIfMatchedOnEverythingApartFromState Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "foo=bar", - }, - }, Path: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -1957,10 +1920,12 @@ func Test_StrongestMatch__ShouldBeCacheableIfMatchedOnEverythingApartFromStateZe Value: "http", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "?foo=bar", + Query: &models.QueryRequestFieldMatchers{ + "foo": []models.RequestFieldMatchers{ + { + Matcher: matchers.Exact, + Value: "bar", + }, }, }, Path: []models.RequestFieldMatchers{ diff --git a/core/models/payload.go b/core/models/payload.go index 393599224..d245e063c 100644 --- a/core/models/payload.go +++ b/core/models/payload.go @@ -317,6 +317,6 @@ func (r *ResponseDetails) ConvertToResponseDetailsViewV5() v2.ResponseDetailsVie return view } -func (this RequestDetails) GetRawQuery() string { +func (this *RequestDetails) GetRawQuery() string { return this.rawQuery } diff --git a/core/models/request_matcher.go b/core/models/request_matcher.go index ecd7090ea..b5aaac5cd 100644 --- a/core/models/request_matcher.go +++ b/core/models/request_matcher.go @@ -2,8 +2,6 @@ package models import ( "encoding/json" - "net/url" - v2 "github.com/SpectoLabs/hoverfly/core/handlers/v2" "github.com/SpectoLabs/hoverfly/core/matching/matchers" "github.com/SpectoLabs/hoverfly/core/util" @@ -149,24 +147,17 @@ type RequestMatcherResponsePair struct { } func NewRequestMatcherResponsePairFromView(view *v2.RequestMatcherResponsePairViewV5) *RequestMatcherResponsePair { - for i, matcher := range view.RequestMatcher.DeprecatedQuery { - if matcher.Matcher == matchers.Exact { - sortedQuery := util.SortQueryString(matcher.Value.(string)) - view.RequestMatcher.DeprecatedQuery[i].Value = sortedQuery - } - } return &RequestMatcherResponsePair{ RequestMatcher: RequestMatcher{ - Path: NewRequestFieldMatchersFromView(view.RequestMatcher.Path), - Method: NewRequestFieldMatchersFromView(view.RequestMatcher.Method), - Destination: NewRequestFieldMatchersFromView(view.RequestMatcher.Destination), - Scheme: NewRequestFieldMatchersFromView(view.RequestMatcher.Scheme), - DeprecatedQuery: NewRequestFieldMatchersFromView(view.RequestMatcher.DeprecatedQuery), - Body: NewRequestFieldMatchersFromView(view.RequestMatcher.Body), - Headers: NewRequestFieldMatchersFromMapView(view.RequestMatcher.Headers), - Query: NewQueryRequestFieldMatchersFromMapView(view.RequestMatcher.Query), - RequiresState: view.RequestMatcher.RequiresState, + Path: NewRequestFieldMatchersFromView(view.RequestMatcher.Path), + Method: NewRequestFieldMatchersFromView(view.RequestMatcher.Method), + Destination: NewRequestFieldMatchersFromView(view.RequestMatcher.Destination), + Scheme: NewRequestFieldMatchersFromView(view.RequestMatcher.Scheme), + Body: NewRequestFieldMatchersFromView(view.RequestMatcher.Body), + Headers: NewRequestFieldMatchersFromMapView(view.RequestMatcher.Headers), + Query: NewQueryRequestFieldMatchersFromMapView(view.RequestMatcher.Query), + RequiresState: view.RequestMatcher.RequiresState, }, Response: NewResponseDetailsFromResponse(view.Response), } @@ -174,7 +165,7 @@ func NewRequestMatcherResponsePairFromView(view *v2.RequestMatcherResponsePairVi func (this *RequestMatcherResponsePair) BuildView() v2.RequestMatcherResponsePairViewV5 { - var path, method, destination, scheme, query, body []v2.MatcherViewV5 + var path, method, destination, scheme, body []v2.MatcherViewV5 if this.RequestMatcher.Path != nil && len(this.RequestMatcher.Path) != 0 { views := []v2.MatcherViewV5{} @@ -216,14 +207,6 @@ func (this *RequestMatcherResponsePair) BuildView() v2.RequestMatcherResponsePai body = views } - if this.RequestMatcher.DeprecatedQuery != nil && len(this.RequestMatcher.DeprecatedQuery) != 0 { - views := []v2.MatcherViewV5{} - for _, matcher := range this.RequestMatcher.DeprecatedQuery { - views = append(views, matcher.BuildView()) - } - query = views - } - headersWithMatchers := map[string][]v2.MatcherViewV5{} for key, matchers := range this.RequestMatcher.Headers { views := []v2.MatcherViewV5{} @@ -247,30 +230,28 @@ func (this *RequestMatcherResponsePair) BuildView() v2.RequestMatcherResponsePai return v2.RequestMatcherResponsePairViewV5{ RequestMatcher: v2.RequestMatcherViewV5{ - Path: path, - Method: method, - Destination: destination, - Scheme: scheme, - DeprecatedQuery: query, - Body: body, - Headers: headersWithMatchers, - Query: queriesWithMatchers, - RequiresState: this.RequestMatcher.RequiresState, + Path: path, + Method: method, + Destination: destination, + Scheme: scheme, + Body: body, + Headers: headersWithMatchers, + Query: queriesWithMatchers, + RequiresState: this.RequestMatcher.RequiresState, }, Response: this.Response.ConvertToResponseDetailsViewV5(), } } type RequestMatcher struct { - Path []RequestFieldMatchers - Method []RequestFieldMatchers - Destination []RequestFieldMatchers - Scheme []RequestFieldMatchers - DeprecatedQuery []RequestFieldMatchers - Body []RequestFieldMatchers - Headers map[string][]RequestFieldMatchers - Query *QueryRequestFieldMatchers - RequiresState map[string]string + Path []RequestFieldMatchers + Method []RequestFieldMatchers + Destination []RequestFieldMatchers + Scheme []RequestFieldMatchers + Body []RequestFieldMatchers + Headers map[string][]RequestFieldMatchers + Query *QueryRequestFieldMatchers + RequiresState map[string]string } type QueryRequestFieldMatchers map[string][]RequestFieldMatchers @@ -296,7 +277,6 @@ func (this RequestMatcher) ToEagerlyCacheable() *RequestDetails { this.Destination == nil || len(this.Destination) != 1 || this.Destination[0].Matcher != matchers.Exact || this.Method == nil || len(this.Method) != 1 || this.Method[0].Matcher != matchers.Exact || this.Path == nil || len(this.Path) != 1 || this.Path[0].Matcher != matchers.Exact || - this.DeprecatedQuery != nil && len(this.DeprecatedQuery) == 1 && this.DeprecatedQuery[0].Matcher != matchers.Exact || this.Scheme == nil || len(this.Scheme) != 1 || this.Scheme[0].Matcher != matchers.Exact { return nil } @@ -330,8 +310,6 @@ func (this RequestMatcher) ToEagerlyCacheable() *RequestDetails { } } - } else if this.DeprecatedQuery != nil && len(this.DeprecatedQuery) == 1 { - query, _ = url.ParseQuery(this.DeprecatedQuery[0].Value.(string)) } return &RequestDetails{ diff --git a/core/models/request_matcher_test.go b/core/models/request_matcher_test.go index b8d9311c5..122b40d0a 100644 --- a/core/models/request_matcher_test.go +++ b/core/models/request_matcher_test.go @@ -215,26 +215,6 @@ func Test_NewRequestMatcherResponsePairFromView_LeavesQueriesWithMatchersNil(t * Expect(unit.RequestMatcher.Query).To(BeNil()) } -func Test_NewRequestMatcherResponsePairFromView_SortsDeprecatedQuery(t *testing.T) { - RegisterTestingT(t) - - unit := models.NewRequestMatcherResponsePairFromView(&v2.RequestMatcherResponsePairViewV5{ - RequestMatcher: v2.RequestMatcherViewV5{ - DeprecatedQuery: []v2.MatcherViewV5{ - { - Matcher: matchers.Exact, - Value: "b=b&a=a", - }, - }, - }, - Response: v2.ResponseDetailsViewV5{ - Body: "body", - }, - }) - - Expect(unit.RequestMatcher.DeprecatedQuery[0].Value).To(Equal("a=a&b=b")) -} - func Test_NewRequestMatcherResponsePairFromView_StoresTemplated(t *testing.T) { RegisterTestingT(t) @@ -284,12 +264,6 @@ func Test_RequestMatcher_BuildRequestDetailsFromExactMatches_GeneratesARequestDe Value: "path", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "query=two", - }, - }, Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -304,7 +278,7 @@ func Test_RequestMatcher_BuildRequestDetailsFromExactMatches_GeneratesARequestDe Destination: "destination", Method: "method", Path: "path", - Query: map[string][]string{"query": {"two"}}, + Query: map[string][]string{}, Scheme: "scheme", })) } @@ -339,12 +313,6 @@ func Test_RequestMatcher_BuildRequestDetailsFromExactMatches_ReturnsNilIfMissing Value: "path", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "query", - }, - }, Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, diff --git a/core/models/simulation_test.go b/core/models/simulation_test.go index 93badc5ea..edeed3569 100644 --- a/core/models/simulation_test.go +++ b/core/models/simulation_test.go @@ -68,12 +68,6 @@ func Test_Simulation_AddPair_CanAddAFullPairToTheArray(t *testing.T) { Value: "/testpath", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "?query=test", - }, - }, Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -104,8 +98,6 @@ func Test_Simulation_AddPair_CanAddAFullPairToTheArray(t *testing.T) { Expect(unit.GetMatchingPairs()[0].RequestMatcher.Method[0].Value).To(Equal("testmethod")) Expect(unit.GetMatchingPairs()[0].RequestMatcher.Path[0].Matcher).To(Equal("exact")) Expect(unit.GetMatchingPairs()[0].RequestMatcher.Path[0].Value).To(Equal("/testpath")) - Expect(unit.GetMatchingPairs()[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal("exact")) - Expect(unit.GetMatchingPairs()[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("?query=test")) Expect(unit.GetMatchingPairs()[0].RequestMatcher.Scheme[0].Matcher).To(Equal("exact")) Expect(unit.GetMatchingPairs()[0].RequestMatcher.Scheme[0].Value).To(Equal("http")) @@ -151,12 +143,6 @@ func Test_Simulation_AddPairInSequence_CanAddAFullPairToTheArray(t *testing.T) { Value: "/testpath", }, }, - DeprecatedQuery: []models.RequestFieldMatchers{ - { - Matcher: matchers.Exact, - Value: "?query=test", - }, - }, Scheme: []models.RequestFieldMatchers{ { Matcher: matchers.Exact, @@ -187,8 +173,6 @@ func Test_Simulation_AddPairInSequence_CanAddAFullPairToTheArray(t *testing.T) { Expect(unit.GetMatchingPairs()[0].RequestMatcher.Method[0].Value).To(Equal("testmethod")) Expect(unit.GetMatchingPairs()[0].RequestMatcher.Path[0].Matcher).To(Equal("exact")) Expect(unit.GetMatchingPairs()[0].RequestMatcher.Path[0].Value).To(Equal("/testpath")) - Expect(unit.GetMatchingPairs()[0].RequestMatcher.DeprecatedQuery[0].Matcher).To(Equal("exact")) - Expect(unit.GetMatchingPairs()[0].RequestMatcher.DeprecatedQuery[0].Value).To(Equal("?query=test")) Expect(unit.GetMatchingPairs()[0].RequestMatcher.Scheme[0].Matcher).To(Equal("exact")) Expect(unit.GetMatchingPairs()[0].RequestMatcher.Scheme[0].Value).To(Equal("http")) diff --git a/functional-tests/core/api/simulation_api_v2_test.go b/functional-tests/core/api/simulation_api_v2_test.go index e1b1fe2f7..1737bdfbc 100644 --- a/functional-tests/core/api/simulation_api_v2_test.go +++ b/functional-tests/core/api/simulation_api_v2_test.go @@ -406,19 +406,6 @@ var _ = Describe("/api/v2/simulation", func() { Expect(string(responseBody)).To(Equal(`{"error":"Invalid simulation: schema version r3 is not supported by this version of Hoverfly, you may need to update Hoverfly"}`)) }) - It("should warn when importing deprecatedQuery", func() { - request := sling.New().Put("http://localhost:" + hoverfly.GetAdminPort() + "/api/v2/simulation") - payload := bytes.NewBufferString(testdata.V1JsonPayload) - - request.Body(payload) - response := functional_tests.DoRequest(request) - Expect(response.StatusCode).To(Equal(http.StatusOK)) - - responseBody, _ := ioutil.ReadAll(response.Body) - Expect(string(responseBody)).To(ContainSubstring("WARNING: Usage of deprecated field `deprecatedQuery` on data.pairs[1].request.deprecatedQuery, please update your simulation to use `query` field")) - Expect(string(responseBody)).To(ContainSubstring("https://hoverfly.readthedocs.io/en/latest/pages/troubleshooting/troubleshooting.html#why-does-my-simulation-have-a-deprecatedquery-field")) - }) - It("should warn when importing responses with content length and encoding", func() { request := sling.New().Put("http://localhost:" + hoverfly.GetAdminPort() + "/api/v2/simulation") payload := bytes.NewBufferString(testdata.ContentLengthAndTransferEncoding) diff --git a/functional-tests/hoverctl/import_test.go b/functional-tests/hoverctl/import_test.go index dedfc5a8d..869ed0338 100644 --- a/functional-tests/hoverctl/import_test.go +++ b/functional-tests/hoverctl/import_test.go @@ -1,8 +1,6 @@ package hoverctl_suite import ( - "io/ioutil" - "github.com/SpectoLabs/hoverfly/functional-tests" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -10,10 +8,6 @@ import ( var _ = Describe("When I import with hoverctl", func() { - var ( - hoverfly *functional_tests.Hoverfly - ) - Context("without providing a path to write to", func() { It("it should fail nicely", func() { @@ -33,76 +27,4 @@ var _ = Describe("When I import with hoverctl", func() { }) }) - Describe("with a running hoverfly", func() { - - BeforeEach(func() { - hoverfly = functional_tests.NewHoverfly() - hoverfly.Start() - - functional_tests.Run(hoverctlBinary, "targets", "update", "local", "--admin-port", hoverfly.GetAdminPort()) - }) - - AfterEach(func() { - hoverfly.Stop() - }) - - It("can show warnings", func() { - - fileName := functional_tests.GenerateFileName() - err := ioutil.WriteFile(fileName, []byte(`{ - "data": { - "pairs": [ - { - "response": { - "status": 200, - "body": "YmFzZTY0IGVuY29kZWQ=", - "encodedBody": true, - "headers": { - "Hoverfly": [ - "Was-Here" - ] - }, - "templated": false - }, - "request": { - "path": { - "exactMatch": "/pages/keyconcepts/templates.html" - }, - "method": { - "exactMatch": "GET" - }, - "destination": { - "exactMatch": "docs.hoverfly.io" - }, - "scheme": { - "exactMatch": "http" - }, - "query": { - "exactMatch": "query=true" - }, - "body": { - "exactMatch": "" - } - } - } - ], - "globalActions": { - "delays": [] - } - }, - "meta": { - "schemaVersion": "v3", - "hoverflyVersion": "v0.13.0", - "timeExported": "2017-07-13T16:34:30+01:00" - } - }`), 0644) - Expect(err).To(BeNil()) - - output := functional_tests.Run(hoverctlBinary, "import", fileName) - Expect(output).To(ContainSubstring("WARNING: Usage of deprecated field `deprecatedQuery` on data.pairs[0].request.deprecatedQuery, please update your simulation to use `query` field")) - Expect(output).To(ContainSubstring("https://hoverfly.readthedocs.io/en/latest/pages/troubleshooting/troubleshooting.html#why-does-my-simulation-have-a-deprecatedquery-field")) - Expect(output).To(ContainSubstring("Successfully imported simulation ")) - - }) - }) })