Commit 6374a660 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http/httptest: make ResponseRecorder.Result.Status match http.Transport

Fixes #18438

Change-Id: I9599c1536d5e8bad7662b8ffa19e9b0746e27e60
Reviewed-on: https://go-review.googlesource.com/44000Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a28ce75d
......@@ -6,6 +6,7 @@ package httptest
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"strconv"
......@@ -176,7 +177,7 @@ func (rw *ResponseRecorder) Result() *http.Response {
if res.StatusCode == 0 {
res.StatusCode = 200
}
res.Status = http.StatusText(res.StatusCode)
res.Status = fmt.Sprintf("%03d %s", res.StatusCode, http.StatusText(res.StatusCode))
if rw.Body != nil {
res.Body = ioutil.NopCloser(bytes.NewReader(rw.Body.Bytes()))
}
......
......@@ -23,7 +23,15 @@ func TestRecorder(t *testing.T) {
return nil
}
}
hasResultStatus := func(wantCode int) checkFunc {
hasResultStatus := func(want string) checkFunc {
return func(rec *ResponseRecorder) error {
if rec.Result().Status != want {
return fmt.Errorf("Result().Status = %q; want %q", rec.Result().Status, want)
}
return nil
}
}
hasResultStatusCode := func(wantCode int) checkFunc {
return func(rec *ResponseRecorder) error {
if rec.Result().StatusCode != wantCode {
return fmt.Errorf("Result().StatusCode = %d; want %d", rec.Result().StatusCode, wantCode)
......@@ -235,7 +243,8 @@ func TestRecorder(t *testing.T) {
hasOldHeader("X-Foo", "1"),
hasStatus(0),
hasHeader("X-Foo", "1"),
hasResultStatus(200),
hasResultStatus("200 OK"),
hasResultStatusCode(200),
),
},
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment