(t *testing.T)
| 3433 | } |
| 3434 | |
| 3435 | func TestRouter_RouteWhenNotFoundRouteParamKind(t *testing.T) { |
| 3436 | var testCases = []struct { |
| 3437 | expectRoute any |
| 3438 | expectParam map[string]string |
| 3439 | name string |
| 3440 | whenURL string |
| 3441 | expectID int |
| 3442 | }{ |
| 3443 | { |
| 3444 | name: "route not existent /xx to not found handler /:file", |
| 3445 | whenURL: "/xx", |
| 3446 | expectRoute: "/:file", |
| 3447 | expectID: 4, |
| 3448 | expectParam: map[string]string{"file": "xx"}, |
| 3449 | }, |
| 3450 | { |
| 3451 | name: "route not existent /a/xx to not found handler /a/:file", |
| 3452 | whenURL: "/a/xx", |
| 3453 | expectRoute: "/a/:file", |
| 3454 | expectID: 5, |
| 3455 | expectParam: map[string]string{"file": "xx"}, |
| 3456 | }, |
| 3457 | { |
| 3458 | name: "route not existent /a/c/dxxx to not found handler /a/c/d:file", |
| 3459 | whenURL: "/a/c/dxxx", |
| 3460 | expectRoute: "/a/c/d:file", |
| 3461 | expectID: 6, |
| 3462 | expectParam: map[string]string{"file": "xxx"}, |
| 3463 | }, |
| 3464 | { |
| 3465 | name: "route /a/c/df to /a/c/df", |
| 3466 | whenURL: "/a/c/df", |
| 3467 | expectRoute: "/a/c/df", |
| 3468 | expectID: 1, |
| 3469 | }, |
| 3470 | } |
| 3471 | |
| 3472 | for _, tc := range testCases { |
| 3473 | t.Run(tc.name, func(t *testing.T) { |
| 3474 | e := New() |
| 3475 | e.contextPathParamAllocSize.Store(1) |
| 3476 | r := e.router |
| 3477 | |
| 3478 | r.Add(Route{Method: http.MethodGet, Path: "/", Handler: handlerHelper("ID", 0), Name: "0"}) |
| 3479 | r.Add(Route{Method: http.MethodGet, Path: "/a/c/df", Handler: handlerHelper("ID", 1), Name: "1"}) |
| 3480 | r.Add(Route{Method: http.MethodGet, Path: "/a/b*", Handler: handlerHelper("ID", 2), Name: "2"}) |
| 3481 | r.Add(Route{Method: http.MethodPut, Path: "/*", Handler: handlerHelper("ID", 3), Name: "3"}) |
| 3482 | |
| 3483 | r.Add(Route{Method: RouteNotFound, Path: "/a/c/d:file", Handler: handlerHelper("ID", 6), Name: "6"}) |
| 3484 | r.Add(Route{Method: RouteNotFound, Path: "/a/:file", Handler: handlerHelper("ID", 5), Name: "5"}) |
| 3485 | r.Add(Route{Method: RouteNotFound, Path: "/:file", Handler: handlerHelper("ID", 4), Name: "4"}) |
| 3486 | |
| 3487 | req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil) |
| 3488 | c := e.NewContext(req, nil) |
| 3489 | |
| 3490 | handler := r.Route(c) |
| 3491 | handler(c) |
| 3492 |
nothing calls this directly
no test coverage detected
searching dependent graphs…