build: modernize with "go fix -rangeint": use range over int

This commit is contained in:
Nick Craig-Wood
2026-08-21 12:23:31 +01:00
parent 67728ce37d
commit a64c0a0fde
8 changed files with 22 additions and 22 deletions
+1 -1
View File
@@ -157,7 +157,7 @@ func parseArrowStream(body io.Reader) ([]*container.BlobItem, *string, error) {
rec := reader.RecordBatch() rec := reader.RecordBatch()
rows := int(rec.NumRows()) rows := int(rec.NumRows())
for row := 0; row < rows; row++ { for row := range rows {
item := &container.BlobItem{ item := &container.BlobItem{
Properties: &container.BlobProperties{}, Properties: &container.BlobProperties{},
} }
+1 -1
View File
@@ -198,7 +198,7 @@ func TestHandleFlatListResponse_MultiRecordBatch(t *testing.T) {
// First batch: 2 rows // First batch: 2 rows
builder := arrowArray.NewRecordBuilder(alloc, schema) builder := arrowArray.NewRecordBuilder(alloc, schema)
for i := 0; i < 2; i++ { for range 2 {
builder.Field(0).(*arrowArray.StringBuilder).Append("batch1_blob") builder.Field(0).(*arrowArray.StringBuilder).Append("batch1_blob")
for j := 1; j < 11; j++ { for j := 1; j < 11; j++ {
builder.Field(j).AppendNull() builder.Field(j).AppendNull()
+1 -1
View File
@@ -2031,7 +2031,7 @@ func (album *Album) fetchPhotosParallel(ctx context.Context, totalPhotos int64)
sem := make(chan struct{}, workers) sem := make(chan struct{}, workers)
var wg sync.WaitGroup var wg sync.WaitGroup
for i := 0; i < numPartitions; i++ { for i := range numPartitions {
wg.Add(1) wg.Add(1)
go func(idx int) { go func(idx int) {
defer wg.Done() defer wg.Done()
+2 -2
View File
@@ -1191,7 +1191,7 @@ func TestFlushCaches_NoPendingDeltaRace(t *testing.T) {
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
defer close(done) defer close(done)
for i := 0; i < 100; i++ { for range 100 {
lib.deltaMu.Lock() lib.deltaMu.Lock()
lib.pendingDelta = &deltaPayload{ lib.pendingDelta = &deltaPayload{
records: []json.RawMessage{json.RawMessage(`{"recordName":"m1","recordType":"CPLMaster"}`)}, records: []json.RawMessage{json.RawMessage(`{"recordName":"m1","recordType":"CPLMaster"}`)},
@@ -1201,7 +1201,7 @@ func TestFlushCaches_NoPendingDeltaRace(t *testing.T) {
lib.applyPendingDelta(context.Background()) lib.applyPendingDelta(context.Background())
} }
}() }()
for i := 0; i < 100; i++ { for range 100 {
ps.FlushCaches() ps.FlushCaches()
// Re-add the library since FlushCaches clears it // Re-add the library since FlushCaches clears it
ps.mu.Lock() ps.mu.Lock()
+4 -4
View File
@@ -428,7 +428,7 @@ func TestHostKeyCallbackRefusesAtCap(t *testing.T) {
opt: Options{PinHostKey: true}, opt: Options{PinHostKey: true},
hostKeys: map[string][][]byte{}, hostKeys: map[string][][]byte{},
} }
for i := 0; i < maxHostKeys; i++ { for i := range maxHostKeys {
algo := fmt.Sprintf("test-algo-%d", i) algo := fmt.Sprintf("test-algo-%d", i)
f.hostKeys[algo] = [][]byte{{byte(i)}} f.hostKeys[algo] = [][]byte{{byte(i)}}
} }
@@ -480,7 +480,7 @@ func TestHostKeyCallbackPinHostKeyRace(t *testing.T) {
const N = 16 const N = 16
pendings := make([]*pendingKey, N) pendings := make([]*pendingKey, N)
wg.Add(N) wg.Add(N)
for i := 0; i < N; i++ { for i := range N {
go func(i int) { go func(i int) {
defer wg.Done() defer wg.Done()
cb := f.hostKeyCallback(&pendings[i]) cb := f.hostKeyCallback(&pendings[i])
@@ -489,7 +489,7 @@ func TestHostKeyCallbackPinHostKeyRace(t *testing.T) {
}(i) }(i)
} }
wg.Wait() wg.Wait()
for i := 0; i < N; i++ { for i := range N {
require.NotNil(t, pendings[i], "dial %d should have stashed its own key", i) require.NotNil(t, pendings[i], "dial %d should have stashed its own key", i)
assert.Equal(t, keyBytes, pendings[i].marshalled) assert.Equal(t, keyBytes, pendings[i].marshalled)
} }
@@ -631,7 +631,7 @@ func TestCommitHostKeyConcurrent(t *testing.T) {
keys := makeTestKeys(t, N) keys := makeTestKeys(t, N)
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(N) wg.Add(N)
for i := 0; i < N; i++ { for i := range N {
go func(i int) { go func(i int) {
defer wg.Done() defer wg.Done()
f.commitHostKey(&pendingKey{ f.commitHostKey(&pendingKey{
+4 -4
View File
@@ -103,7 +103,7 @@ func TestFolderWindowLimiterShape(t *testing.T) {
} }
// Window 1: the first burst grants pass immediately... // Window 1: the first burst grants pass immediately...
for i := 0; i < defaultListFolderBurst; i++ { for i := range defaultListFolderBurst {
assert.Equal(t, base, reserve(base), "burst grant %d passes immediately", i+1) assert.Equal(t, base, reserve(base), "burst grant %d passes immediately", i+1)
} }
// ...then the paced phase spends the rest of the budget one interval apart // ...then the paced phase spends the rest of the budget one interval apart
@@ -149,14 +149,14 @@ func TestFolderWindowLimiterIdleResume(t *testing.T) {
var grants []time.Time var grants []time.Time
g := base g := base
// Spend window 1's full budget greedily. // Spend window 1's full budget greedily.
for i := 0; i < defaultListFolderLimit; i++ { for range defaultListFolderLimit {
g = lim.reserve(g) g = lim.reserve(g)
grants = append(grants, g) grants = append(grants, g)
} }
// Resume mid-window-2 after an idle gap and hammer across the 2->3 // Resume mid-window-2 after an idle gap and hammer across the 2->3
// boundary: a fresh burst fires on resume and again at the boundary. // boundary: a fresh burst fires on resume and again at the boundary.
g = base.Add(window + window/2) g = base.Add(window + window/2)
for i := 0; i < defaultListFolderLimit; i++ { for range defaultListFolderLimit {
g = lim.reserve(g) g = lim.reserve(g)
grants = append(grants, g) grants = append(grants, g)
} }
@@ -187,7 +187,7 @@ func TestFolderWindowLimiterClamps(t *testing.T) {
// burst >= limit clamps to limit-1, leaving one paced token per window. // burst >= limit clamps to limit-1, leaving one paced token per window.
lim = newFs(5, 99).folderListLimiter("Y") lim = newFs(5, 99).folderListLimiter("Y")
for i := 0; i < 4; i++ { for i := range 4 {
assert.Equal(t, base, lim.reserve(base), "clamped burst grant %d", i+1) assert.Equal(t, base, lim.reserve(base), "clamped burst grant %d", i+1)
} }
assert.Equal(t, base.Add(window), lim.reserve(base), "5th grant rolls into the next window") assert.Equal(t, base.Add(window), lim.reserve(base), "5th grant rolls into the next window")
+8 -8
View File
@@ -287,11 +287,11 @@ func TestOutputHandlerConcurrency(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
// Goroutines calling Handle (text format) // Goroutines calling Handle (text format)
for i := 0; i < goroutines; i++ { for range goroutines {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
r := slog.NewRecord(t0, slog.LevelInfo, "concurrent text", 0) r := slog.NewRecord(t0, slog.LevelInfo, "concurrent text", 0)
r.AddAttrs(slog.String("object", "obj")) r.AddAttrs(slog.String("object", "obj"))
_ = h.Handle(ctx, r) _ = h.Handle(ctx, r)
@@ -300,11 +300,11 @@ func TestOutputHandlerConcurrency(t *testing.T) {
} }
// Goroutines calling setFormat (switching between text and JSON) // Goroutines calling setFormat (switching between text and JSON)
for i := 0; i < 2; i++ { for range 2 {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for j := range iterations {
if j%2 == 0 { if j%2 == 0 {
h.setFormat(logFormatDate | logFormatTime) h.setFormat(logFormatDate | logFormatTime)
} else { } else {
@@ -318,7 +318,7 @@ func TestOutputHandlerConcurrency(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
h.setFormatFlags(logFormatPid | logFormatMicroseconds) h.setFormatFlags(logFormatPid | logFormatMicroseconds)
h.clearFormatFlags(logFormatPid | logFormatMicroseconds) h.clearFormatFlags(logFormatPid | logFormatMicroseconds)
} }
@@ -328,7 +328,7 @@ func TestOutputHandlerConcurrency(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for j := range iterations {
if j%2 == 0 { if j%2 == 0 {
h.SetLevel(slog.LevelDebug) h.SetLevel(slog.LevelDebug)
} else { } else {
@@ -342,7 +342,7 @@ func TestOutputHandlerConcurrency(t *testing.T) {
go func() { go func() {
defer wg.Done() defer wg.Done()
noop := func(_ slog.Level, _ string) {} noop := func(_ slog.Level, _ string) {}
for j := 0; j < iterations; j++ { for range iterations {
h.SetOutput(noop) h.SetOutput(noop)
h.ResetOutput() h.ResetOutput()
} }
@@ -352,7 +352,7 @@ func TestOutputHandlerConcurrency(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
for j := 0; j < iterations; j++ { for range iterations {
_ = h.WithAttrs(nil) _ = h.WithAttrs(nil)
_ = h.WithGroup("g") _ = h.WithGroup("g")
} }
+1 -1
View File
@@ -769,7 +769,7 @@ func TestItemHandleCachingReopenDuringGraceClose(t *testing.T) {
buf := make([]byte, 1) buf := make([]byte, 1)
const iterations = 50 const iterations = 50
for i := 0; i < iterations; i++ { for i := range iterations {
// Open, read (to create a downloader) and close so a grace // Open, read (to create a downloader) and close so a grace
// timer is pending with the fd and downloaders still alive. // timer is pending with the fd and downloaders still alive.
require.NoError(t, item.Open(obj)) require.NoError(t, item.Open(obj))