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

Function HTTPError

assert/http_assertions.go:73–88  ·  view source on GitHub ↗

HTTPError asserts that a specified handler returns an error status code. assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} Returns whether the assertion was successful (true) or not (false).

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

Source from the content-addressed store, hash-verified

71//
72// Returns whether the assertion was successful (true) or not (false).
73func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool {
74 if h, ok := t.(tHelper); ok {
75 h.Helper()
76 }
77 code, err := httpCode(handler, method, url, values)
78 if err != nil {
79 Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err), msgAndArgs...)
80 }
81
82 isErrorCode := code >= http.StatusBadRequest
83 if !isErrorCode {
84 Fail(t, fmt.Sprintf("Expected HTTP error status code for %q but received %d", url+"?"+values.Encode(), code), msgAndArgs...)
85 }
86
87 return isErrorCode
88}
89
90// HTTPStatusCode asserts that a specified handler returns a specified status code.
91//

Callers 4

HTTPErrorFunction · 0.92
HTTPErrorfFunction · 0.70
TestHTTPErrorFunction · 0.70
HTTPErrorMethod · 0.70

Calls 3

httpCodeFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestHTTPErrorFunction · 0.56