diff --git a/pkg/httpmock/legacy.go b/pkg/httpmock/legacy.go index 9474c3dd8..9402c21c7 100644 --- a/pkg/httpmock/legacy.go +++ b/pkg/httpmock/legacy.go @@ -12,19 +12,19 @@ import ( // TODO: clean up methods in this file when there are no more callers func (r *Registry) StubResponse(status int, body io.Reader) { - r.Register(MatchAny, func(*http.Request) (*http.Response, error) { - return httpResponse(status, body), nil + r.Register(MatchAny, func(req *http.Request) (*http.Response, error) { + return httpResponse(status, req, body), nil }) } func (r *Registry) StubWithFixture(status int, fixtureFileName string) func() { fixturePath := path.Join("../test/fixtures/", fixtureFileName) fixtureFile, err := os.Open(fixturePath) - r.Register(MatchAny, func(*http.Request) (*http.Response, error) { + r.Register(MatchAny, func(req *http.Request) (*http.Response, error) { if err != nil { return nil, err } - return httpResponse(200, fixtureFile), nil + return httpResponse(200, req, fixtureFile), nil }) return func() { if err == nil { diff --git a/pkg/httpmock/stub.go b/pkg/httpmock/stub.go index 48077ed4e..cc42dfd6c 100644 --- a/pkg/httpmock/stub.go +++ b/pkg/httpmock/stub.go @@ -59,15 +59,15 @@ func decodeJSONBody(req *http.Request, dest interface{}) error { } func StringResponse(body string) Responder { - return func(*http.Request) (*http.Response, error) { - return httpResponse(200, bytes.NewBufferString(body)), nil + return func(req *http.Request) (*http.Response, error) { + return httpResponse(200, req, bytes.NewBufferString(body)), nil } } func JSONResponse(body interface{}) Responder { - return func(*http.Request) (*http.Response, error) { + return func(req *http.Request) (*http.Response, error) { b, _ := json.Marshal(body) - return httpResponse(200, bytes.NewBuffer(b)), nil + return httpResponse(200, req, bytes.NewBuffer(b)), nil } } @@ -84,7 +84,7 @@ func GraphQLMutation(body string, cb func(map[string]interface{})) Responder { } cb(bodyData.Variables.Input) - return httpResponse(200, bytes.NewBufferString(body)), nil + return httpResponse(200, req, bytes.NewBufferString(body)), nil } } @@ -100,13 +100,14 @@ func GraphQLQuery(body string, cb func(string, map[string]interface{})) Responde } cb(bodyData.Query, bodyData.Variables) - return httpResponse(200, bytes.NewBufferString(body)), nil + return httpResponse(200, req, bytes.NewBufferString(body)), nil } } -func httpResponse(status int, body io.Reader) *http.Response { +func httpResponse(status int, req *http.Request, body io.Reader) *http.Response { return &http.Response{ StatusCode: status, + Request: req, Body: ioutil.NopCloser(body), } }