File tree 2 files changed +13
-3
lines changed 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package httptest
6
6
7
7
import (
8
8
"bytes"
9
+ "fmt"
9
10
"io/ioutil"
10
11
"net/http"
11
12
"strconv"
@@ -176,7 +177,7 @@ func (rw *ResponseRecorder) Result() *http.Response {
176
177
if res .StatusCode == 0 {
177
178
res .StatusCode = 200
178
179
}
179
- res .Status = http .StatusText (res .StatusCode )
180
+ res .Status = fmt . Sprintf ( "%03d %s" , res . StatusCode , http .StatusText (res .StatusCode ) )
180
181
if rw .Body != nil {
181
182
res .Body = ioutil .NopCloser (bytes .NewReader (rw .Body .Bytes ()))
182
183
}
Original file line number Diff line number Diff line change @@ -23,7 +23,15 @@ func TestRecorder(t *testing.T) {
23
23
return nil
24
24
}
25
25
}
26
- hasResultStatus := func (wantCode int ) checkFunc {
26
+ hasResultStatus := func (want string ) checkFunc {
27
+ return func (rec * ResponseRecorder ) error {
28
+ if rec .Result ().Status != want {
29
+ return fmt .Errorf ("Result().Status = %q; want %q" , rec .Result ().Status , want )
30
+ }
31
+ return nil
32
+ }
33
+ }
34
+ hasResultStatusCode := func (wantCode int ) checkFunc {
27
35
return func (rec * ResponseRecorder ) error {
28
36
if rec .Result ().StatusCode != wantCode {
29
37
return fmt .Errorf ("Result().StatusCode = %d; want %d" , rec .Result ().StatusCode , wantCode )
@@ -235,7 +243,8 @@ func TestRecorder(t *testing.T) {
235
243
hasOldHeader ("X-Foo" , "1" ),
236
244
hasStatus (0 ),
237
245
hasHeader ("X-Foo" , "1" ),
238
- hasResultStatus (200 ),
246
+ hasResultStatus ("200 OK" ),
247
+ hasResultStatusCode (200 ),
239
248
),
240
249
},
241
250
{
You can’t perform that action at this time.
0 commit comments