TestErrorHandler_PicksRightOne() — fiber Function Reference
Architecture documentation for the TestErrorHandler_PicksRightOne() function in app_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 6757bd88_2e31_2a55_02cb_3f8ce02cc80f["TestErrorHandler_PicksRightOne()"] e728fdd2_242f_706b_c1d2_041b3d6badb5["app_test.go"] 6757bd88_2e31_2a55_02cb_3f8ce02cc80f -->|defined in| e728fdd2_242f_706b_c1d2_041b3d6badb5 style 6757bd88_2e31_2a55_02cb_3f8ce02cc80f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
app_test.go lines 2941–3010
func TestErrorHandler_PicksRightOne(t *testing.T) {
t.Parallel()
// common handler to be used by all routes,
// it will always fail by returning an error since
// we need to test that the right ErrorHandler is invoked
handler := func(_ Ctx) error {
return errors.New("random error")
}
// subapp /api/v1/users [no custom error handler]
appAPIV1Users := New()
appAPIV1Users.Get("/", handler)
// subapp /api/v1/use [with custom error handler]
appAPIV1UseEH := func(c Ctx, _ error) error {
return c.SendString("/api/v1/use error handler")
}
appAPIV1Use := New(Config{ErrorHandler: appAPIV1UseEH})
appAPIV1Use.Get("/", handler)
// subapp: /api/v1 [with custom error handler]
appV1EH := func(c Ctx, _ error) error {
return c.SendString("/api/v1 error handler")
}
appV1 := New(Config{ErrorHandler: appV1EH})
appV1.Get("/", handler)
appV1.Use("/users", appAPIV1Users)
appV1.Use("/use", appAPIV1Use)
// root app [no custom error handler]
app := New()
app.Get("/", handler)
app.Use("/api/v1", appV1)
testCases := []struct {
path string // the endpoint url to test
expected string // the expected error response
}{
// /api/v1/users mount doesn't have custom ErrorHandler
// so it should use the upper-nearest one (/api/v1)
{"/api/v1/users", "/api/v1 error handler"},
// /api/v1/use mount has a custom ErrorHandler
{"/api/v1/use", "/api/v1/use error handler"},
// /api/v1 mount has a custom ErrorHandler
{"/api/v1", "/api/v1 error handler"},
// / mount doesn't have custom ErrorHandler, since is
// the root path i will use Fiber's default Error Handler
{"/", "random error"},
}
for _, testCase := range testCases {
t.Run(testCase.path, func(t *testing.T) {
t.Parallel()
resp, err := app.Test(httptest.NewRequest(MethodGet, testCase.path, http.NoBody))
if err != nil {
t.Fatal(err)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
require.Equal(t, testCase.expected, string(body))
})
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does TestErrorHandler_PicksRightOne() do?
TestErrorHandler_PicksRightOne() is a function in the fiber codebase, defined in app_test.go.
Where is TestErrorHandler_PicksRightOne() defined?
TestErrorHandler_PicksRightOne() is defined in app_test.go at line 2941.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free