Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bodyFile to response part of pair #893

Merged
merged 10 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func BenchmarkProcessRequest(b *testing.B) {
Mode: "simulate",
})

simulation := v2.SimulationViewV5{}
simulation := v2.SimulationViewV6{}
_ = json.Unmarshal([]byte(`{
"data": {
"pairs": [{
Expand Down Expand Up @@ -99,13 +99,13 @@ func BenchmarkProcessRequest(b *testing.B) {
}
},
"meta": {
"schemaVersion": "v5",
"schemaVersion": "v6",
"hoverflyVersion": "v0.17.0",
"timeExported": "2017-05-30T14:23:44+01:00"
}
}`), &simulation)

templated := v2.SimulationViewV5{}
templated := v2.SimulationViewV6{}
_ = json.Unmarshal([]byte(`{
"data": {
"pairs": [{
Expand Down Expand Up @@ -150,19 +150,19 @@ func BenchmarkProcessRequest(b *testing.B) {
}
},
"meta": {
"schemaVersion": "v5",
"schemaVersion": "v6",
"hoverflyVersion": "v0.17.0",
"timeExported": "2017-05-30T14:23:44+01:00"
}
}`), &templated)

bytes, _ := ioutil.ReadFile("../testdata/large_response_body.json")
largeResponse := v2.SimulationViewV5{}
largeResponse := v2.SimulationViewV6{}
_ = json.Unmarshal(bytes, &largeResponse)

benchmarks := []struct {
name string
simulation v2.SimulationViewV5
simulation v2.SimulationViewV6
}{
{"Simple simulation", simulation},
{"Templated simulation", templated},
Expand Down
20 changes: 10 additions & 10 deletions core/handlers/v2/cache_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ func (this HoverflyCacheStub) GetCache() (CacheView, error) {
return CacheView{
Cache: []CachedResponseView{
{
MatchingPair: &RequestMatcherResponsePairViewV5{
RequestMatcher: RequestMatcherViewV5{
Destination: []MatcherViewV5{
NewMatcherView(matchers.Exact, "one"),
MatchingPair: &RequestMatcherResponsePairViewV6{
RequestMatcher: RequestMatcherViewV6{
Destination: []MatcherViewV6{
NewMatcherViewV6(matchers.Exact, "one"),
},
},
Response: ResponseDetailsViewV5{},
Response: ResponseDetailsViewV6{},
},
},
{
MatchingPair: &RequestMatcherResponsePairViewV5{
RequestMatcher: RequestMatcherViewV5{
Destination: []MatcherViewV5{
NewMatcherView(matchers.Exact, "two"),
MatchingPair: &RequestMatcherResponsePairViewV6{
RequestMatcher: RequestMatcherViewV6{
Destination: []MatcherViewV6{
NewMatcherViewV6(matchers.Exact, "two"),
},
},
Response: ResponseDetailsViewV5{},
Response: ResponseDetailsViewV6{},
},
},
},
Expand Down
20 changes: 10 additions & 10 deletions core/handlers/v2/journal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ func Test_JournalHandler_Post_CallsFilter(t *testing.T) {
unit := JournalHandler{Hoverfly: &stubHoverfly}

journalEntryFilterView := JournalEntryFilterView{
Request: &RequestMatcherViewV5{
Destination: []MatcherViewV5{
NewMatcherView(matchers.Exact, "hoverfly.io"),
Request: &RequestMatcherViewV6{
Destination: []MatcherViewV6{
NewMatcherViewV6(matchers.Exact, "hoverfly.io"),
},
Path: []MatcherViewV5{
NewMatcherView(matchers.Glob, "*"),
Path: []MatcherViewV6{
NewMatcherViewV6(matchers.Glob, "*"),
},
},
}
Expand Down Expand Up @@ -295,12 +295,12 @@ func Test_JournalHandler_Post_JournalError(t *testing.T) {
unit := JournalHandler{Hoverfly: &stubHoverfly}

requestMatcher := JournalEntryFilterView{
Request: &RequestMatcherViewV5{
Destination: []MatcherViewV5{
NewMatcherView(matchers.Exact, "hoverfly.io"),
Request: &RequestMatcherViewV6{
Destination: []MatcherViewV6{
NewMatcherViewV6(matchers.Exact, "hoverfly.io"),
},
Path: []MatcherViewV5{
NewMatcherView(matchers.Glob, "*"),
Path: []MatcherViewV6{
NewMatcherViewV6(matchers.Glob, "*"),
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions core/handlers/v2/simulation_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

type HoverflySimulation interface {
GetSimulation() (SimulationViewV5, error)
GetFilteredSimulation(string) (SimulationViewV5, error)
PutSimulation(SimulationViewV5) SimulationImportResult
GetSimulation() (SimulationViewV6, error)
GetFilteredSimulation(string) (SimulationViewV6, error)
PutSimulation(SimulationViewV6) SimulationImportResult
DeleteSimulation()
}

Expand Down Expand Up @@ -60,7 +60,7 @@ func (this *SimulationHandler) Get(w http.ResponseWriter, req *http.Request, nex
urlPattern := req.URL.Query().Get("urlPattern")

var err error
var simulationView SimulationViewV5
var simulationView SimulationViewV6
if urlPattern == "" {
simulationView, err = this.Hoverfly.GetSimulation()
} else {
Expand Down Expand Up @@ -106,7 +106,7 @@ func (this *SimulationHandler) Options(w http.ResponseWriter, r *http.Request, n
}

func (this *SimulationHandler) GetSchema(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
bytes, _ := json.Marshal(SimulationViewV5Schema)
bytes, _ := json.Marshal(SimulationViewV6Schema)

handlers.WriteResponse(w, bytes)
}
Expand Down
104 changes: 52 additions & 52 deletions core/handlers/v2/simulation_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ import (

type HoverflySimulationStub struct {
Deleted bool
Simulation SimulationViewV5
Simulation SimulationViewV6
UrlPattern string
Filtered bool
}

func (this HoverflySimulationStub) GetSimulation() (SimulationViewV5, error) {
pairOne := RequestMatcherResponsePairViewV5{
RequestMatcher: RequestMatcherViewV5{
Destination: []MatcherViewV5{
NewMatcherView(matchers.Exact, "test.com"),
func (this HoverflySimulationStub) GetSimulation() (SimulationViewV6, error) {
pairOne := RequestMatcherResponsePairViewV6{
RequestMatcher: RequestMatcherViewV6{
Destination: []MatcherViewV6{
NewMatcherViewV6(matchers.Exact, "test.com"),
},
Path: []MatcherViewV5{
NewMatcherView(matchers.Exact, "/testing"),
Path: []MatcherViewV6{
NewMatcherViewV6(matchers.Exact, "/testing"),
},
},
Response: ResponseDetailsViewV5{
Response: ResponseDetailsViewV6{
Body: "test-body",
},
}

return SimulationViewV5{
DataViewV5{
RequestResponsePairs: []RequestMatcherResponsePairViewV5{pairOne},
return SimulationViewV6{
DataViewV6{
RequestResponsePairs: []RequestMatcherResponsePairViewV6{pairOne},
GlobalActions: GlobalActionsView{
Delays: []v1.ResponseDelayView{
{
Expand All @@ -56,7 +56,7 @@ func (this HoverflySimulationStub) GetSimulation() (SimulationViewV5, error) {
}, nil
}

func (this *HoverflySimulationStub) GetFilteredSimulation(urlPattern string) (SimulationViewV5, error) {
func (this *HoverflySimulationStub) GetFilteredSimulation(urlPattern string) (SimulationViewV6, error) {
this.Filtered = true
this.UrlPattern = urlPattern
return this.GetSimulation()
Expand All @@ -66,42 +66,42 @@ func (this *HoverflySimulationStub) DeleteSimulation() {
this.Deleted = true
}

func (this *HoverflySimulationStub) PutSimulation(simulation SimulationViewV5) SimulationImportResult {
func (this *HoverflySimulationStub) PutSimulation(simulation SimulationViewV6) SimulationImportResult {
this.Simulation = simulation
return SimulationImportResult{}
}

type HoverflySimulationErrorStub struct{}

func (this HoverflySimulationErrorStub) GetSimulation() (SimulationViewV5, error) {
return SimulationViewV5{}, fmt.Errorf("error")
func (this HoverflySimulationErrorStub) GetSimulation() (SimulationViewV6, error) {
return SimulationViewV6{}, fmt.Errorf("error")
}

func (this HoverflySimulationErrorStub) GetFilteredSimulation(urlPattern string) (SimulationViewV5, error) {
return SimulationViewV5{}, fmt.Errorf("error")
func (this HoverflySimulationErrorStub) GetFilteredSimulation(urlPattern string) (SimulationViewV6, error) {
return SimulationViewV6{}, fmt.Errorf("error")
}

func (this *HoverflySimulationErrorStub) DeleteSimulation() {}

func (this *HoverflySimulationErrorStub) PutSimulation(simulation SimulationViewV5) SimulationImportResult {
func (this *HoverflySimulationErrorStub) PutSimulation(simulation SimulationViewV6) SimulationImportResult {
return SimulationImportResult{
err: fmt.Errorf("error"),
}
}

type HoverflySimulationWarningStub struct{}

func (this HoverflySimulationWarningStub) GetSimulation() (SimulationViewV5, error) {
return SimulationViewV5{}, fmt.Errorf("error")
func (this HoverflySimulationWarningStub) GetSimulation() (SimulationViewV6, error) {
return SimulationViewV6{}, fmt.Errorf("error")
}

func (this HoverflySimulationWarningStub) GetFilteredSimulation(urlPattern string) (SimulationViewV5, error) {
return SimulationViewV5{}, fmt.Errorf("error")
func (this HoverflySimulationWarningStub) GetFilteredSimulation(urlPattern string) (SimulationViewV6, error) {
return SimulationViewV6{}, fmt.Errorf("error")
}

func (this *HoverflySimulationWarningStub) DeleteSimulation() {}

func (this *HoverflySimulationWarningStub) PutSimulation(simulation SimulationViewV5) SimulationImportResult {
func (this *HoverflySimulationWarningStub) PutSimulation(simulation SimulationViewV6) SimulationImportResult {
return SimulationImportResult{
WarningMessages: []SimulationImportWarning{{"This is a warning", "url"}},
}
Expand All @@ -120,22 +120,22 @@ func TestSimulationHandler_Get_ReturnsSimulation(t *testing.T) {

Expect(response.Code).To(Equal(http.StatusOK))

simulationView, err := unmarshalSimulationViewV5(response.Body)
simulationView, err := unmarshalSimulationViewV6(response.Body)
Expect(err).To(BeNil())

Expect(simulationView.DataViewV5.RequestResponsePairs).To(HaveLen(1))
Expect(simulationView.DataViewV6.RequestResponsePairs).To(HaveLen(1))

Expect(simulationView.DataViewV5.RequestResponsePairs[0].RequestMatcher.Destination[0].Matcher).To(Equal("exact"))
Expect(simulationView.DataViewV5.RequestResponsePairs[0].RequestMatcher.Destination[0].Value).To(Equal("test.com"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].RequestMatcher.Destination[0].Matcher).To(Equal("exact"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].RequestMatcher.Destination[0].Value).To(Equal("test.com"))

Expect(simulationView.DataViewV5.RequestResponsePairs[0].RequestMatcher.Path[0].Matcher).To(Equal("exact"))
Expect(simulationView.DataViewV5.RequestResponsePairs[0].RequestMatcher.Path[0].Value).To(Equal("/testing"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].RequestMatcher.Path[0].Matcher).To(Equal("exact"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].RequestMatcher.Path[0].Value).To(Equal("/testing"))

Expect(simulationView.DataViewV5.RequestResponsePairs[0].Response.Body).To(Equal("test-body"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].Response.Body).To(Equal("test-body"))

Expect(simulationView.DataViewV5.GlobalActions.Delays).To(HaveLen(1))
Expect(simulationView.DataViewV5.GlobalActions.Delays[0].HttpMethod).To(Equal("GET"))
Expect(simulationView.DataViewV5.GlobalActions.Delays[0].Delay).To(Equal(100))
Expect(simulationView.DataViewV6.GlobalActions.Delays).To(HaveLen(1))
Expect(simulationView.DataViewV6.GlobalActions.Delays[0].HttpMethod).To(Equal("GET"))
Expect(simulationView.DataViewV6.GlobalActions.Delays[0].Delay).To(Equal(100))

Expect(simulationView.MetaView.SchemaVersion).To(Equal("v3"))
Expect(simulationView.MetaView.HoverflyVersion).To(Equal("test"))
Expand Down Expand Up @@ -174,10 +174,10 @@ func TestSimulationHandler_Get_WithEmptyUrlPatternShouldNotFilterSimulation(t *t

Expect(response.Code).To(Equal(http.StatusOK))

simulationView, err := unmarshalSimulationViewV5(response.Body)
simulationView, err := unmarshalSimulationViewV6(response.Body)
Expect(err).To(BeNil())

Expect(simulationView.DataViewV5.RequestResponsePairs).To(HaveLen(1))
Expect(simulationView.DataViewV6.RequestResponsePairs).To(HaveLen(1))
Expect(stubHoverfly.Filtered).To(BeFalse())
}

Expand All @@ -194,10 +194,10 @@ func TestSimulationHandler_Get_WithUrlPatternShouldFilterSimulation(t *testing.T

Expect(response.Code).To(Equal(http.StatusOK))

simulationView, err := unmarshalSimulationViewV5(response.Body)
simulationView, err := unmarshalSimulationViewV6(response.Body)
Expect(err).To(BeNil())

Expect(simulationView.DataViewV5.RequestResponsePairs).To(HaveLen(1))
Expect(simulationView.DataViewV6.RequestResponsePairs).To(HaveLen(1))
Expect(stubHoverfly.Filtered).To(BeTrue())
Expect(stubHoverfly.UrlPattern).To(Equal("foo.com"))
}
Expand Down Expand Up @@ -230,22 +230,22 @@ func TestSimulationHandler_Delete_CallsGetAfterDelete(t *testing.T) {

response := makeRequestOnHandler(unit.Delete, request)

simulationView, err := unmarshalSimulationViewV5(response.Body)
simulationView, err := unmarshalSimulationViewV6(response.Body)
Expect(err).To(BeNil())

Expect(simulationView.DataViewV5.RequestResponsePairs).To(HaveLen(1))
Expect(simulationView.DataViewV6.RequestResponsePairs).To(HaveLen(1))

Expect(simulationView.DataViewV5.RequestResponsePairs[0].RequestMatcher.Destination[0].Matcher).To(Equal("exact"))
Expect(simulationView.DataViewV5.RequestResponsePairs[0].RequestMatcher.Destination[0].Value).To(Equal("test.com"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].RequestMatcher.Destination[0].Matcher).To(Equal("exact"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].RequestMatcher.Destination[0].Value).To(Equal("test.com"))

Expect(simulationView.DataViewV5.RequestResponsePairs[0].RequestMatcher.Path[0].Matcher).To(Equal("exact"))
Expect(simulationView.DataViewV5.RequestResponsePairs[0].RequestMatcher.Path[0].Value).To(Equal("/testing"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].RequestMatcher.Path[0].Matcher).To(Equal("exact"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].RequestMatcher.Path[0].Value).To(Equal("/testing"))

Expect(simulationView.DataViewV5.RequestResponsePairs[0].Response.Body).To(Equal("test-body"))
Expect(simulationView.DataViewV6.RequestResponsePairs[0].Response.Body).To(Equal("test-body"))

Expect(simulationView.DataViewV5.GlobalActions.Delays).To(HaveLen(1))
Expect(simulationView.DataViewV5.GlobalActions.Delays[0].HttpMethod).To(Equal("GET"))
Expect(simulationView.DataViewV5.GlobalActions.Delays[0].Delay).To(Equal(100))
Expect(simulationView.DataViewV6.GlobalActions.Delays).To(HaveLen(1))
Expect(simulationView.DataViewV6.GlobalActions.Delays[0].HttpMethod).To(Equal("GET"))
Expect(simulationView.DataViewV6.GlobalActions.Delays[0].Delay).To(Equal(100))

Expect(simulationView.MetaView.SchemaVersion).To(Equal("v3"))
Expect(simulationView.MetaView.HoverflyVersion).To(Equal("test"))
Expand Down Expand Up @@ -606,17 +606,17 @@ func Test_SimulationHandler_OptionsSchema_GetsOptions(t *testing.T) {
Expect(response.Header().Get("Allow")).To(Equal("OPTIONS, GET"))
}

func unmarshalSimulationViewV5(buffer *bytes.Buffer) (SimulationViewV5, error) {
func unmarshalSimulationViewV6(buffer *bytes.Buffer) (SimulationViewV6, error) {
body, err := ioutil.ReadAll(buffer)
if err != nil {
return SimulationViewV5{}, err
return SimulationViewV6{}, err
}

var simulationView SimulationViewV5
var simulationView SimulationViewV6

err = json.Unmarshal(body, &simulationView)
if err != nil {
return SimulationViewV5{}, err
return SimulationViewV6{}, err
}

return simulationView, nil
Expand Down
Loading