(t *testing.T)
| 2250 | } |
| 2251 | |
| 2252 | func TestRouter_Match_DifferentParamNamesForSamePlace(t *testing.T) { |
| 2253 | var testCases = []struct { |
| 2254 | expectError error |
| 2255 | expectParam map[string]string |
| 2256 | name string |
| 2257 | whenURL string |
| 2258 | whenMethod string |
| 2259 | expectRoute string |
| 2260 | }{ |
| 2261 | { |
| 2262 | name: "ok, 1=id + 2=file", |
| 2263 | whenURL: "/users/123/file/payroll.csv", |
| 2264 | whenMethod: http.MethodGet, |
| 2265 | expectRoute: "/users/:id/file/:file", |
| 2266 | expectParam: map[string]string{"id": "123", "file": "payroll.csv"}, |
| 2267 | }, |
| 2268 | { |
| 2269 | name: "ok, 1=id2 + 2=file2", |
| 2270 | whenURL: "/users/123/file/payroll.csv", |
| 2271 | whenMethod: http.MethodPost, |
| 2272 | expectRoute: "/users/:id2/file/:file2", |
| 2273 | expectParam: map[string]string{"id2": "123", "file2": "payroll.csv"}, |
| 2274 | }, |
| 2275 | { |
| 2276 | name: "ok, 1=uid", |
| 2277 | whenURL: "/users/999/files", |
| 2278 | whenMethod: http.MethodGet, |
| 2279 | expectRoute: "/users/:uid/files", |
| 2280 | expectParam: map[string]string{"uid": "999"}, |
| 2281 | }, |
| 2282 | } |
| 2283 | |
| 2284 | for _, tc := range testCases { |
| 2285 | t.Run(tc.name, func(t *testing.T) { |
| 2286 | e := New() |
| 2287 | |
| 2288 | e.GET("/users/create", handlerFunc) |
| 2289 | e.GET("/users/:id/file/:file", handlerFunc) |
| 2290 | e.POST("/users/:id2/file/:file2", handlerFunc) |
| 2291 | e.GET("/users/:uid/files", handlerFunc) |
| 2292 | |
| 2293 | req := httptest.NewRequest(tc.whenMethod, tc.whenURL, nil) |
| 2294 | c := e.NewContext(req, nil) |
| 2295 | handler := e.router.Route(c) |
| 2296 | |
| 2297 | err := handler(c) |
| 2298 | if tc.expectError != nil { |
| 2299 | assert.Equal(t, tc.expectError, err) |
| 2300 | } else { |
| 2301 | assert.NoError(t, err) |
| 2302 | } |
| 2303 | assert.Equal(t, tc.expectRoute, c.Path()) |
| 2304 | for param, expectedValue := range tc.expectParam { |
| 2305 | assert.Equal(t, expectedValue, c.pathValues.GetOr(param, "")) |
| 2306 | } |
| 2307 | checkUnusedParamValues(t, c, tc.expectParam) |
| 2308 | }) |
| 2309 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…