TestRouterMatchAnySlash shall verify finding the best route for any routes with trailing slash requests
(t *testing.T)
| 1517 | // TestRouterMatchAnySlash shall verify finding the best route |
| 1518 | // for any routes with trailing slash requests |
| 1519 | func TestRouterMatchAnySlash(t *testing.T) { |
| 1520 | e := New() |
| 1521 | |
| 1522 | // Routes |
| 1523 | e.GET("/users", handlerFunc) |
| 1524 | e.GET("/users/*", handlerFunc) |
| 1525 | e.GET("/img/*", handlerFunc) |
| 1526 | e.GET("/img/load", handlerFunc) |
| 1527 | e.GET("/img/load/*", handlerFunc) |
| 1528 | e.GET("/assets/*", handlerFunc) |
| 1529 | |
| 1530 | var testCases = []struct { |
| 1531 | expectError error |
| 1532 | expectParam map[string]string |
| 1533 | whenURL string |
| 1534 | expectRoute string |
| 1535 | }{ |
| 1536 | { |
| 1537 | whenURL: "/", |
| 1538 | expectRoute: "", |
| 1539 | expectParam: map[string]string{"*": ""}, |
| 1540 | expectError: ErrNotFound, |
| 1541 | }, |
| 1542 | { // Test trailing slash request for simple any route (see #1526) |
| 1543 | whenURL: "/users/", |
| 1544 | expectRoute: "/users/*", |
| 1545 | expectParam: map[string]string{"*": ""}, |
| 1546 | }, |
| 1547 | { |
| 1548 | whenURL: "/users/joe", |
| 1549 | expectRoute: "/users/*", |
| 1550 | expectParam: map[string]string{"*": "joe"}, |
| 1551 | }, |
| 1552 | // Test trailing slash request for nested any route (see #1526) |
| 1553 | { |
| 1554 | whenURL: "/img/load", |
| 1555 | expectRoute: "/img/load", |
| 1556 | expectParam: map[string]string{"*": ""}, |
| 1557 | }, |
| 1558 | { |
| 1559 | whenURL: "/img/load/", |
| 1560 | expectRoute: "/img/load/*", |
| 1561 | expectParam: map[string]string{"*": ""}, |
| 1562 | }, |
| 1563 | { |
| 1564 | whenURL: "/img/load/ben", |
| 1565 | expectRoute: "/img/load/*", |
| 1566 | expectParam: map[string]string{"*": "ben"}, |
| 1567 | }, |
| 1568 | // Test /assets/* any route |
| 1569 | { // ... without trailing slash must not match |
| 1570 | whenURL: "/assets", |
| 1571 | expectRoute: "", |
| 1572 | expectParam: map[string]string{"*": ""}, |
| 1573 | expectError: ErrNotFound, |
| 1574 | }, |
| 1575 | |
| 1576 | { // ... with trailing slash must match |
nothing calls this directly
no test coverage detected
searching dependent graphs…