| 610 | } |
| 611 | |
| 612 | func TestListOfRoutes(t *testing.T) { |
| 613 | router := New() |
| 614 | router.GET("/favicon.ico", handlerTest1) |
| 615 | router.GET("/", handlerTest1) |
| 616 | group := router.Group("/users") |
| 617 | { |
| 618 | group.GET("/", handlerTest2) |
| 619 | group.GET("/:id", handlerTest1) |
| 620 | group.POST("/:id", handlerTest2) |
| 621 | } |
| 622 | router.Static("/static", ".") |
| 623 | |
| 624 | list := router.Routes() |
| 625 | |
| 626 | assert.Len(t, list, 7) |
| 627 | assertRoutePresent(t, list, RouteInfo{ |
| 628 | Method: http.MethodGet, |
| 629 | Path: "/favicon.ico", |
| 630 | Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$", |
| 631 | }) |
| 632 | assertRoutePresent(t, list, RouteInfo{ |
| 633 | Method: http.MethodGet, |
| 634 | Path: "/", |
| 635 | Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$", |
| 636 | }) |
| 637 | assertRoutePresent(t, list, RouteInfo{ |
| 638 | Method: http.MethodGet, |
| 639 | Path: "/users/", |
| 640 | Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest2$", |
| 641 | }) |
| 642 | assertRoutePresent(t, list, RouteInfo{ |
| 643 | Method: http.MethodGet, |
| 644 | Path: "/users/:id", |
| 645 | Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$", |
| 646 | }) |
| 647 | assertRoutePresent(t, list, RouteInfo{ |
| 648 | Method: http.MethodPost, |
| 649 | Path: "/users/:id", |
| 650 | Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest2$", |
| 651 | }) |
| 652 | } |
| 653 | |
| 654 | func TestEngineHandleContext(t *testing.T) { |
| 655 | r := New() |