From 8c40c7faa3a939529eb4f99c1e81e67d198ae153 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Mon, 1 Dec 2025 23:37:50 +0000 Subject: [PATCH] test: Add panic recovery test for ErrorHandler Tests that panics in handlers are recovered and return 500. Coverage: 91.7% to 100%. --- internal/api/middleware_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/api/middleware_test.go b/internal/api/middleware_test.go index 410ecee..ea25bb5 100644 --- a/internal/api/middleware_test.go +++ b/internal/api/middleware_test.go @@ -460,3 +460,20 @@ func TestErrorHandler_EmptyPath(t *testing.T) { t.Errorf("expected empty path to be normalized to '/', got %q", capturedPath) } } + +func TestErrorHandler_PanicRecovery(t *testing.T) { + // Test that panics are recovered and return 500 + handler := ErrorHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + panic("test panic") + })) + + req := httptest.NewRequest(http.MethodGet, "/test", nil) + rec := httptest.NewRecorder() + + // Should not panic - ErrorHandler recovers it + handler.ServeHTTP(rec, req) + + if rec.Code != http.StatusInternalServerError { + t.Errorf("expected 500 after panic recovery, got %d", rec.Code) + } +}