For some reason, I cannot seem to get ioutil.ReadAll(res.Body)
, where res
is the *http.Response
returned by res, err := hc.Do(redirectRequest)
(for hc http.Client
, redirectRequest *http.Request
).
Testing strategy thus far
Any time I see hc.Do
or http.Request
in the SUT, my instinct is to spin up a fake server and point the appropriate application states to it. Such a server, for this test, looks like this :
badServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// some stuff
w.Write([some bad bytes])
}))
defer badServer.Close()
I don't seem to have a way to control res.Body
, which is literally the only thing keeping me from 100% test completion against the func this is all in.
I tried, in the errorThrowingServer
's handler func, setting r.Body
to a stub io.ReadCloser
that throws an error when Read()
is called, but that doesn't effect res
.