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

Function Test_Ctx_CustomCtx_and_Method

ctx_test.go:444–474  ·  view source on GitHub ↗

go test -run Test_Ctx_CustomCtx

(t *testing.T)

Source from the content-addressed store, hash-verified

442
443// go test -run Test_Ctx_CustomCtx
444func Test_Ctx_CustomCtx_and_Method(t *testing.T) {
445 t.Parallel()
446
447 // Create app with custom request methods
448 methods := append(DefaultMethods, "JOHN") //nolint:gocritic // We want a new slice here
449 app := NewWithCustomCtx(func(app *App) CustomCtx {
450 return &customCtx{
451 DefaultCtx: *NewDefaultCtx(app),
452 }
453 }, Config{
454 RequestMethods: methods,
455 })
456
457 // Add route with custom method
458 app.Add([]string{"JOHN"}, "/doe", testEmptyHandler)
459 resp, err := app.Test(httptest.NewRequest("JOHN", "/doe", http.NoBody))
460 require.NoError(t, err, "app.Test(req)")
461 defer func() { require.NoError(t, resp.Body.Close()) }()
462 require.Equal(t, StatusOK, resp.StatusCode, "Status code")
463
464 body, err := io.ReadAll(resp.Body)
465 require.NoError(t, err, "io.ReadAll(resp.Body)")
466 require.Empty(t, body)
467 require.Empty(t, resp.Header.Get(HeaderContentType))
468 require.Equal(t, int64(0), resp.ContentLength)
469
470 // Add a new method
471 require.Panics(t, func() {
472 app.Add([]string{"JANE"}, "/jane", testEmptyHandler)
473 })
474}
475
476// go test -run Test_Ctx_Accepts_EmptyAccept
477func Test_Ctx_Accepts_EmptyAccept(t *testing.T) {

Callers

nothing calls this directly

Calls 6

NewWithCustomCtxFunction · 0.85
NewDefaultCtxFunction · 0.85
TestMethod · 0.80
AddMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected