Skip to content

Commit

Permalink
Fix body_limit middleware unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wsx864321 authored and aldas committed Apr 5, 2022
1 parent 63c62bc commit 572466d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion middleware/body_limit_test.go
Expand Up @@ -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)) {
Expand All @@ -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)
Expand Down

0 comments on commit 572466d

Please sign in to comment.