-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: net/http/httpest: add ResponseRecorder.EnableFullDuplex #65120
Comments
(*ResponseRecorder).EnableFullDuplex
CC @neild |
It would be trivial to add an Furthermore, I think most full-duplex handlers would be better tested with a |
I don't personally have useful for The main reason why I'm advocating for
I honestly had thought that Here's what my code looked like before: recorder := httptest.NewResponseRecorder()
r := &http.Request{URL: ..., Body: ...}
someHandlerToTest(w, r)
checkResponse(recorder) And switching it to this is much longer: s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler(w, r)
}))
u, err := url.JoinPath(s.URL, "...")
require.NoError(t, err)
url, err := url.Parse(u)
require.NoError(t, err)
r := &http.Request{URL: url, Body: ...}
resp, err := http.DefaultClient.Do(r)
require.NoError(t, err)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err) It gets more complicated because of course sending a request to the Maybe the simplicity with implementing full duplex on the |
Proposal Details
It can be difficult to test code that expects to be able to use
EnableFullDuplex
becausehttptest.(*ResponseRecorder)
doesn't implementEnableFullDuplex
.The text was updated successfully, but these errors were encountered: