HTTPSuccess asserts that a specified handler returns a success status code. assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) Returns whether the assertion was successful (true) or not (false).
(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{})
| 27 | // |
| 28 | // Returns whether the assertion was successful (true) or not (false). |
| 29 | func HTTPSuccess(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { |
| 30 | if h, ok := t.(tHelper); ok { |
| 31 | h.Helper() |
| 32 | } |
| 33 | code, err := httpCode(handler, method, url, values) |
| 34 | if err != nil { |
| 35 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err), msgAndArgs...) |
| 36 | } |
| 37 | |
| 38 | isSuccessCode := code >= http.StatusOK && code <= http.StatusPartialContent |
| 39 | if !isSuccessCode { |
| 40 | Fail(t, fmt.Sprintf("Expected HTTP success status code for %q but received %d", url+"?"+values.Encode(), code), msgAndArgs...) |
| 41 | } |
| 42 | |
| 43 | return isSuccessCode |
| 44 | } |
| 45 | |
| 46 | // HTTPRedirect asserts that a specified handler returns a redirect status code. |
| 47 | // |