(t *testing.T)
| 3502 | } |
| 3503 | |
| 3504 | func 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 | |
| 3557 | func TestPathValues_Get(t *testing.T) { |
| 3558 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…