Skip to content

Commit 6a947d2

Browse files
iosmanthusclaude
andcommitted
pkg/utils/apiutil: fix lint errors in TestEnsureRewindableBody
Move `require.New(t)` into each subtest so that failures are attributed to the correct sub-`*testing.T`, and apply minor lint fixes (unused param, intrange). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
1 parent c71d947 commit 6a947d2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/utils/apiutil/apiutil_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func TestGetIPPortFromHTTPRequest(t *testing.T) {
213213

214214
type errReader struct{ err error }
215215

216-
func (e *errReader) Read(p []byte) (int, error) { return 0, e.err }
216+
func (e *errReader) Read(_ []byte) (int, error) { return 0, e.err }
217217
func (*errReader) Close() error { return nil }
218218

219219
type closeTracker struct {
@@ -227,23 +227,24 @@ func (c *closeTracker) Close() error {
227227
}
228228

229229
func TestEnsureRewindableBody(t *testing.T) {
230-
re := require.New(t)
231-
232230
t.Run("nil body is a no-op", func(t *testing.T) {
231+
re := require.New(t)
233232
r := &http.Request{}
234233
re.NoError(EnsureRewindableBody(r))
235234
re.Nil(r.Body)
236235
re.Nil(r.GetBody)
237236
})
238237

239238
t.Run("http.NoBody is a no-op", func(t *testing.T) {
239+
re := require.New(t)
240240
r := &http.Request{Body: http.NoBody}
241241
re.NoError(EnsureRewindableBody(r))
242242
re.Equal(http.NoBody, r.Body)
243243
re.Nil(r.GetBody)
244244
})
245245

246246
t.Run("existing GetBody is preserved", func(t *testing.T) {
247+
re := require.New(t)
247248
orig := io.NopCloser(bytes.NewBufferString("payload"))
248249
called := false
249250
getBody := func() (io.ReadCloser, error) {
@@ -261,6 +262,7 @@ func TestEnsureRewindableBody(t *testing.T) {
261262
})
262263

263264
t.Run("empty body is restored to NoBody", func(t *testing.T) {
265+
re := require.New(t)
264266
tracker := &closeTracker{Reader: bytes.NewReader(nil)}
265267
r := &http.Request{Body: tracker}
266268
re.NoError(EnsureRewindableBody(r))
@@ -274,6 +276,7 @@ func TestEnsureRewindableBody(t *testing.T) {
274276
})
275277

276278
t.Run("non-empty body becomes rewindable", func(t *testing.T) {
279+
re := require.New(t)
277280
payload := []byte(`{"hello":"world"}`)
278281
tracker := &closeTracker{Reader: bytes.NewReader(payload)}
279282
r := &http.Request{Body: tracker, ContentLength: -1}
@@ -291,7 +294,7 @@ func TestEnsureRewindableBody(t *testing.T) {
291294
// GetBody should be invokable multiple times and each returned
292295
// ReadCloser should independently yield the same payload -- this is
293296
// the actual rewindability guarantee we care about.
294-
for i := 0; i < 3; i++ {
297+
for range 3 {
295298
rc, err := r.GetBody()
296299
re.NoError(err)
297300
got, err := io.ReadAll(rc)
@@ -302,6 +305,7 @@ func TestEnsureRewindableBody(t *testing.T) {
302305
})
303306

304307
t.Run("read error is propagated", func(t *testing.T) {
308+
re := require.New(t)
305309
wantErr := errors.New("boom")
306310
r := &http.Request{Body: &errReader{err: wantErr}}
307311
err := EnsureRewindableBody(r)

0 commit comments

Comments
 (0)