@@ -39,12 +39,14 @@ func TestGetClient(t *testing.T) {
39
39
w .WriteHeader (http .StatusSeeOther )
40
40
}))
41
41
stdClient := http.Client {}
42
- _ , err := stdClient .Get (ts .URL )
42
+ r , err := stdClient .Get (ts .URL )
43
43
assert .Error (t , err )
44
+ r .Body .Close ()
44
45
45
46
client := GetClient ()
46
47
res , err := client .Get (ts .URL )
47
48
assert .Equal (t , "/////" , res .Header .Get ("Location" ))
49
+ res .Body .Close ()
48
50
assert .NoError (t , err )
49
51
})
50
52
}
@@ -61,7 +63,8 @@ func TestDoSuccessful(t *testing.T) {
61
63
body , _ := ioutil .ReadAll (r .Body )
62
64
assert .Equal (t , `{"requestValue":"someValueIn"}` + "\n " , string (body ))
63
65
assert .Equal (t , r .Method , "POST" )
64
- w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
66
+ _ , err := w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
67
+ assert .NoError (t , err )
65
68
}))
66
69
defer ts .Close ()
67
70
@@ -100,7 +103,8 @@ func TestDoSuccessful(t *testing.T) {
100
103
t .Run ("no request body" , func (t * testing.T ) {
101
104
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
102
105
assert .Equal (t , r .Method , "POST" )
103
- w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
106
+ _ , err := w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
107
+ assert .NoError (t , err )
104
108
}))
105
109
defer ts .Close ()
106
110
@@ -157,7 +161,8 @@ func TestDoSuccessful(t *testing.T) {
157
161
body , _ := ioutil .ReadAll (r .Body )
158
162
assert .Equal (t , `{"requestValue":"someValueIn"}` , string (body ))
159
163
assert .Equal (t , r .Method , "POST" )
160
- w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
164
+ _ , err := w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
165
+ assert .NoError (t , err )
161
166
}))
162
167
defer ts .Close ()
163
168
@@ -231,7 +236,8 @@ func TestDoHTTPErrors(t *testing.T) {
231
236
t .Run ("non 2xx response with body" , func (t * testing.T ) {
232
237
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
233
238
w .WriteHeader (http .StatusBadRequest )
234
- w .Write ([]byte ("some error message" ))
239
+ _ , err := w .Write ([]byte ("some error message" ))
240
+ assert .NoError (t , err )
235
241
}))
236
242
defer ts .Close ()
237
243
@@ -278,7 +284,8 @@ func TestDoOtherErrors(t *testing.T) {
278
284
func TestGet (t * testing.T ) {
279
285
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
280
286
assert .Equal (t , r .Method , "GET" )
281
- w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
287
+ _ , err := w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
288
+ assert .NoError (t , err )
282
289
}))
283
290
defer ts .Close ()
284
291
@@ -293,7 +300,8 @@ func TestPost(t *testing.T) {
293
300
body , _ := ioutil .ReadAll (r .Body )
294
301
assert .Equal (t , `{"requestValue":"someValueIn"}` + "\n " , string (body ))
295
302
assert .Equal (t , r .Method , "POST" )
296
- w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
303
+ _ , err := w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
304
+ assert .NoError (t , err )
297
305
}))
298
306
defer ts .Close ()
299
307
@@ -307,7 +315,10 @@ func ExampleDo() {
307
315
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
308
316
body , _ := ioutil .ReadAll (r .Body )
309
317
fmt .Println (string (body ))
310
- w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
318
+ _ , err := w .Write ([]byte (`{"responseValue":"someValueOut"}` ))
319
+ if err != nil {
320
+ panic (err )
321
+ }
311
322
}))
312
323
defer ts .Close ()
313
324
0 commit comments