(t *testing.T)
| 307 | } |
| 308 | |
| 309 | func TestGroup_RouteNotFound(t *testing.T) { |
| 310 | var testCases = []struct { |
| 311 | expectRoute any |
| 312 | name string |
| 313 | whenURL string |
| 314 | expectCode int |
| 315 | }{ |
| 316 | { |
| 317 | name: "404, route to static not found handler /group/a/c/xx", |
| 318 | whenURL: "/group/a/c/xx", |
| 319 | expectRoute: "GET /group/a/c/xx", |
| 320 | expectCode: http.StatusNotFound, |
| 321 | }, |
| 322 | { |
| 323 | name: "404, route to path param not found handler /group/a/:file", |
| 324 | whenURL: "/group/a/echo.exe", |
| 325 | expectRoute: "GET /group/a/:file", |
| 326 | expectCode: http.StatusNotFound, |
| 327 | }, |
| 328 | { |
| 329 | name: "404, route to any not found handler /group/*", |
| 330 | whenURL: "/group/b/echo.exe", |
| 331 | expectRoute: "GET /group/*", |
| 332 | expectCode: http.StatusNotFound, |
| 333 | }, |
| 334 | { |
| 335 | name: "200, route /group/a/c/df to /group/a/c/df", |
| 336 | whenURL: "/group/a/c/df", |
| 337 | expectRoute: "GET /group/a/c/df", |
| 338 | expectCode: http.StatusOK, |
| 339 | }, |
| 340 | } |
| 341 | |
| 342 | for _, tc := range testCases { |
| 343 | t.Run(tc.name, func(t *testing.T) { |
| 344 | e := New() |
| 345 | g := e.Group("/group") |
| 346 | |
| 347 | okHandler := func(c *Context) error { |
| 348 | return c.String(http.StatusOK, c.Request().Method+" "+c.Path()) |
| 349 | } |
| 350 | notFoundHandler := func(c *Context) error { |
| 351 | return c.String(http.StatusNotFound, c.Request().Method+" "+c.Path()) |
| 352 | } |
| 353 | |
| 354 | g.GET("/", okHandler) |
| 355 | g.GET("/a/c/df", okHandler) |
| 356 | g.GET("/a/b*", okHandler) |
| 357 | g.PUT("/*", okHandler) |
| 358 | |
| 359 | g.RouteNotFound("/a/c/xx", notFoundHandler) // static |
| 360 | g.RouteNotFound("/a/:file", notFoundHandler) // param |
| 361 | g.RouteNotFound("/*", notFoundHandler) // any |
| 362 | |
| 363 | req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil) |
| 364 | rec := httptest.NewRecorder() |
| 365 | |
| 366 | e.ServeHTTP(rec, req) |
nothing calls this directly
no test coverage detected
searching dependent graphs…