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

Function Test_Ctx_SaveFileToStorage_BufferNotReused

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

Source from the content-addressed store, hash-verified

5723}
5724
5725func Test_Ctx_SaveFileToStorage_BufferNotReused(t *testing.T) {
5726 t.Parallel()
5727
5728 app := New()
5729 storage := &captureStorage{t: t}
5730 ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
5731
5732 t.Cleanup(func() {
5733 app.ReleaseCtx(ctx)
5734 })
5735
5736 const payloadSize = 1024
5737 firstPayload := bytes.Repeat([]byte{'a'}, payloadSize)
5738 secondPayload := bytes.Repeat([]byte{'b'}, payloadSize)
5739
5740 firstHeader := createMultipartFileHeader(t, "first.bin", firstPayload)
5741 require.NoError(t, ctx.SaveFileToStorage(firstHeader, "first", storage))
5742
5743 firstStored := storage.data["first"]
5744 require.Equal(t, firstPayload, firstStored)
5745
5746 secondHeader := createMultipartFileHeader(t, "second.bin", secondPayload)
5747 require.NoError(t, ctx.SaveFileToStorage(secondHeader, "second", storage))
5748 require.Equal(t, secondPayload, storage.data["second"])
5749
5750 require.Equal(t, firstPayload, firstStored, "stored data must not rely on pooled buffers")
5751}
5752
5753type mockContextAwareStorage struct {
5754 t *testing.T

Callers

nothing calls this directly

Calls 5

AcquireCtxMethod · 0.80
ReleaseCtxMethod · 0.80
NewFunction · 0.70
SaveFileToStorageMethod · 0.65

Tested by

no test coverage detected