Open ghost opened 3 years ago
I've managed to test this using something as follows:
serverAPI := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// says the response is longer than what we're actually returning
w.Header().Add("Content-Length", "50")
// return less bytes, wich will result in an "unexpected EOF" from ioutil.ReadAll()
_, _ = w.Write([]byte("a"))
}),
)
defer serverAPI.Close()
Same issue here. The problem is that this library immediately consumes that response buffer and will have the mock RoundTripper return (nil, error) instead of (http.Response, nil) (with the reader as http.Response.Body).
I am trying to test the following line of code:
This is my test:
I removed the URL and other extra stuff, the code is a little (but not much) more complex than that. However, the
ioutil.ReadAll
refuses to spew an error. What am I doing wrong?