File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 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) {
12281228 assertError (t , err )
12291229 assertEqual (t , http .StatusOK , resp .StatusCode ())
12301230
1231- resp .body = nil
1231+ resp .SetBody ( nil )
12321232 assertEqual (t , "" , resp .String ())
12331233}
12341234
Original file line number Diff line number Diff line change @@ -37,6 +37,18 @@ func (r *Response) Body() []byte {
3737 return r .body
3838}
3939
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+
4052// Status method returns the HTTP status string for the executed request.
4153//
4254// Example: 200 OK
Original file line number Diff line number Diff line change @@ -616,18 +616,18 @@ func TestClientRetryPost(t *testing.T) {
616616
617617 if resp != nil {
618618 if resp .StatusCode () == http .StatusInternalServerError {
619- t .Logf ("Got response body: %s" , string ( resp .body ))
619+ t .Logf ("Got response body: %s" , resp .String ( ))
620620 var usersResponse []map [string ]interface {}
621621 err := json .Unmarshal (resp .body , & usersResponse )
622622 assertError (t , err )
623623
624624 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 ( ))
626626 }
627627
628628 return
629629 }
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 ( ))
631631 }
632632}
633633
You can’t perform that action at this time.
0 commit comments