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{})
| 131 | // |
| 132 | // Returns whether the assertion was successful (true) or not (false). |
| 133 | func 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. |