Issue #1739
(t *testing.T)
| 1461 | |
| 1462 | // Issue #1739 |
| 1463 | func TestRouterMatchAnyPrefixIssue(t *testing.T) { |
| 1464 | e := New() |
| 1465 | |
| 1466 | // Routes |
| 1467 | e.GET("/*", handlerFunc) |
| 1468 | e.GET("/users/*", handlerFunc) |
| 1469 | |
| 1470 | var testCases = []struct { |
| 1471 | expectRoute any |
| 1472 | expectParam map[string]string |
| 1473 | whenURL string |
| 1474 | }{ |
| 1475 | { |
| 1476 | whenURL: "/", |
| 1477 | expectRoute: "/*", |
| 1478 | expectParam: map[string]string{"*": ""}, |
| 1479 | }, |
| 1480 | { |
| 1481 | whenURL: "/users", |
| 1482 | expectRoute: "/*", |
| 1483 | expectParam: map[string]string{"*": "users"}, |
| 1484 | }, |
| 1485 | { |
| 1486 | whenURL: "/users/", |
| 1487 | expectRoute: "/users/*", |
| 1488 | expectParam: map[string]string{"*": ""}, |
| 1489 | }, |
| 1490 | { |
| 1491 | whenURL: "/users_prefix", |
| 1492 | expectRoute: "/*", |
| 1493 | expectParam: map[string]string{"*": "users_prefix"}, |
| 1494 | }, |
| 1495 | { |
| 1496 | whenURL: "/users_prefix/", |
| 1497 | expectRoute: "/*", |
| 1498 | expectParam: map[string]string{"*": "users_prefix/"}, |
| 1499 | }, |
| 1500 | } |
| 1501 | for _, tc := range testCases { |
| 1502 | t.Run(tc.whenURL, func(t *testing.T) { |
| 1503 | req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil) |
| 1504 | c := e.NewContext(req, nil) |
| 1505 | handler := e.router.Route(c) |
| 1506 | |
| 1507 | assert.NoError(t, handler(c)) |
| 1508 | assert.Equal(t, tc.expectRoute, c.Path()) |
| 1509 | for param, expectedValue := range tc.expectParam { |
| 1510 | assert.Equal(t, expectedValue, c.pathValues.GetOr(param, "---none---")) |
| 1511 | } |
| 1512 | checkUnusedParamValues(t, c, tc.expectParam) |
| 1513 | }) |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | // TestRouterMatchAnySlash shall verify finding the best route |
| 1518 | // for any routes with trailing slash requests |
nothing calls this directly
no test coverage detected
searching dependent graphs…