(t *testing.T, method string)
| 45 | } |
| 46 | |
| 47 | func performRequestInGroup(t *testing.T, method string) { |
| 48 | router := New() |
| 49 | v1 := router.Group("v1", func(c *Context) {}) |
| 50 | assert.Equal(t, "/v1", v1.BasePath()) |
| 51 | |
| 52 | login := v1.Group("/login/", func(c *Context) {}, func(c *Context) {}) |
| 53 | assert.Equal(t, "/v1/login/", login.BasePath()) |
| 54 | |
| 55 | handler := func(c *Context) { |
| 56 | c.String(http.StatusBadRequest, "the method was %s and index %d", c.Request.Method, c.index) |
| 57 | } |
| 58 | |
| 59 | switch method { |
| 60 | case http.MethodGet: |
| 61 | v1.GET("/test", handler) |
| 62 | login.GET("/test", handler) |
| 63 | case http.MethodPost: |
| 64 | v1.POST("/test", handler) |
| 65 | login.POST("/test", handler) |
| 66 | case http.MethodPut: |
| 67 | v1.PUT("/test", handler) |
| 68 | login.PUT("/test", handler) |
| 69 | case http.MethodPatch: |
| 70 | v1.PATCH("/test", handler) |
| 71 | login.PATCH("/test", handler) |
| 72 | case http.MethodDelete: |
| 73 | v1.DELETE("/test", handler) |
| 74 | login.DELETE("/test", handler) |
| 75 | case http.MethodHead: |
| 76 | v1.HEAD("/test", handler) |
| 77 | login.HEAD("/test", handler) |
| 78 | case http.MethodOptions: |
| 79 | v1.OPTIONS("/test", handler) |
| 80 | login.OPTIONS("/test", handler) |
| 81 | default: |
| 82 | panic("unknown method") |
| 83 | } |
| 84 | |
| 85 | w := PerformRequest(router, method, "/v1/login/test") |
| 86 | assert.Equal(t, http.StatusBadRequest, w.Code) |
| 87 | assert.Equal(t, "the method was "+method+" and index 3", w.Body.String()) |
| 88 | |
| 89 | w = PerformRequest(router, method, "/v1/test") |
| 90 | assert.Equal(t, http.StatusBadRequest, w.Code) |
| 91 | assert.Equal(t, "the method was "+method+" and index 1", w.Body.String()) |
| 92 | } |
| 93 | |
| 94 | func TestRouterGroupInvalidStatic(t *testing.T) { |
| 95 | router := New() |
no test coverage detected