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

Function TestRouterParamStaticConflict

router_test.go:1282–1320  ·  view source on GitHub ↗

Issue #1509

(t *testing.T)

Source from the content-addressed store, hash-verified

1280
1281// Issue #1509
1282func TestRouterParamStaticConflict(t *testing.T) {
1283 e := New()
1284
1285 g := e.Group("/g")
1286 g.GET("/skills", handlerFunc)
1287 g.GET("/status", handlerFunc)
1288 g.GET("/:name", handlerFunc)
1289
1290 var testCases = []struct {
1291 expectRoute any
1292 expectParam map[string]string
1293 whenURL string
1294 }{
1295 {
1296 whenURL: "/g/s",
1297 expectRoute: "/g/:name",
1298 expectParam: map[string]string{"name": "s"},
1299 },
1300 {
1301 whenURL: "/g/status",
1302 expectRoute: "/g/status",
1303 expectParam: map[string]string{"name": ""},
1304 },
1305 }
1306 for _, tc := range testCases {
1307 t.Run(tc.whenURL, func(t *testing.T) {
1308 c := e.NewContext(httptest.NewRequest(http.MethodGet, tc.whenURL, nil), nil)
1309
1310 handler := e.router.Route(c)
1311
1312 assert.NoError(t, handler(c))
1313 assert.Equal(t, tc.expectRoute, c.Path())
1314 for param, expectedValue := range tc.expectParam {
1315 assert.Equal(t, expectedValue, c.pathValues.GetOr(param, ""))
1316 }
1317 checkUnusedParamValues(t, c, tc.expectParam)
1318 })
1319 }
1320}
1321
1322func TestRouterParam_escapeColon(t *testing.T) {
1323 // to allow Google cloud API like route paths with colon in them

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
GroupMethod · 0.45
GETMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…