Skip to content

Commit e33d656

Browse files
joshfreeCopilot
andcommitted
test(transport): satisfy bodyclose in etag_test helpers
The do/helper closures returned *http.Response, which the bodyclose linter flags at each call site even though the body is closed inside the closure. Return only the asserted values (status code, body, and headers) so no response escapes the helper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4959e1f9-f8e6-4e97-a487-f395a0123c79
1 parent eb8c3fc commit e33d656

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

pkg/http/transport/etag_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,24 @@ func TestETagTransport_ServesCachedBodyOn304(t *testing.T) {
4242

4343
rt := &ETagTransport{Transport: http.DefaultTransport}
4444

45-
do := func() (*http.Response, string) {
45+
do := func() (int, string) {
4646
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil)
4747
require.NoError(t, err)
4848
resp, err := rt.RoundTrip(req)
4949
require.NoError(t, err)
5050
defer resp.Body.Close()
5151
data, err := io.ReadAll(resp.Body)
5252
require.NoError(t, err)
53-
return resp, string(data)
53+
return resp.StatusCode, string(data)
5454
}
5555

56-
resp1, body1 := do()
57-
assert.Equal(t, http.StatusOK, resp1.StatusCode)
56+
status1, body1 := do()
57+
assert.Equal(t, http.StatusOK, status1)
5858
assert.Equal(t, body, body1)
5959
assert.Empty(t, lastIfNoneMatch, "first request must not send If-None-Match")
6060

61-
resp2, body2 := do()
62-
assert.Equal(t, http.StatusOK, resp2.StatusCode, "304 is translated to the cached 200")
61+
status2, body2 := do()
62+
assert.Equal(t, http.StatusOK, status2, "304 is translated to the cached 200")
6363
assert.Equal(t, body, body2, "cached body is served on 304")
6464
assert.Equal(t, etag, lastIfNoneMatch, "second request sends the cached ETag")
6565
assert.Equal(t, int32(2), atomic.LoadInt32(&requests), "every request still reaches the server")
@@ -90,21 +90,21 @@ func TestETagTransport_UpdatesRateLimitHeadersFrom304(t *testing.T) {
9090

9191
rt := &ETagTransport{Transport: http.DefaultTransport}
9292

93-
do := func() *http.Response {
93+
do := func() http.Header {
9494
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, server.URL, nil)
9595
require.NoError(t, err)
9696
resp, err := rt.RoundTrip(req)
9797
require.NoError(t, err)
9898
_, _ = io.Copy(io.Discard, resp.Body)
9999
resp.Body.Close()
100-
return resp
100+
return resp.Header
101101
}
102102

103-
resp1 := do()
104-
assert.Equal(t, "100", resp1.Header.Get("X-RateLimit-Remaining"))
103+
h1 := do()
104+
assert.Equal(t, "100", h1.Get("X-RateLimit-Remaining"))
105105

106-
resp2 := do()
107-
assert.Equal(t, "99", resp2.Header.Get("X-RateLimit-Remaining"), "rate-limit headers come from the live 304")
106+
h2 := do()
107+
assert.Equal(t, "99", h2.Get("X-RateLimit-Remaining"), "rate-limit headers come from the live 304")
108108
}
109109

110110
// TestETagTransport_ScopesCacheByAuthorization verifies cached bodies are not

0 commit comments

Comments
 (0)