(t *testing.T, api []testRoute)
| 2215 | } |
| 2216 | |
| 2217 | func testRouterAPI(t *testing.T, api []testRoute) { |
| 2218 | e := New() |
| 2219 | |
| 2220 | for _, route := range api { |
| 2221 | ri, err := e.AddRoute(Route{ |
| 2222 | Method: route.Method, |
| 2223 | Path: route.Path, |
| 2224 | Handler: func(c *Context) error { |
| 2225 | return nil |
| 2226 | }, |
| 2227 | }) |
| 2228 | assert.NoError(t, err) |
| 2229 | assert.NotNil(t, ri) |
| 2230 | } |
| 2231 | |
| 2232 | c := e.NewContext(nil, nil) |
| 2233 | for _, route := range api { |
| 2234 | t.Run(route.Path, func(t *testing.T) { |
| 2235 | c.SetRequest(httptest.NewRequest(route.Method, route.Path, nil)) |
| 2236 | e.router.Route(c) |
| 2237 | |
| 2238 | tokens := strings.SplitSeq(route.Path[1:], "/") |
| 2239 | for token := range tokens { |
| 2240 | if token[0] == ':' { |
| 2241 | assert.Equal(t, c.pathValues.GetOr(token[1:], "---none---"), token) |
| 2242 | } |
| 2243 | } |
| 2244 | }) |
| 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | func TestRouterGitHubAPI(t *testing.T) { |
| 2249 | testRouterAPI(t, gitHubAPI) |
no test coverage detected
searching dependent graphs…