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

Function TestRoute_ToRouteInfo

route_test.go:82–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestRoute_ToRouteInfo(t *testing.T) {
83 var testCases = []struct {
84 expect RouteInfo
85 given Route
86 name string
87 whenParams []string
88 }{
89 {
90 name: "ok, no params, with name",
91 given: Route{
92 Method: http.MethodGet,
93 Path: "/test",
94 Handler: func(c *Context) error {
95 return c.String(http.StatusTeapot, "OK")
96 },
97 Middlewares: nil,
98 Name: "test route",
99 },
100 expect: RouteInfo{
101 Method: http.MethodGet,
102 Path: "/test",
103 Parameters: nil,
104 Name: "test route",
105 },
106 },
107 {
108 name: "ok, params",
109 given: Route{
110 Method: http.MethodGet,
111 Path: "users/:id/:file", // no slash prefix
112 Handler: func(c *Context) error {
113 return c.String(http.StatusTeapot, "OK")
114 },
115 Middlewares: nil,
116 Name: "",
117 },
118 whenParams: []string{"id", "file"},
119 expect: RouteInfo{
120 Method: http.MethodGet,
121 Path: "users/:id/:file",
122 Parameters: []string{"id", "file"},
123 Name: "GET:users/:id/:file",
124 },
125 },
126 }
127
128 for _, tc := range testCases {
129 t.Run(tc.name, func(t *testing.T) {
130 ri := tc.given.ToRouteInfo(tc.whenParams)
131 assert.Equal(t, tc.expect, ri)
132 })
133 }
134}
135
136func TestRoute_ForGroup(t *testing.T) {
137 route := Route{

Callers

nothing calls this directly

Calls 2

ToRouteInfoMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…