test: Add test for ErrorHandler empty URL path normalization

Covers the fix for issue #334 where empty path is normalized to '/'.
Coverage: 87.5% to 91.7%.
This commit is contained in:
rcourtman 2025-12-01 23:21:07 +00:00
parent d69b0bbc86
commit a5369ba2cd

View file

@ -441,3 +441,22 @@ func TestResponseWriter_EdgeCases(t *testing.T) {
}
})
}
func TestErrorHandler_EmptyPath(t *testing.T) {
// Test that empty path is normalized to "/" (fix for issue #334)
var capturedPath string
handler := ErrorHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
capturedPath = r.URL.Path
w.WriteHeader(http.StatusOK)
}))
req := httptest.NewRequest(http.MethodGet, "http://example.com", nil)
req.URL.Path = "" // explicitly set empty path
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, req)
if capturedPath != "/" {
t.Errorf("expected empty path to be normalized to '/', got %q", capturedPath)
}
}