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

Function HTTPBody

assert/http_assertions.go:114–125  ·  assert/http_assertions.go::HTTPBody

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)

Source from the content-addressed store, hash-verified

112// HTTPBody is a helper that returns HTTP body of the response. It returns
113// empty string if building a new request fails.
114func 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.

Callers 2

HTTPBodyContainsFunction · 0.85
HTTPBodyNotContainsFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected