Skip to content

Comments

Replace client.Get with http.NewRequestWithContext in tests#46

Open
JamieMagee wants to merge 1 commit intomainfrom
jamiemagee/fix-noctx-lint
Open

Replace client.Get with http.NewRequestWithContext in tests#46
JamieMagee wants to merge 1 commit intomainfrom
jamiemagee/fix-noctx-lint

Conversation

@JamieMagee
Copy link
Member

@JamieMagee JamieMagee commented Feb 11, 2026

Three places in proxy_test.go call client.Get(url), which doesn't accept a context. The noctx linter catches this because any outgoing HTTP request should carry a context for cancellation and tracing.

Each call site now builds an http.Request withhttp.NewRequestWithContext(context.Background(), ...) and uses client.Do(req) instead.

client.Get doesn't take a context, so the noctx linter flags it. Switch
the three call sites in proxy_test.go to build an explicit request with
context.Background() and use client.Do instead.
Copilot AI review requested due to automatic review settings February 11, 2026 16:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates proxy integration tests to ensure outbound HTTP requests are created with an explicit context (to satisfy noctx linting) by replacing client.Get(url) with http.NewRequestWithContext(...)+client.Do(req).

Changes:

  • Replace client.Get(url) with http.NewRequestWithContext(context.Background(), ...) and client.Do(req) in TestProxyHTTPRequest.
  • Apply the same request construction pattern in both HTTP and HTTPS subtests within TestIPRestrictions.
Comments suppressed due to low confidence (1)

proxy_test.go:50

  • If client.Do(req) returns an error, the test logs it but continues and then dereferences rsp.Body, which will panic when rsp is nil. Fail fast (t.Fatalf/require.NoError) or return before using rsp.
	rsp, err := client.Do(req)
	if err != nil {
		t.Errorf("making proxied request: %v", err)
	}
	defer rsp.Body.Close()
	assert.Equal(t, 200, rsp.StatusCode)

Comment on lines +42 to 47
t.Errorf("initializing new request: %v", err)
}

rsp, err := client.Do(req)
if err != nil {
t.Errorf("making proxied request: %v", err)
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant