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

Function Test_Ctx_FormFile_BodyLimitExceeded

ctx_test.go:2445–2466  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2443}
2444
2445func Test_Ctx_FormFile_BodyLimitExceeded(t *testing.T) {
2446 t.Parallel()
2447
2448 app := New(Config{
2449 BodyLimit: 64,
2450 })
2451 c := app.AcquireCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck,forcetypeassert // not needed
2452
2453 body := &bytes.Buffer{}
2454 writer := multipart.NewWriter(body)
2455 ioWriter, err := writer.CreateFormFile("file", "test.txt")
2456 require.NoError(t, err)
2457 _, err = ioWriter.Write([]byte(strings.Repeat("a", 256)))
2458 require.NoError(t, err)
2459 require.NoError(t, writer.Close())
2460
2461 c.Request().Header.Set(HeaderContentType, writer.FormDataContentType())
2462 c.Request().SetBody(body.Bytes())
2463
2464 _, err = c.FormFile("file")
2465 require.ErrorIs(t, err, fasthttp.ErrBodyTooLarge)
2466}
2467
2468func Test_Ctx_FormValue_BodyLimitExceeded(t *testing.T) {
2469 t.Parallel()

Callers

nothing calls this directly

Calls 8

BytesMethod · 0.95
AcquireCtxMethod · 0.80
NewFunction · 0.70
WriteMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.65
RequestMethod · 0.65
FormFileMethod · 0.65

Tested by

no test coverage detected