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.
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user