| 79 | } |
| 80 | |
| 81 | func TestMiddlewareNoMethodEnabled(t *testing.T) { |
| 82 | signature := "" |
| 83 | router := New() |
| 84 | router.HandleMethodNotAllowed = true |
| 85 | router.Use(func(c *Context) { |
| 86 | signature += "A" |
| 87 | c.Next() |
| 88 | signature += "B" |
| 89 | }) |
| 90 | router.Use(func(c *Context) { |
| 91 | signature += "C" |
| 92 | c.Next() |
| 93 | signature += "D" |
| 94 | }) |
| 95 | router.NoMethod(func(c *Context) { |
| 96 | signature += "E" |
| 97 | c.Next() |
| 98 | signature += "F" |
| 99 | }, func(c *Context) { |
| 100 | signature += "G" |
| 101 | c.Next() |
| 102 | signature += "H" |
| 103 | }) |
| 104 | router.NoRoute(func(c *Context) { |
| 105 | signature += " X " |
| 106 | }) |
| 107 | router.POST("/", func(c *Context) { |
| 108 | signature += " XX " |
| 109 | }) |
| 110 | // RUN |
| 111 | w := PerformRequest(router, http.MethodGet, "/") |
| 112 | |
| 113 | // TEST |
| 114 | assert.Equal(t, http.StatusMethodNotAllowed, w.Code) |
| 115 | assert.Equal(t, "ACEGHFDB", signature) |
| 116 | } |
| 117 | |
| 118 | func TestMiddlewareNoMethodDisabled(t *testing.T) { |
| 119 | signature := "" |