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

Function TestRouterParam

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

Source from the content-addressed store, hash-verified

703}
704
705func TestRouterParam(t *testing.T) {
706 e := New()
707
708 e.GET("/users/:id", handlerFunc)
709
710 var testCases = []struct {
711 expectRoute any
712 expectParam map[string]string
713 name string
714 whenURL string
715 }{
716 {
717 name: "route /users/1 to /users/:id",
718 whenURL: "/users/1",
719 expectRoute: "/users/:id",
720 expectParam: map[string]string{"id": "1"},
721 },
722 {
723 name: "route /users/1/ to /users/:id",
724 whenURL: "/users/1/",
725 expectRoute: "/users/:id",
726 expectParam: map[string]string{"id": "1/"},
727 },
728 }
729
730 for _, tc := range testCases {
731 t.Run(tc.name, func(t *testing.T) {
732 c := e.NewContext(nil, nil)
733 c.SetRequest(httptest.NewRequest(http.MethodGet, tc.whenURL, nil))
734 _ = e.router.Route(c)
735
736 assert.Equal(t, tc.expectRoute, c.Path())
737 for param, expectedValue := range tc.expectParam {
738 assert.Equal(t, expectedValue, c.pathValues.GetOr(param, "---none---"))
739 }
740 checkUnusedParamValues(t, c, tc.expectParam)
741 })
742 }
743}
744
745func TestRouter_addAndMatchAllSupportedMethods(t *testing.T) {
746 var testCases = []struct {

Callers

nothing calls this directly

Calls 8

SetRequestMethod · 0.95
PathMethod · 0.95
NewFunction · 0.85
checkUnusedParamValuesFunction · 0.85
NewContextMethod · 0.80
GetOrMethod · 0.80
RouteMethod · 0.65
GETMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…