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

Function Test_Ctx_CustomCtx

ctx_test.go:355–377  ·  view source on GitHub ↗

go test -run Test_Ctx_CustomCtx

(t *testing.T)

Source from the content-addressed store, hash-verified

353
354// go test -run Test_Ctx_CustomCtx
355func Test_Ctx_CustomCtx(t *testing.T) {
356 t.Parallel()
357
358 app := NewWithCustomCtx(func(app *App) CustomCtx {
359 return &customCtx{
360 DefaultCtx: *NewDefaultCtx(app),
361 }
362 })
363
364 app.Get("/:id", func(c Ctx) error {
365 return c.SendString(c.Params("id"))
366 })
367 resp, err := app.Test(httptest.NewRequest(MethodGet, "/v3", &bytes.Buffer{}))
368 require.NoError(t, err, "app.Test(req)")
369 defer func() { require.NoError(t, resp.Body.Close()) }()
370
371 body, err := io.ReadAll(resp.Body)
372 require.NoError(t, err, "io.ReadAll(resp.Body)")
373 require.Len(t, body, len("prefix_v3"))
374 require.Equal(t, "prefix_v3", string(body))
375 require.Equal(t, MIMETextPlainCharsetUTF8, resp.Header.Get(HeaderContentType))
376 require.Equal(t, int64(len(body)), resp.ContentLength)
377}
378
379func Test_App_AcquireDefaultCtx_CustomCtxFallback(t *testing.T) {
380 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewWithCustomCtxFunction · 0.85
NewDefaultCtxFunction · 0.85
TestMethod · 0.80
GetMethod · 0.65
SendStringMethod · 0.65
ParamsMethod · 0.65
CloseMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected