AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions
(req *http.Request, expectedStatusCode int)
| 504 | |
| 505 | // AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions |
| 506 | func (tc *Tester) AssertResponseCode(req *http.Request, expectedStatusCode int) *http.Response { |
| 507 | tc.t.Helper() |
| 508 | |
| 509 | resp, err := tc.Client.Do(req) //nolint:gosec // no SSRFs demonstrated |
| 510 | if err != nil { |
| 511 | tc.t.Fatalf("failed to call server %s", err) |
| 512 | } |
| 513 | |
| 514 | if expectedStatusCode != resp.StatusCode { |
| 515 | tc.t.Errorf("requesting \"%s\" expected status code: %d but got %d", req.URL.RequestURI(), expectedStatusCode, resp.StatusCode) |
| 516 | } |
| 517 | |
| 518 | return resp |
| 519 | } |
| 520 | |
| 521 | // AssertResponse requests a URI and asserts the status code and body. |
| 522 | func (tc *Tester) AssertResponse(req *http.Request, expectedStatusCode int, expectedBody string) (*http.Response, string) { |