MCPcopy
hub / github.com/labstack/echo / TestRouterMatchAnySlash

Function TestRouterMatchAnySlash

router_test.go:1519–1601  ·  view source on GitHub ↗

TestRouterMatchAnySlash shall verify finding the best route for any routes with trailing slash requests

(t *testing.T)

Source from the content-addressed store, hash-verified

1517// TestRouterMatchAnySlash shall verify finding the best route
1518// for any routes with trailing slash requests
1519func 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

Callers

nothing calls this directly

Calls 7

PathMethod · 0.95
NewFunction · 0.85
checkUnusedParamValuesFunction · 0.85
NewContextMethod · 0.80
GetOrMethod · 0.80
RouteMethod · 0.65
GETMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…