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

Function TestRoutes_ReverseHandlerName

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

Source from the content-addressed store, hash-verified

2669}
2670
2671func TestRoutes_ReverseHandlerName(t *testing.T) {
2672 static := func(*Context) error { return nil }
2673 getUser := func(*Context) error { return nil }
2674 getAny := func(*Context) error { return nil }
2675 getFile := func(*Context) error { return nil }
2676
2677 var testCases = []struct {
2678 name string
2679 when string
2680 expect string
2681 expectErr string
2682 whenArgs []any
2683 }{
2684 {
2685 name: "ok, HandlerName + args",
2686 when: HandlerName(getFile),
2687 whenArgs: []any{"1"},
2688 expect: "/group/users/1/files/:fid",
2689 },
2690 {
2691 name: "ok, HandlerName",
2692 when: HandlerName(getFile),
2693 expect: "/group/users/:uid/files/:fid",
2694 },
2695 {
2696 name: "ok, unnamed fixed name",
2697 when: "GET:/static/file",
2698 expect: "/static/file",
2699 },
2700 {
2701 name: "ok, unnamed fixed name",
2702 when: "GET:/users/:id",
2703 expect: "/users/:id",
2704 },
2705 {
2706 name: "ok, unnamed any route",
2707 when: RouteAny + ":/documents/*",
2708 expect: "/documents/*",
2709 },
2710 {
2711 name: "ok, unnamed any route + args",
2712 when: RouteAny + ":/documents/*",
2713 whenArgs: []any{"index.html"},
2714 expect: "/documents/index.html",
2715 },
2716 {
2717 name: "ok, named route + args",
2718 when: HandlerName(getFile),
2719 whenArgs: []any{"1", "abc"},
2720 expect: "/group/users/1/files/abc",
2721 },
2722 }
2723
2724 for _, tc := range testCases {
2725 t.Run(tc.name, func(t *testing.T) {
2726 e := New()
2727 e.GET("/static/file", static)
2728 e.GET("/users/:id", getUser)

Callers

nothing calls this directly

Calls 9

HandlerNameFunction · 0.85
NewFunction · 0.85
RouterMethod · 0.80
RoutesMethod · 0.65
GETMethod · 0.45
AnyMethod · 0.45
GroupMethod · 0.45
AddRouteMethod · 0.45
ReverseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…