Closed
Description
What version of Go are you using (go version
)?
Go 1.15.2
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
All
What did you do?
With http.MaxByteReader
, I want easily check (for example with switch case statement) the error http: request body too large
.
What did you expect to see?
https://play.golang.org/p/rm17KEL91Z5
func TestMaxBytesReader(t *testing.T) {
req := ioutil.NopCloser(bytes.NewBufferString("my too long request"))
_, err := http.MaxBytesReader(httptest.NewRecorder(), req, 2).Read([]byte{10: 0})
if err != http.ErrBodyTooLarge {
t.FailNow()
}
}
What did you see instead?
https://play.golang.org/p/ucUuzXjY3s7
func TestMaxBytesReader(t *testing.T) {
req := ioutil.NopCloser(bytes.NewBufferString("my too long request"))
_, err := http.MaxBytesReader(httptest.NewRecorder(), req, 2).Read([]byte{10: 0})
if err == nil || err.Error() != "http: request body too large" {
t.FailNow()
}
}