(t *testing.T)
| 80 | } |
| 81 | |
| 82 | func 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 | |
| 136 | func TestRoute_ForGroup(t *testing.T) { |
| 137 | route := Route{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…