From 89638d29bbe40688eaf9c4bbdbd42d9ee843dd40 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Mon, 30 Mar 2026 00:36:50 +0700 Subject: [PATCH] Improve URL assertion logic in reverse proxy tests. Updated assertSameURL function in reverse_test.go to handle nil URLs and enhance comparison logic, ensuring more accurate URL mismatch reporting and better test reliability. --- internal/proxy/reverse_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/proxy/reverse_test.go b/internal/proxy/reverse_test.go index acb4837..f8eb33a 100644 --- a/internal/proxy/reverse_test.go +++ b/internal/proxy/reverse_test.go @@ -133,7 +133,15 @@ func TestBuildUpstreamURLRoundTrip(t *testing.T) { func assertSameURL(t *testing.T, got, want *url.URL) { t.Helper() - if got.Scheme != want.Scheme || got.Host != want.Host || got.Path != want.Path || got.RawQuery != want.RawQuery { - t.Fatalf("URL mismatch\ngot %q\nwant %q", got.String(), want.String()) + if got == nil || want == nil { + t.Fatalf("nil URL: got=%v want=%v", got, want) } + // JoinPath vs url.Parse can differ in Path vs RawPath while String() is identical. + if got.String() == want.String() { + return + } + if got.Scheme == want.Scheme && got.Host == want.Host && got.RawQuery == want.RawQuery && got.EscapedPath() == want.EscapedPath() { + return + } + t.Fatalf("URL mismatch\ngot %q\nwant %q", got.String(), want.String()) }