| 2833 | } |
| 2834 | |
| 2835 | func TestRouter_Routes(t *testing.T) { |
| 2836 | routes := []*Route{ |
| 2837 | {Method: http.MethodGet, Path: "/users/:user/events"}, |
| 2838 | {Method: http.MethodGet, Path: "/users/:user/events/public"}, |
| 2839 | {Method: http.MethodPost, Path: "/repos/:owner/:repo/git/refs"}, |
| 2840 | {Method: http.MethodPost, Path: "/repos/:owner/:repo/git/tags"}, |
| 2841 | } |
| 2842 | router := NewRouter(RouterConfig{}) |
| 2843 | for _, r := range routes { |
| 2844 | _, err := router.Add(Route{ |
| 2845 | Method: r.Method, |
| 2846 | Path: r.Path, |
| 2847 | Handler: func(c *Context) error { |
| 2848 | return c.String(http.StatusOK, "OK") |
| 2849 | }, |
| 2850 | }) |
| 2851 | if err != nil { |
| 2852 | t.Fatal(err) |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | assert.Equal(t, len(routes), len(router.Routes())) |
| 2857 | for _, r := range router.Routes() { |
| 2858 | found := false |
| 2859 | for _, rr := range routes { |
| 2860 | if r.Method == rr.Method && r.Path == rr.Path { |
| 2861 | found = true |
| 2862 | break |
| 2863 | } |
| 2864 | } |
| 2865 | if !found { |
| 2866 | t.Errorf("Route %s %s not found", r.Method, r.Path) |
| 2867 | } |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | func TestRouterNoRoutablePath(t *testing.T) { |
| 2872 | e := New() |