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

Function HTTPSuccess

assert/http_assertions.go:29–44  ·  assert/http_assertions.go::HTTPSuccess

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{})

Source from the content-addressed store, hash-verified

27//
28// Returns whether the assertion was successful (true) or not (false).
29func 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//

Callers 6

HTTPSuccessFunction · 0.92
HTTPSuccessfFunction · 0.70
TestHTTPSuccessFunction · 0.70
HTTPSuccessMethod · 0.70

Calls 3

httpCodeFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 3

TestHTTPSuccessFunction · 0.56