1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Fix body_limit middleware unit test

This commit is contained in:
gemaizi 2022-03-21 23:45:06 +08:00 committed by Martti T
parent 63c62bcbe5
commit 572466d928

View File

@ -33,12 +33,13 @@ func TestBodyLimit(t *testing.T) {
assert.Equal(hw, rec.Body.Bytes())
}
// Based on content read (overlimit)
// Based on content length (overlimit)
he := BodyLimit("2B")(h)(c).(*echo.HTTPError)
assert.Equal(http.StatusRequestEntityTooLarge, he.Code)
// Based on content read (within limit)
req = httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(hw))
req.ContentLength = -1
rec = httptest.NewRecorder()
c = e.NewContext(req, rec)
if assert.NoError(BodyLimit("2M")(h)(c)) {
@ -48,6 +49,7 @@ func TestBodyLimit(t *testing.T) {
// Based on content read (overlimit)
req = httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(hw))
req.ContentLength = -1
rec = httptest.NewRecorder()
c = e.NewContext(req, rec)
he = BodyLimit("2B")(h)(c).(*echo.HTTPError)