You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (errReader) Read(p []byte) (int, error) {
return 1, errors.New("Computer says NON!")
}
// Wait for vault to unseal: body error.
func TestWaitForVaultToUnsealBodyError(t *testing.T) {
defer gock.Off() // Flush pending mocks after test execution
gock.New(URL).
Get("v1/seal-status").
Reply(200).
Body(errReader{})
ook()
}
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?
The text was updated successfully, but these errors were encountered:
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 returningw.Header().Add("Content-Length", "50")
// return less bytes, wich will result in an "unexpected EOF" from ioutil.ReadAll()_, _=w.Write([]byte("a"))
}),
)
deferserverAPI.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?The text was updated successfully, but these errors were encountered: