(t *testing.T)
| 1674 | } |
| 1675 | } |
| 1676 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…