Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func TestProxyHTTPRequest(t *testing.T) {
url, httpSrv := testHTTPServer(t)
defer httpSrv.Close()

rsp, err := client.Get(url)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
if err != nil {
t.Errorf("initializing new request: %v", err)
}

rsp, err := client.Do(req)
if err != nil {
t.Errorf("making proxied request: %v", err)
Comment on lines +42 to 47
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If NewRequestWithContext fails, the test currently logs the error but continues, leaving req nil and causing client.Do(req) to panic. Use a fatal assertion (t.Fatalf/require.NoError) or return immediately after reporting the error.

This issue also appears on line 45 of the same file.

Suggested change
t.Errorf("initializing new request: %v", err)
}
rsp, err := client.Do(req)
if err != nil {
t.Errorf("making proxied request: %v", err)
t.Fatalf("initializing new request: %v", err)
}
rsp, err := client.Do(req)
if err != nil {
t.Fatalf("making proxied request: %v", err)

Copilot uses AI. Check for mistakes.
}
Expand All @@ -63,7 +68,13 @@ func TestIPRestrictions(t *testing.T) {

for _, url := range httpTestCases {
t.Run(url, func(t *testing.T) {
rsp, err := client.Get(url)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
if err != nil {
t.Errorf("initializing new request: %v", err)
return
}

rsp, err := client.Do(req)
if err != nil {
t.Errorf("making proxied request: %v", err)
return
Expand All @@ -86,7 +97,13 @@ func TestIPRestrictions(t *testing.T) {
// the connection from being established while goproxy tries to setup TLS
for _, url := range httpsTestCases {
t.Run(url, func(t *testing.T) {
_, err := client.Get(url) //nolint:bodyclose // error expected, no body to close
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
if err != nil {
t.Errorf("initializing new request: %v", err)
return
}

_, err = client.Do(req) //nolint:bodyclose // error expected, no body to close
assert.Error(t, err)
})
}
Expand Down
Loading