MCPcopy
hub / github.com/go-chi/chi / TestMiddlewarePanicOnLateUse

Function TestMiddlewarePanicOnLateUse

mux_test.go:1448–1468  ·  mux_test.go::TestMiddlewarePanicOnLateUse
(t *testing.T)

Source from the content-addressed store, hash-verified

1446}
1447
1448func 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
1470func TestMountingExistingPath(t *testing.T) {
1471 handler := func(w http.ResponseWriter, r *http.Request) {}

Callers

nothing calls this directly

Calls 6

GetMethod · 0.95
UseMethod · 0.95
NewRouterFunction · 0.85
HandlerFuncMethod · 0.80
WriteMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected