MCPcopy Index your code
hub / github.com/labstack/echo / TestPathValuesSizeOverMultipleRequests

Function TestPathValuesSizeOverMultipleRequests

router_test.go:2519–2546  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2517}
2518
2519func TestPathValuesSizeOverMultipleRequests(t *testing.T) {
2520 e := New()
2521 e.GET("/test/:id/:action", handlerFunc) // max params is 2
2522
2523 req := httptest.NewRequest(http.MethodGet, "/test/1/a", nil)
2524 rec := httptest.NewRecorder()
2525
2526 c := e.AcquireContext()
2527 c.Reset(req, rec)
2528 assert.Equal(t, 0, len(*c.pathValues)) // fresh context is empty
2529 assert.Equal(t, 2, cap(*c.pathValues)) // is set max path params amount
2530
2531 // imitate some (pre)middleware changing/replacing pathparams to smaller size
2532 c.SetPathValues(PathValues{
2533 {Name: "id", Value: "1"},
2534 })
2535 assert.Equal(t, 1, len(*c.pathValues)) // as SetPathValues was provided
2536 assert.Equal(t, 2, cap(*c.pathValues)) // SetPathValues did not change that to smaller
2537
2538 handler := e.router.Route(c)
2539 e.ReleaseContext(c)
2540
2541 assert.NoError(t, handler(c))
2542 assert.Equal(t, 2, len(*c.pathValues)) // matched route had 2 path params
2543 assert.Equal(t, 2, cap(*c.pathValues)) // was not changed
2544 assert.Equal(t, "1", c.Param("id"))
2545 assert.Equal(t, "a", c.Param("action"))
2546}
2547
2548// Issue #1655
2549func TestRouterFindNotPanicOrLoopsWhenContextSetParamValuesIsCalledWithLessValuesThanEchoMaxParam(t *testing.T) {

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
AcquireContextMethod · 0.80
SetPathValuesMethod · 0.80
ReleaseContextMethod · 0.80
ParamMethod · 0.80
RouteMethod · 0.65
GETMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…