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

Function HTTPBodyContains

assert/http_assertions.go:133–145  ·  assert/http_assertions.go::HTTPBodyContains

HTTPBodyContains asserts that a specified handler returns a body that contains a string. assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") Returns whether the assertion was successful (true) or not (false).

(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

131//
132// Returns whether the assertion was successful (true) or not (false).
133func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {
134 if h, ok := t.(tHelper); ok {
135 h.Helper()
136 }
137 body := HTTPBody(handler, method, url, values)
138
139 contains := strings.Contains(body, fmt.Sprint(str))
140 if !contains {
141 Fail(t, fmt.Sprintf("Expected response body for %q to contain %q but found %q", url+"?"+values.Encode(), str, body), msgAndArgs...)
142 }
143
144 return contains
145}
146
147// HTTPBodyNotContains asserts that a specified handler returns a
148// body that does not contain a string.

Callers 4

HTTPBodyContainsFunction · 0.92
HTTPBodyContainsfFunction · 0.70
TestHttpBodyFunction · 0.70
HTTPBodyContainsMethod · 0.70

Calls 4

HTTPBodyFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65
ContainsMethod · 0.45

Tested by 1

TestHttpBodyFunction · 0.56