Skip to content

Commit

Permalink
Remove support for deprecatedQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysitu committed Feb 25, 2024
1 parent 8ea06fd commit 4560f3e
Showing 20 changed files with 112 additions and 475 deletions.
10 changes: 0 additions & 10 deletions core/handlers/v2/simulation_views.go
Original file line number Diff line number Diff line change
@@ -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 {
23 changes: 10 additions & 13 deletions core/handlers/v2/simulation_views_test.go
Original file line number Diff line number Diff line change
@@ -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]"))
}
47 changes: 22 additions & 25 deletions core/handlers/v2/simulation_views_upgrade.go
Original file line number Diff line number Diff line change
@@ -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,
46 changes: 0 additions & 46 deletions core/handlers/v2/simulation_views_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -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) {
17 changes: 8 additions & 9 deletions core/handlers/v2/simulation_views_v5.go
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion core/hoverfly_service_test.go
Original file line number Diff line number Diff line change
@@ -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))

4 changes: 0 additions & 4 deletions core/import.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading

0 comments on commit 4560f3e

Please sign in to comment.