HTTPRedirect asserts that a specified handler returns a redirect status code. assert.HTTPRedirect(t, myHandler, "GET", "/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{})
| 49 | // |
| 50 | // Returns whether the assertion was successful (true) or not (false). |
| 51 | func HTTPRedirect(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { |
| 52 | if h, ok := t.(tHelper); ok { |
| 53 | h.Helper() |
| 54 | } |
| 55 | code, err := httpCode(handler, method, url, values) |
| 56 | if err != nil { |
| 57 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err), msgAndArgs...) |
| 58 | } |
| 59 | |
| 60 | isRedirectCode := code >= http.StatusMultipleChoices && code <= http.StatusTemporaryRedirect |
| 61 | if !isRedirectCode { |
| 62 | Fail(t, fmt.Sprintf("Expected HTTP redirect status code for %q but received %d", url+"?"+values.Encode(), code), msgAndArgs...) |
| 63 | } |
| 64 | |
| 65 | return isRedirectCode |
| 66 | } |
| 67 | |
| 68 | // HTTPError asserts that a specified handler returns an error status code. |
| 69 | // |