(t *testing.T)
| 3364 | } |
| 3365 | |
| 3366 | func TestRouter_RouteWhenNotFoundRouteAnyKind(t *testing.T) { |
| 3367 | var testCases = []struct { |
| 3368 | expectRoute any |
| 3369 | expectParam map[string]string |
| 3370 | name string |
| 3371 | whenURL string |
| 3372 | expectID int |
| 3373 | }{ |
| 3374 | { |
| 3375 | name: "route not existent /xx to not found handler /*", |
| 3376 | whenURL: "/xx", |
| 3377 | expectRoute: "/*", |
| 3378 | expectID: 4, |
| 3379 | expectParam: map[string]string{"*": "xx"}, |
| 3380 | }, |
| 3381 | { |
| 3382 | name: "route not existent /a/xx to not found handler /a/*", |
| 3383 | whenURL: "/a/xx", |
| 3384 | expectRoute: "/a/*", |
| 3385 | expectID: 5, |
| 3386 | expectParam: map[string]string{"*": "xx"}, |
| 3387 | }, |
| 3388 | { |
| 3389 | name: "route not existent /a/c/dxxx to not found handler /a/c/d*", |
| 3390 | whenURL: "/a/c/dxxx", |
| 3391 | expectRoute: "/a/c/d*", |
| 3392 | expectID: 6, |
| 3393 | expectParam: map[string]string{"*": "xxx"}, |
| 3394 | }, |
| 3395 | { |
| 3396 | name: "route /a/c/df to /a/c/df", |
| 3397 | whenURL: "/a/c/df", |
| 3398 | expectRoute: "/a/c/df", |
| 3399 | expectID: 1, |
| 3400 | }, |
| 3401 | } |
| 3402 | |
| 3403 | for _, tc := range testCases { |
| 3404 | t.Run(tc.name, func(t *testing.T) { |
| 3405 | e := New() |
| 3406 | e.contextPathParamAllocSize.Store(1) |
| 3407 | r := e.router |
| 3408 | |
| 3409 | r.Add(Route{Method: http.MethodGet, Path: "/", Handler: handlerHelper("ID", 0), Name: "0"}) |
| 3410 | r.Add(Route{Method: http.MethodGet, Path: "/a/c/df", Handler: handlerHelper("ID", 1), Name: "1"}) |
| 3411 | r.Add(Route{Method: http.MethodGet, Path: "/a/b*", Handler: handlerHelper("ID", 2), Name: "2"}) |
| 3412 | r.Add(Route{Method: http.MethodPut, Path: "/*", Handler: handlerHelper("ID", 3), Name: "3"}) |
| 3413 | |
| 3414 | r.Add(Route{Method: RouteNotFound, Path: "/a/c/d*", Handler: handlerHelper("ID", 6), Name: "6"}) |
| 3415 | r.Add(Route{Method: RouteNotFound, Path: "/a/*", Handler: handlerHelper("ID", 5), Name: "5"}) |
| 3416 | r.Add(Route{Method: RouteNotFound, Path: "/*", Handler: handlerHelper("ID", 4), Name: "4"}) |
| 3417 | |
| 3418 | req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil) |
| 3419 | c := e.NewContext(req, nil) |
| 3420 | |
| 3421 | handler := r.Route(c) |
| 3422 | handler(c) |
| 3423 |
nothing calls this directly
no test coverage detected
searching dependent graphs…