File tree 3 files changed +16
-4
lines changed
3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -1228,7 +1228,7 @@ func TestPatchMethod(t *testing.T) {
1228
1228
assertError (t , err )
1229
1229
assertEqual (t , http .StatusOK , resp .StatusCode ())
1230
1230
1231
- resp .body = nil
1231
+ resp .SetBody ( nil )
1232
1232
assertEqual (t , "" , resp .String ())
1233
1233
}
1234
1234
Original file line number Diff line number Diff line change @@ -37,6 +37,18 @@ func (r *Response) Body() []byte {
37
37
return r .body
38
38
}
39
39
40
+ // SetBody method is to set Response body in byte slice. Typically,
41
+ // its helpful for test cases.
42
+ //
43
+ // resp.SetBody([]byte("This is test body content"))
44
+ // resp.SetBody(nil)
45
+ //
46
+ // Since v2.10.0
47
+ func (r * Response ) SetBody (b []byte ) * Response {
48
+ r .body = b
49
+ return r
50
+ }
51
+
40
52
// Status method returns the HTTP status string for the executed request.
41
53
//
42
54
// Example: 200 OK
Original file line number Diff line number Diff line change @@ -616,18 +616,18 @@ func TestClientRetryPost(t *testing.T) {
616
616
617
617
if resp != nil {
618
618
if resp .StatusCode () == http .StatusInternalServerError {
619
- t .Logf ("Got response body: %s" , string ( resp .body ))
619
+ t .Logf ("Got response body: %s" , resp .String ( ))
620
620
var usersResponse []map [string ]interface {}
621
621
err := json .Unmarshal (resp .body , & usersResponse )
622
622
assertError (t , err )
623
623
624
624
if ! reflect .DeepEqual (users , usersResponse ) {
625
- t .Errorf ("Expected request body to be echoed back as response body. Instead got: %s" , string ( resp .body ))
625
+ t .Errorf ("Expected request body to be echoed back as response body. Instead got: %s" , resp .String ( ))
626
626
}
627
627
628
628
return
629
629
}
630
- t .Errorf ("Got unexpected response code: %d with body: %s" , resp .StatusCode (), string ( resp .body ))
630
+ t .Errorf ("Got unexpected response code: %d with body: %s" , resp .StatusCode (), resp .String ( ))
631
631
}
632
632
}
633
633
You can’t perform that action at this time.
0 commit comments