MCPcopy
hub / github.com/stretchr/testify / HTTPStatusCode

Function HTTPStatusCode

assert/http_assertions.go:95–110  ·  assert/http_assertions.go::HTTPStatusCode

HTTPStatusCode asserts that a specified handler returns a specified status code. assert.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501) Returns whether the assertion was successful (true) or not (false).

(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, statuscode int, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

93//
94// Returns whether the assertion was successful (true) or not (false).
95func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) bool {
96 if h, ok := t.(tHelper); ok {
97 h.Helper()
98 }
99 code, err := httpCode(handler, method, url, values)
100 if err != nil {
101 Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err), msgAndArgs...)
102 }
103
104 successful := code == statuscode
105 if !successful {
106 Fail(t, fmt.Sprintf("Expected HTTP status code %d for %q but received %d", statuscode, url+"?"+values.Encode(), code), msgAndArgs...)
107 }
108
109 return successful
110}
111
112// HTTPBody is a helper that returns HTTP body of the response. It returns
113// empty string if building a new request fails.

Callers 4

HTTPStatusCodeFunction · 0.92
HTTPStatusCodefFunction · 0.70
TestHTTPStatusCodeFunction · 0.70
HTTPStatusCodeMethod · 0.70

Calls 3

httpCodeFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestHTTPStatusCodeFunction · 0.56