(t *testing.T)
| 1320 | } |
| 1321 | |
| 1322 | func TestRouterParam_escapeColon(t *testing.T) { |
| 1323 | // to allow Google cloud API like route paths with colon in them |
| 1324 | // i.e. https://service.name/v1/some/resource/name:customVerb <- that `:customVerb` is not path param. It is just a string |
| 1325 | e := New() |
| 1326 | |
| 1327 | e.POST("/files/a/long/file\\:undelete", handlerFunc) |
| 1328 | e.POST("/multilevel\\:undelete/second\\:something", handlerFunc) |
| 1329 | e.POST("/mixed/:id/second\\:something", handlerFunc) |
| 1330 | e.POST("/v1/some/resource/name:customVerb", handlerFunc) |
| 1331 | |
| 1332 | var testCases = []struct { |
| 1333 | whenURL string |
| 1334 | expectRoute string |
| 1335 | expectParam map[string]string |
| 1336 | expectError string |
| 1337 | }{ |
| 1338 | { |
| 1339 | whenURL: "/files/a/long/file:undelete", |
| 1340 | expectRoute: "/files/a/long/file\\:undelete", |
| 1341 | expectParam: map[string]string{}, |
| 1342 | }, |
| 1343 | { |
| 1344 | whenURL: "/multilevel:undelete/second:something", |
| 1345 | expectRoute: "/multilevel\\:undelete/second\\:something", |
| 1346 | expectParam: map[string]string{}, |
| 1347 | }, |
| 1348 | { |
| 1349 | whenURL: "/mixed/123/second:something", |
| 1350 | expectRoute: "/mixed/:id/second\\:something", |
| 1351 | expectParam: map[string]string{"id": "123"}, |
| 1352 | }, |
| 1353 | { |
| 1354 | whenURL: "/files/a/long/file:notMatching", |
| 1355 | expectRoute: "", |
| 1356 | expectError: "Not Found", |
| 1357 | expectParam: nil, |
| 1358 | }, |
| 1359 | { |
| 1360 | whenURL: "/v1/some/resource/name:PATCH", |
| 1361 | expectRoute: "/v1/some/resource/name:customVerb", |
| 1362 | expectParam: map[string]string{"customVerb": ":PATCH"}, |
| 1363 | }, |
| 1364 | } |
| 1365 | for _, tc := range testCases { |
| 1366 | t.Run(tc.whenURL, func(t *testing.T) { |
| 1367 | req := httptest.NewRequest(http.MethodPost, tc.whenURL, nil) |
| 1368 | c := e.NewContext(req, nil) |
| 1369 | handler := e.router.Route(c) |
| 1370 | |
| 1371 | err := handler(c) |
| 1372 | |
| 1373 | assert.Equal(t, tc.expectRoute, c.Path()) |
| 1374 | if tc.expectError != "" { |
| 1375 | assert.EqualError(t, err, tc.expectError) |
| 1376 | } else { |
| 1377 | assert.NoError(t, err) |
| 1378 | } |
| 1379 | for param, expectedValue := range tc.expectParam { |
nothing calls this directly
no test coverage detected
searching dependent graphs…