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{})
| 71 | // |
| 72 | // Returns whether the assertion was successful (true) or not (false). |
| 73 | func 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 | // |