test: Add panic recovery test for ErrorHandler
Tests that panics in handlers are recovered and return 500. Coverage: 91.7% to 100%.
This commit is contained in:
parent
d0c2524353
commit
8c40c7faa3
1 changed files with 17 additions and 0 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue