MCPcopy
hub / github.com/labstack/echo / TestRouter_RouteWhenNotFoundRouteStaticKind

Function TestRouter_RouteWhenNotFoundRouteStaticKind

router_test.go:3504–3555  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3502}
3503
3504func TestRouter_RouteWhenNotFoundRouteStaticKind(t *testing.T) {
3505 // note: static not found handler is quite silly thing to have but we still support it
3506 var testCases = []struct {
3507 expectRoute any
3508 expectParam map[string]string
3509 name string
3510 whenURL string
3511 expectID int
3512 }{
3513 {
3514 name: "route not existent / to not found handler /",
3515 whenURL: "/",
3516 expectRoute: "/",
3517 expectID: 3,
3518 expectParam: map[string]string{},
3519 },
3520 {
3521 name: "route /a to /a",
3522 whenURL: "/a",
3523 expectRoute: "/a",
3524 expectID: 1,
3525 },
3526 }
3527
3528 for _, tc := range testCases {
3529 t.Run(tc.name, func(t *testing.T) {
3530 e := New()
3531 e.contextPathParamAllocSize.Store(1)
3532 r := e.router
3533
3534 r.Add(Route{Method: http.MethodPut, Path: "/", Handler: handlerHelper("ID", 0), Name: "0"})
3535 r.Add(Route{Method: http.MethodGet, Path: "/a", Handler: handlerHelper("ID", 1), Name: "1"})
3536 r.Add(Route{Method: http.MethodPut, Path: "/*", Handler: handlerHelper("ID", 2), Name: "2"})
3537
3538 r.Add(Route{Method: RouteNotFound, Path: "/", Handler: handlerHelper("ID", 3), Name: "3"})
3539
3540 req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil)
3541 c := e.NewContext(req, nil)
3542
3543 handler := r.Route(c)
3544 handler(c)
3545
3546 testValue, _ := c.Get("ID").(int)
3547 assert.Equal(t, tc.expectID, testValue)
3548 assert.Equal(t, tc.expectRoute, c.Path())
3549 for param, expectedValue := range tc.expectParam {
3550 assert.Equal(t, expectedValue, c.Param(param))
3551 }
3552 checkUnusedParamValues(t, c, tc.expectParam)
3553 })
3554 }
3555}
3556
3557func TestPathValues_Get(t *testing.T) {
3558 var testCases = []struct {

Callers

nothing calls this directly

Calls 8

GetMethod · 0.95
PathMethod · 0.95
ParamMethod · 0.95
NewFunction · 0.85
checkUnusedParamValuesFunction · 0.85
NewContextMethod · 0.80
AddMethod · 0.65
RouteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…