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

Function TestRouterMatchAnyMultiLevelWithPost

router_test.go:1676–1741  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1674 }
1675}
1676func TestRouterMatchAnyMultiLevelWithPost(t *testing.T) {
1677 e := New()
1678
1679 // Routes
1680 e.POST("/api/auth/login", handlerFunc)
1681 e.POST("/api/auth/forgotPassword", handlerFunc)
1682 e.Any("/api/*", handlerFunc)
1683 e.Any("/*", handlerFunc)
1684
1685 var testCases = []struct {
1686 expectRoute any
1687 expectError error
1688 expectParam map[string]string
1689 whenMethod string
1690 whenURL string
1691 }{
1692 { // POST /api/auth/login shall choose login method
1693 whenURL: "/api/auth/login",
1694 whenMethod: http.MethodPost,
1695 expectRoute: "/api/auth/login",
1696 expectParam: map[string]string{"*": ""},
1697 },
1698 { // POST /api/auth/logout shall choose nearest any route
1699 whenURL: "/api/auth/logout",
1700 whenMethod: http.MethodPost,
1701 expectRoute: "/api/*",
1702 expectParam: map[string]string{"*": "auth/logout"},
1703 },
1704 { // POST to /api/other/test shall choose nearest any route
1705 whenURL: "/api/other/test",
1706 whenMethod: http.MethodPost,
1707 expectRoute: "/api/*",
1708 expectParam: map[string]string{"*": "other/test"},
1709 },
1710 { // GET to /api/other/test shall choose nearest any route
1711 whenURL: "/api/other/test",
1712 whenMethod: http.MethodGet,
1713 expectRoute: "/api/*",
1714 expectParam: map[string]string{"*": "other/test"},
1715 },
1716 }
1717 for _, tc := range testCases {
1718 t.Run(tc.whenURL, func(t *testing.T) {
1719 method := http.MethodGet
1720 if tc.whenMethod != "" {
1721 method = tc.whenMethod
1722 }
1723
1724 req := httptest.NewRequest(method, tc.whenURL, nil)
1725 c := e.NewContext(req, nil)
1726 handler := e.router.Route(c)
1727
1728 err := handler(c)
1729 if tc.expectError != nil {
1730 assert.Equal(t, tc.expectError, err)
1731 } else {
1732 assert.NoError(t, err)
1733 }

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…