(t *testing.T)
| 206 | } |
| 207 | |
| 208 | func TestRoutes_FindByMethodPath(t *testing.T) { |
| 209 | var testCases = []struct { |
| 210 | name string |
| 211 | whenMethod string |
| 212 | whenPath string |
| 213 | expectName string |
| 214 | expectError string |
| 215 | given Routes |
| 216 | }{ |
| 217 | { |
| 218 | name: "ok, found", |
| 219 | given: exampleRoutes(), |
| 220 | whenMethod: http.MethodGet, |
| 221 | whenPath: "/users/:id", |
| 222 | expectName: "GET:/users/:id", |
| 223 | }, |
| 224 | { |
| 225 | name: "nok, not found", |
| 226 | given: exampleRoutes(), |
| 227 | whenMethod: http.MethodPut, |
| 228 | whenPath: "/users/:id", |
| 229 | expectName: "", |
| 230 | expectError: "route not found by method and path", |
| 231 | }, |
| 232 | { |
| 233 | name: "nok, not found from nil", |
| 234 | given: nil, |
| 235 | whenMethod: http.MethodGet, |
| 236 | whenPath: "/users/:id", |
| 237 | expectName: "", |
| 238 | expectError: "route not found by method and path", |
| 239 | }, |
| 240 | } |
| 241 | |
| 242 | for _, tc := range testCases { |
| 243 | t.Run(tc.name, func(t *testing.T) { |
| 244 | ri, err := tc.given.FindByMethodPath(tc.whenMethod, tc.whenPath) |
| 245 | |
| 246 | if tc.expectError != "" { |
| 247 | assert.EqualError(t, err, tc.expectError) |
| 248 | assert.Equal(t, RouteInfo{}, ri) |
| 249 | } else { |
| 250 | assert.NoError(t, err) |
| 251 | } |
| 252 | if tc.expectName != "" { |
| 253 | assert.Equal(t, tc.expectName, ri.Name) |
| 254 | } |
| 255 | }) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | func TestRoutes_FilterByMethod(t *testing.T) { |
| 260 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…