| 1446 | } |
| 1447 | |
| 1448 | func TestMiddlewarePanicOnLateUse(t *testing.T) { |
| 1449 | handler := func(w http.ResponseWriter, r *http.Request) { |
| 1450 | w.Write([]byte("hello\n")) |
| 1451 | } |
| 1452 | |
| 1453 | mw := func(next http.Handler) http.Handler { |
| 1454 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1455 | next.ServeHTTP(w, r) |
| 1456 | }) |
| 1457 | } |
| 1458 | |
| 1459 | defer func() { |
| 1460 | if recover() == nil { |
| 1461 | t.Error("expected panic()") |
| 1462 | } |
| 1463 | }() |
| 1464 | |
| 1465 | r := NewRouter() |
| 1466 | r.Get("/", handler) |
| 1467 | r.Use(mw) // Too late to apply middleware, we're expecting panic(). |
| 1468 | } |
| 1469 | |
| 1470 | func TestMountingExistingPath(t *testing.T) { |
| 1471 | handler := func(w http.ResponseWriter, r *http.Request) {} |