Skip to content

Commit 3d4ea00

Browse files
committed
httptesting: fix for Go 1.6
The httptest.ResponseRecorder type has become more sophisticated, and our code was being a bit devious by constructing one without using the expected methods. Fix by using the expected methods to make the ResponseRecorder. We should eventually remove our use of ResponseRecorder entirely and fix all the code that uses httptesting, but we don't need to bite that bullet quite yet.
1 parent 45f216f commit 3d4ea00

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

httptesting/http.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func AssertJSONResponse(c *gc.C, rec *httptest.ResponseRecorder, expectStatus in
138138
c.Assert(rec.Body.Bytes(), gc.HasLen, 0)
139139
return
140140
}
141-
c.Assert(rec.Header().Get("Content-Type"), gc.Equals, "application/json")
141+
c.Assert(rec.Header().Get("Content-Type"), gc.Equals, "application/json", gc.Commentf("headers: %q", rec.Header()))
142142

143143
if assertBody, ok := expectBody.(BodyAsserter); ok {
144144
var data json.RawMessage
@@ -217,13 +217,15 @@ func DoRequest(c *gc.C, p DoRequestParams) *httptest.ResponseRecorder {
217217
return nil
218218
}
219219
defer resp.Body.Close()
220-
var rec httptest.ResponseRecorder
221-
rec.HeaderMap = resp.Header
222-
rec.Code = resp.StatusCode
223-
rec.Body = new(bytes.Buffer)
220+
rec := httptest.NewRecorder()
221+
h := rec.Header()
222+
for k, v := range resp.Header {
223+
h[k] = v
224+
}
225+
rec.WriteHeader(resp.StatusCode)
224226
_, err := io.Copy(rec.Body, resp.Body)
225227
c.Assert(err, jc.ErrorIsNil)
226-
return &rec
228+
return rec
227229
}
228230

229231
// Do invokes a request on the given handler with the given

0 commit comments

Comments
 (0)