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

Function Test_Ctx_CustomCtx_WithMiddleware

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

Source from the content-addressed store, hash-verified

411}
412
413func Test_Ctx_CustomCtx_WithMiddleware(t *testing.T) {
414 t.Parallel()
415
416 app := NewWithCustomCtx(func(app *App) CustomCtx {
417 return &customCtx{
418 DefaultCtx: *NewDefaultCtx(app),
419 }
420 })
421
422 app.Use(func(c Ctx) error {
423 _, ok := c.(*customCtx)
424 require.True(t, ok)
425 return c.Next()
426 })
427
428 app.Get("/", func(c Ctx) error {
429 custom, ok := c.(*customCtx)
430 require.True(t, ok)
431 return c.SendString(custom.Params(""))
432 })
433
434 resp, err := app.Test(httptest.NewRequest(MethodGet, "/", http.NoBody))
435 require.NoError(t, err, "app.Test(req)")
436 defer func() { require.NoError(t, resp.Body.Close()) }()
437
438 body, err := io.ReadAll(resp.Body)
439 require.NoError(t, err, "io.ReadAll(resp.Body)")
440 require.Equal(t, "prefix_", string(body))
441}
442
443// go test -run Test_Ctx_CustomCtx
444func Test_Ctx_CustomCtx_and_Method(t *testing.T) {

Callers

nothing calls this directly

Calls 9

NewWithCustomCtxFunction · 0.85
NewDefaultCtxFunction · 0.85
TestMethod · 0.80
UseMethod · 0.65
NextMethod · 0.65
GetMethod · 0.65
SendStringMethod · 0.65
ParamsMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected