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

Function Test_App_ErrorHandler_HandlerStack

app_test.go:602–630  ·  app_test.go::Test_App_ErrorHandler_HandlerStack
(t *testing.T)

Source from the content-addressed store, hash-verified

600}
601
602func Test_App_ErrorHandler_HandlerStack(t *testing.T) {
603 t.Parallel()
604 app := New(Config{
605 ErrorHandler: func(c Ctx, err error) error {
606 require.Equal(t, "1: USE error", err.Error())
607 return DefaultErrorHandler(c, err)
608 },
609 })
610 app.Use("/", func(c Ctx) error {
611 err := c.Next() // call next USE
612 require.Equal(t, "2: USE error", err.Error())
613 return errors.New("1: USE error")
614 }, func(c Ctx) error {
615 err := c.Next() // call [0] GET
616 require.Equal(t, "0: GET error", err.Error())
617 return errors.New("2: USE error")
618 })
619 app.Get("/", func(_ Ctx) error {
620 return errors.New("0: GET error")
621 })
622
623 resp, err := app.Test(httptest.NewRequest(MethodGet, "/", http.NoBody))
624 require.NoError(t, err, "app.Test(req)")
625 require.Equal(t, 500, resp.StatusCode, "Status code")
626
627 body, err := io.ReadAll(resp.Body)
628 require.NoError(t, err)
629 require.Equal(t, "1: USE error", string(body))
630}
631
632func Test_App_ErrorHandler_RouteStack(t *testing.T) {
633 t.Parallel()

Callers

nothing calls this directly

Calls 8

TestMethod · 0.80
NewFunction · 0.70
DefaultErrorHandlerFunction · 0.70
ErrorMethod · 0.65
UseMethod · 0.65
NextMethod · 0.65
NewMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected