(t *testing.T)
| 1385 | } |
| 1386 | |
| 1387 | func TestRouterMatchAny(t *testing.T) { |
| 1388 | e := New() |
| 1389 | |
| 1390 | // Routes |
| 1391 | e.GET("/", handlerFunc) |
| 1392 | e.GET("/*", handlerFunc) |
| 1393 | e.GET("/users/*", handlerFunc) |
| 1394 | |
| 1395 | var testCases = []struct { |
| 1396 | expectRoute any |
| 1397 | expectParam map[string]string |
| 1398 | whenURL string |
| 1399 | }{ |
| 1400 | { |
| 1401 | whenURL: "/", |
| 1402 | expectRoute: "/", |
| 1403 | expectParam: map[string]string{"*": ""}, |
| 1404 | }, |
| 1405 | { |
| 1406 | whenURL: "/download", |
| 1407 | expectRoute: "/*", |
| 1408 | expectParam: map[string]string{"*": "download"}, |
| 1409 | }, |
| 1410 | { |
| 1411 | whenURL: "/users/joe", |
| 1412 | expectRoute: "/users/*", |
| 1413 | expectParam: map[string]string{"*": "joe"}, |
| 1414 | }, |
| 1415 | } |
| 1416 | for _, tc := range testCases { |
| 1417 | t.Run(tc.whenURL, func(t *testing.T) { |
| 1418 | c := e.NewContext(httptest.NewRequest(http.MethodGet, tc.whenURL, nil), nil) |
| 1419 | |
| 1420 | handler := e.router.Route(c) |
| 1421 | |
| 1422 | assert.NoError(t, handler(c)) |
| 1423 | assert.Equal(t, tc.expectRoute, c.Path()) |
| 1424 | for param, expectedValue := range tc.expectParam { |
| 1425 | assert.Equal(t, expectedValue, c.pathValues.GetOr(param, "")) |
| 1426 | } |
| 1427 | checkUnusedParamValues(t, c, tc.expectParam) |
| 1428 | }) |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | // NOTE: this is to document current implementation. Last added route with `*` asterisk is always the match and no |
| 1433 | // backtracking or more precise matching is done to find more suitable match. |
nothing calls this directly
no test coverage detected
searching dependent graphs…