MCPcopy
hub / github.com/caddyserver/caddy / AssertResponseCode

Method AssertResponseCode

caddytest/caddytest.go:506–519  ·  view source on GitHub ↗

AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions

(req *http.Request, expectedStatusCode int)

Source from the content-addressed store, hash-verified

504
505// AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions
506func (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.
522func (tc *Tester) AssertResponse(req *http.Request, expectedStatusCode int, expectedBody string) (*http.Response, string) {

Callers 6

TestLoadUnorderedJSONFunction · 0.95
AssertResponseMethod · 0.95
TestH2ToH2CStreamFunction · 0.95
TestBrowseFunction · 0.95

Calls 1

DoMethod · 0.80

Tested by 5

TestLoadUnorderedJSONFunction · 0.76
TestH2ToH2CStreamFunction · 0.76
TestBrowseFunction · 0.76