(t *testing.T)
| 175 | } |
| 176 | |
| 177 | func TestRouterChaining(t *testing.T) { |
| 178 | router1 := New() |
| 179 | router2 := New() |
| 180 | router1.NotFound = router2 |
| 181 | |
| 182 | fooHit := false |
| 183 | router1.POST("/foo", func(w http.ResponseWriter, req *http.Request, _ Params) { |
| 184 | fooHit = true |
| 185 | w.WriteHeader(http.StatusOK) |
| 186 | }) |
| 187 | |
| 188 | barHit := false |
| 189 | router2.POST("/bar", func(w http.ResponseWriter, req *http.Request, _ Params) { |
| 190 | barHit = true |
| 191 | w.WriteHeader(http.StatusOK) |
| 192 | }) |
| 193 | |
| 194 | r, _ := http.NewRequest(http.MethodPost, "/foo", nil) |
| 195 | w := httptest.NewRecorder() |
| 196 | router1.ServeHTTP(w, r) |
| 197 | if !(w.Code == http.StatusOK && fooHit) { |
| 198 | t.Errorf("Regular routing failed with router chaining.") |
| 199 | t.FailNow() |
| 200 | } |
| 201 | |
| 202 | r, _ = http.NewRequest(http.MethodPost, "/bar", nil) |
| 203 | w = httptest.NewRecorder() |
| 204 | router1.ServeHTTP(w, r) |
| 205 | if !(w.Code == http.StatusOK && barHit) { |
| 206 | t.Errorf("Chained routing failed with router chaining.") |
| 207 | t.FailNow() |
| 208 | } |
| 209 | |
| 210 | r, _ = http.NewRequest(http.MethodPost, "/qax", nil) |
| 211 | w = httptest.NewRecorder() |
| 212 | router1.ServeHTTP(w, r) |
| 213 | if !(w.Code == http.StatusNotFound) { |
| 214 | t.Errorf("NotFound behavior failed with router chaining.") |
| 215 | t.FailNow() |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | func BenchmarkAllowed(b *testing.B) { |
| 220 | handlerFunc := func(_ http.ResponseWriter, _ *http.Request, _ Params) {} |
nothing calls this directly
no test coverage detected