MCPcopy
hub / github.com/gofiber/fiber / Test_App_BodyLimit_LargerThanDefault

Function Test_App_BodyLimit_LargerThanDefault

app_test.go:501–523  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

499}
500
501func Test_App_BodyLimit_LargerThanDefault(t *testing.T) {
502 t.Parallel()
503
504 limit := DefaultBodyLimit*2 + 1024 // slightly above double the default
505 app := New(Config{BodyLimit: limit})
506
507 app.Post("/", func(c Ctx) error {
508 return c.SendStatus(StatusOK)
509 })
510
511 // Body larger than the default but within our custom limit should succeed
512 midBody := bytes.Repeat([]byte{'a'}, DefaultBodyLimit+512)
513 req := httptest.NewRequest(MethodPost, "/", bytes.NewReader(midBody))
514 resp, err := app.Test(req)
515 require.NoError(t, err)
516 require.Equal(t, StatusOK, resp.StatusCode)
517
518 // Body above the custom limit should fail
519 largeBody := bytes.Repeat([]byte{'a'}, limit+1)
520 req = httptest.NewRequest(MethodPost, "/", bytes.NewReader(largeBody))
521 _, err = app.Test(req)
522 require.ErrorIs(t, err, fasthttp.ErrBodyTooLarge)
523}
524
525type customConstraint struct{}
526

Callers

nothing calls this directly

Calls 4

TestMethod · 0.80
NewFunction · 0.70
PostMethod · 0.65
SendStatusMethod · 0.65

Tested by

no test coverage detected