HTTPBody is a helper that returns HTTP body of the response. It returns empty string if building a new request fails.
(handler http.HandlerFunc, method, url string, values url.Values)
| 112 | // HTTPBody is a helper that returns HTTP body of the response. It returns |
| 113 | // empty string if building a new request fails. |
| 114 | func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string { |
| 115 | w := httptest.NewRecorder() |
| 116 | if len(values) > 0 { |
| 117 | url += "?" + values.Encode() |
| 118 | } |
| 119 | req, err := http.NewRequest(method, url, http.NoBody) |
| 120 | if err != nil { |
| 121 | return "" |
| 122 | } |
| 123 | handler(w, req) |
| 124 | return w.Body.String() |
| 125 | } |
| 126 | |
| 127 | // HTTPBodyContains asserts that a specified handler returns a |
| 128 | // body that contains a string. |
no test coverage detected