MCPcopy Create free account
hub / github.com/jmespath/go-jmespath / HTTPError

Function HTTPError

internal/testify/assert/http_assertions.go:75–91  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 4

HTTPErrorFunction · 0.92
HTTPErrorfFunction · 0.70
TestHTTPErrorFunction · 0.70
HTTPErrorMethod · 0.70

Calls 3

httpCodeFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestHTTPErrorFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…