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{})
| 73 | // |
| 74 | // Returns whether the assertion was successful (true) or not (false). |
| 75 | func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { |
| 76 | if h, ok := t.(tHelper); ok { |
| 77 | h.Helper() |
| 78 | } |
| 79 | code, err := httpCode(handler, method, url, values) |
| 80 | if err != nil { |
| 81 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) |
| 82 | return false |
| 83 | } |
| 84 | |
| 85 | isErrorCode := code >= http.StatusBadRequest |
| 86 | if !isErrorCode { |
| 87 | Fail(t, fmt.Sprintf("Expected HTTP error status code for %q but received %d", url+"?"+values.Encode(), code)) |
| 88 | } |
| 89 | |
| 90 | return isErrorCode |
| 91 | } |
| 92 | |
| 93 | // HTTPBody is a helper that returns HTTP body of the response. It returns |
| 94 | // empty string if building a new request fails. |
searching dependent graphs…