Apply go fix -rangeint ./...

This commit is contained in:
Michael Eischer
2026-07-22 22:26:19 +02:00
parent fb36a7f59b
commit 2c169edad4
56 changed files with 91 additions and 91 deletions
+2 -2
View File
@@ -154,7 +154,7 @@ func (f *vssDeleteOriginalFS) Lstat(name string) (*fs.ExtendedFileInfo, error) {
_, _ = f.FS.Lstat(name)
// nuke testdata
var err error
for i := 0; i < 3; i++ {
for range 3 {
// The CI sometimes runs into "The process cannot access the file because it is being used by another process" errors
// thus try a few times to remove the data
err = os.RemoveAll(f.testdata)
@@ -738,7 +738,7 @@ func TestBackupSkipIfUnchanged(t *testing.T) {
testSetupBackupData(t, env)
opts := BackupOptions{SkipIfUnchanged: true}
for i := 0; i < 3; i++ {
for range 3 {
testRunBackup(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, env.gopts)
testListSnapshots(t, env.gopts, 1)
}
+2 -2
View File
@@ -46,7 +46,7 @@ func snapshotsDirExists(t testing.TB, dir string) bool {
// waitForMount blocks (max mountWait * mountSleep) until the subdir
// "snapshots" appears in the dir.
func waitForMount(t testing.TB, dir string) {
for i := 0; i < mountWait; i++ {
for range mountWait {
if snapshotsDirExists(t, dir) {
t.Log("mounted directory is ready")
return
@@ -70,7 +70,7 @@ func testRunMount(t testing.TB, gopts global.Options, dir string, wg *sync.WaitG
func testRunUmount(t testing.TB, dir string) {
var err error
for i := 0; i < mountWait; i++ {
for range mountWait {
if err = systemFuse.Unmount(dir); err == nil {
t.Logf("directory %v umounted", dir)
return
+1 -1
View File
@@ -243,7 +243,7 @@ func TestRestore(t *testing.T) {
testRunInit(t, env.gopts)
for i := 0; i < 10; i++ {
for i := range 10 {
p := filepath.Join(env.testdata, fmt.Sprintf("foo/bar/testfile%v", i))
rtest.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
rtest.OK(t, appendRandomData(p, uint(rand.Intn(2<<21))))
+1 -1
View File
@@ -415,7 +415,7 @@ func statsDebugFileType(ctx context.Context, repo restic.Lister, tpe restic.File
func statsDebugBlobs(ctx context.Context, repo restic.Repository) ([restic.NumBlobTypes]*sizeHistogram, error) {
var hist [restic.NumBlobTypes]*sizeHistogram
for i := 0; i < len(hist); i++ {
for i := range len(hist) {
hist[i] = newSizeHistogram(2 * chunker.MaxSize)
}
+1 -1
View File
@@ -24,7 +24,7 @@ func TestSizeHistogramNew(t *testing.T) {
func TestSizeHistogramAdd(t *testing.T) {
h := newSizeHistogram(42)
for i := uint64(0); i < 45; i++ {
for i := range uint64(45) {
h.Add(i)
}
+1 -1
View File
@@ -215,7 +215,7 @@ func buildTargets(sourceDir, outputDir string, targets map[string][]string) {
var wg errgroup.Group
ch := make(chan Job)
for i := 0; i < workers; i++ {
for range workers {
wg.Go(func() error {
for job := range ch {
start := time.Now()
+2 -2
View File
@@ -477,7 +477,7 @@ func TestArchiverSaveFileIncremental(t *testing.T) {
data := rtest.Random(23, 512*1024+887898)
testfile := filepath.Join(tempdir, "testfile")
for i := 0; i < 3; i++ {
for i := range 3 {
appendToFile(t, testfile, data)
node, _ := saveFile(t, repo, testfile, fs.Track{FS: fs.NewLocal()})
@@ -984,7 +984,7 @@ func TestArchiverSaveDirIncremental(t *testing.T) {
// save the empty directory several times in a row, then have a look if the
// archiver did save the same tree several times
for i := 0; i < 5; i++ {
for i := range 5 {
testFS := fs.Track{FS: fs.NewLocal()}
arch := New(repo, testFS, Options{})
arch.summary = &Summary{}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
func TestBufferPoolReuse(t *testing.T) {
success := false
// retries to avoid flakiness. The test can fail depending on the GC.
for i := 0; i < 100; i++ {
for range 100 {
// Test that buffers are actually reused from the pool
pool := newBufferPool(1024)
@@ -33,7 +33,7 @@ func TestBufferPoolReuse(t *testing.T) {
func TestBufferPoolLargeBuffers(t *testing.T) {
success := false
// retries to avoid flakiness. The test can fail depending on the GC.
for i := 0; i < 100; i++ {
for range 100 {
// Test that buffers larger than defaultSize are not returned to pool
pool := newBufferPool(1024)
buf := pool.Get()
+1 -1
View File
@@ -45,7 +45,7 @@ func newFileSaver(ctx context.Context, wg *errgroup.Group, uploader restic.BlobS
CompleteBlob: func(uint64) {},
}
for i := uint(0); i < fileWorkers; i++ {
for range fileWorkers {
wg.Go(func() error {
s.worker(ctx, ch)
return nil
+1 -1
View File
@@ -18,7 +18,7 @@ import (
func createTestFiles(t testing.TB, num int) (files []string) {
tempdir := test.TempDir(t)
for i := 0; i < num; i++ {
for i := range num {
filename := fmt.Sprintf("testfile-%d", i)
err := os.WriteFile(filepath.Join(tempdir, filename), []byte(filename), 0600)
if err != nil {
+1 -1
View File
@@ -29,7 +29,7 @@ func newTreeSaver(ctx context.Context, wg *errgroup.Group, treeWorkers uint, upl
errFn: errFn,
}
for i := uint(0); i < treeWorkers; i++ {
for range treeWorkers {
wg.Go(func() error {
return s.worker(ctx, ch)
})
+1 -1
View File
@@ -54,7 +54,7 @@ func TestTreeSaver(t *testing.T) {
var results []futureNode
for i := 0; i < 20; i++ {
for i := range 20 {
node := &data.Node{
Name: fmt.Sprintf("file-%d", i),
}
+1 -1
View File
@@ -258,7 +258,7 @@ func (be *b2Backend) Stat(ctx context.Context, h backend.Handle) (bi backend.Fil
// Remove removes the blob with the given name and type.
func (be *b2Backend) Remove(ctx context.Context, h backend.Handle) error {
// the retry backend will also repeat the remove method up to 10 times
for i := 0; i < 3; i++ {
for range 3 {
obj := be.bucket.Object(be.Filename(h))
var err error
+1 -1
View File
@@ -238,7 +238,7 @@ func TestErrorBackend(t *testing.T) {
wrappedBE := c.Wrap(errBackend, t.Logf)
var wg sync.WaitGroup
for i := 0; i < 5; i++ {
for range 5 {
wg.Add(1)
go loadTest(&wg, wrappedBE)
}
+1 -1
View File
@@ -24,7 +24,7 @@ func TestNew(t *testing.T) {
stepEnd
)
for step := stepCreate; step < stepEnd; step++ {
for step := range stepEnd {
switch step {
case stepRmTag:
rtest.OK(t, os.Remove(tagFile))
+1 -1
View File
@@ -243,7 +243,7 @@ func TestFileSaveConcurrent(t *testing.T) {
Name: id.String(),
}
for i := 0; i < nproc/2; i++ {
for range nproc / 2 {
g.Go(func() error { return c.save(h, bytes.NewReader(data)) })
// Can't use load because only the main goroutine may call t.Fatal.
+1 -1
View File
@@ -72,7 +72,7 @@ func (l *DefaultLayout) Paths() (dirs []string) {
if !disablePackSubdirs {
// also add subdirs
for i := 0; i < 256; i++ {
for i := range 256 {
subdir := hex.EncodeToString([]byte{byte(i)})
dirs = append(dirs, l.join(l.path, defaultLayoutPaths[backend.PackFile], subdir))
}
+1 -1
View File
@@ -112,7 +112,7 @@ func TestDefaultLayout(t *testing.T) {
filepath.Join(tempdir, "keys"),
}
for i := 0; i < 256; i++ {
for i := range 256 {
want = append(want, filepath.Join(tempdir, "data", fmt.Sprintf("%02x", i)))
}
+1 -1
View File
@@ -32,7 +32,7 @@ func TestRcloneExit(t *testing.T) {
rtest.OK(t, err)
t.Log("killed rclone")
for i := 0; i < 10; i++ {
for range 10 {
_, err = be.Stat(context.TODO(), backend.Handle{
Name: "foo",
Type: backend.PackFile,
+2 -2
View File
@@ -51,7 +51,7 @@ func runMinio(ctx context.Context, t testing.TB, dir, key, secret string) func()
// wait until the TCP port is reachable
var success bool
for i := 0; i < 100; i++ {
for range 100 {
time.Sleep(200 * time.Millisecond)
c, err := net.Dial("tcp", "localhost:9000")
@@ -118,7 +118,7 @@ func newMinioTestSuite(t testing.TB) (*test.Suite[s3.Config], func()) {
},
Factory: location.NewHTTPBackendFactory("s3", s3.ParseConfig, location.NoPassword, func(ctx context.Context, cfg s3.Config, rt http.RoundTripper, errorLog func(string, ...any)) (be backend.Backend, err error) {
for i := 0; i < 50; i++ {
for i := range 50 {
be, err = s3.Create(ctx, cfg, rt, errorLog)
if err != nil {
t.Logf("s3 open: try %d: error %v", i, err)
+1 -1
View File
@@ -115,7 +115,7 @@ func concurrencyTester(t *testing.T, setup func(m *mock.Backend), handler func(b
be := sema.NewBackend(m)
var wg errgroup.Group
for i := 0; i < workerCount; i++ {
for range workerCount {
wg.Go(handler(be))
}
+3 -3
View File
@@ -277,7 +277,7 @@ func (s *Suite[C]) TestList(t *testing.T) {
var m sync.Mutex
wg, ctx := errgroup.WithContext(context.TODO())
for i := 0; i < numTestFiles; i++ {
for range numTestFiles {
data := test.Random(random.Int(), random.Intn(100)+55)
wg.Go(func() error {
id := restic.Hash(data)
@@ -354,7 +354,7 @@ func (s *Suite[C]) TestListCancel(t *testing.T) {
testFiles := make([]backend.Handle, 0, numTestFiles)
for i := 0; i < numTestFiles; i++ {
for i := range numTestFiles {
data := fmt.Appendf(nil, "random test blob %v", i)
id := restic.Hash(data)
h := backend.Handle{Type: backend.PackFile, Name: id.String()}
@@ -768,7 +768,7 @@ func (s *Suite[C]) delayedRemove(t testing.TB, be backend.Backend, handles ...ba
func delayedList(t testing.TB, b backend.Backend, tpe backend.FileType, max int, maxwait time.Duration) restic.IDs {
list := restic.NewIDSet()
start := time.Now()
for i := 0; i < max; i++ {
for range max {
err := b.List(context.TODO(), tpe, func(fi backend.FileInfo) error {
id := restic.TestParseID(fi.Name)
list.Insert(id)
+1 -1
View File
@@ -94,7 +94,7 @@ func TestCacheGetOrCompute(t *testing.T) {
calls := make(chan struct{}, 10)
// start a bunch of blocking goroutines
for i := 0; i < 10; i++ {
for range 10 {
wg.Go(func() error {
buf, err := c.GetOrCompute(id2, func() ([]byte, error) {
// block to ensure that multiple requests are waiting in parallel
+1 -1
View File
@@ -609,7 +609,7 @@ func benchmarkSnapshotScaling(t *testing.B, newSnapshots int) {
treeID := sn2.Tree
for i := 0; i < newSnapshots; i++ {
for i := range newSnapshots {
sn, err := data.NewSnapshot([]string{"test" + strconv.Itoa(i)}, nil, "", time.Now())
if err != nil {
t.Fatal(err)
+2 -2
View File
@@ -88,7 +88,7 @@ func TestFindUsedBlobs(t *testing.T) {
repo := repository.TestRepository(t)
var snapshots []*data.Snapshot
for i := 0; i < findTestSnapshots; i++ {
for i := range findTestSnapshots {
sn := data.TestCreateSnapshot(t, repo, findTestTime.Add(time.Duration(i)*time.Second), findTestDepth)
t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str())
snapshots = append(snapshots, sn)
@@ -131,7 +131,7 @@ func TestMultiFindUsedBlobs(t *testing.T) {
repo := repository.TestRepository(t)
var snapshotTrees restic.IDs
for i := 0; i < findTestSnapshots; i++ {
for i := range findTestSnapshots {
sn := data.TestCreateSnapshot(t, repo, findTestTime.Add(time.Duration(i)*time.Second), findTestDepth)
t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str())
snapshotTrees = append(snapshotTrees, *sn.Tree)
+1 -1
View File
@@ -75,7 +75,7 @@ func (fs *fakeFileSystem) saveTree(ctx context.Context, uploader restic.BlobSave
numNodes := int(rnd.Int63() % maxNodes)
var nodes []*Node
for i := 0; i < numNodes; i++ {
for i := range numNodes {
// randomly select the type of the node, either tree (p = 1/4) or file (p = 3/4).
if depth > 1 && rnd.Int63()%4 == 0 {
treeSeed := rnd.Int63() % maxSeed
+1 -1
View File
@@ -20,7 +20,7 @@ const (
func TestCreateSnapshot(t *testing.T) {
repo := repository.TestRepository(t)
for i := 0; i < testCreateSnapshots; i++ {
for i := range testCreateSnapshots {
data.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth)
}
+1 -1
View File
@@ -201,7 +201,7 @@ func StreamTrees(
// decoding a tree can take quite some time such that this can be both CPU- or IO-bound
// one extra worker to handle huge tree blobs
workerCount := int(repo.Connections()) + runtime.GOMAXPROCS(0) + 1
for i := 0; i < workerCount; i++ {
for i := range workerCount {
workerLoaderChan := loaderChan
if i == 0 {
workerLoaderChan = hugeTreeChan
+1 -1
View File
@@ -198,7 +198,7 @@ func TestNodeRestoreAt(t *testing.T) {
// Update the tests to use UPPER case xattr names for windows.
extAttrArr := test.ExtendedAttributes
// Iterate through the array using pointers
for i := 0; i < len(extAttrArr); i++ {
for i := range extAttrArr {
extAttrArr[i].Name = strings.ToUpper(extAttrArr[i].Name)
}
}
+1 -1
View File
@@ -134,7 +134,7 @@ func TestFuseFile(t *testing.T) {
rtest.Equals(t, node.Size, attr.Size)
rtest.Equals(t, (node.Size/uint64(attr.BlockSize))+1, attr.Blocks)
for i := 0; i < 200; i++ {
for i := range 200 {
offset := rand.Intn(int(filesize))
length := rand.Intn(int(filesize)-offset) + 100
+1 -1
View File
@@ -291,7 +291,7 @@ func (c *Checker) ReadPacks(ctx context.Context, filter func(packs map[restic.ID
// as packs are streamed the concurrency is limited by IO
workerCount := int(c.repo.Connections())
// run workers
for i := 0; i < workerCount; i++ {
for range workerCount {
g.Go(func() error {
bufRd := bufio.NewReaderSize(nil, maxStreamBufferSize)
dec, err := zstd.NewReader(nil)
+3 -3
View File
@@ -145,7 +145,7 @@ func (m *MACKey) UnmarshalJSON(data []byte) error {
// Valid tests whether the key k is valid (i.e. not zero).
func (m *MACKey) Valid() bool {
nonzeroK := false
for i := 0; i < len(m.K); i++ {
for i := range len(m.K) {
if m.K[i] != 0 {
nonzeroK = true
}
@@ -155,7 +155,7 @@ func (m *MACKey) Valid() bool {
return false
}
for i := 0; i < len(m.R); i++ {
for i := range len(m.R) {
if m.R[i] != 0 {
return true
}
@@ -183,7 +183,7 @@ func (k *EncryptionKey) UnmarshalJSON(data []byte) error {
// Valid tests whether the key k is valid (i.e. not zero).
func (k *EncryptionKey) Valid() bool {
for i := 0; i < len(k); i++ {
for i := range len(k) {
if k[i] != 0 {
return true
}
@@ -171,7 +171,7 @@ func TestNonceValid(t *testing.T) {
t.Error("null nonce detected as valid")
}
for i := 0; i < 100; i++ {
for range 100 {
nonce = NewRandomNonce()
if !validNonce(nonce) {
t.Errorf("random nonce not detected as valid: %02x", nonce)
+12 -12
View File
@@ -20,12 +20,12 @@ func TestIndexSerialize(t *testing.T) {
idx := index.NewIndex()
// create 50 packs with 20 blobs each
for i := 0; i < 50; i++ {
for i := range 50 {
packID := restic.NewRandomID()
var blobs pack.Blobs
pos := uint(0)
for j := 0; j < 20; j++ {
for j := range 20 {
length := uint(i*100 + j)
uncompressedLength := uint(0)
if i >= 25 {
@@ -84,12 +84,12 @@ func TestIndexSerialize(t *testing.T) {
// add more blobs to idx
newtests := []*pack.PackedBlob{}
for i := 0; i < 10; i++ {
for i := range 10 {
packID := restic.NewRandomID()
var blobs pack.Blobs
pos := uint(0)
for j := 0; j < 10; j++ {
for j := range 10 {
length := uint(i*100 + j)
pb := &pack.PackedBlob{
Pack: packID,
@@ -144,12 +144,12 @@ func TestIndexSize(t *testing.T) {
packs := 200
blobCount := 100
for i := 0; i < packs; i++ {
for i := range packs {
packID := restic.NewRandomID()
var blobs pack.Blobs
pos := uint(0)
for j := 0; j < blobCount; j++ {
for j := range blobCount {
length := uint(i*100 + j)
blobs = append(blobs, pack.Blob{
BlobHandle: restic.NewRandomBlobHandle(),
@@ -400,7 +400,7 @@ func TestIndexPacks(t *testing.T) {
idx := index.NewIndex()
packs := restic.NewIDSet()
for i := 0; i < 20; i++ {
for range 20 {
packID := restic.NewRandomID()
idx.StorePack(packID, pack.Blobs{
{
@@ -432,7 +432,7 @@ func createRandomIndex(rng *rand.Rand, packfiles int) (idx *index.Index, lookupB
idx.Preallocate(restic.DataBlob, packfiles*9)
// create index with given number of pack files
for i := 0; i < packfiles; i++ {
for i := range packfiles {
packID := NewRandomTestID(rng)
var blobs pack.Blobs
offset := 0
@@ -523,12 +523,12 @@ func TestIndexHas(t *testing.T) {
idx := index.NewIndex()
// create 50 packs with 20 blobs each
for i := 0; i < 50; i++ {
for i := range 50 {
packID := restic.NewRandomID()
var blobs pack.Blobs
pos := uint(0)
for j := 0; j < 20; j++ {
for j := range 20 {
length := uint(i*100 + j)
uncompressedLength := uint(0)
if i >= 25 {
@@ -564,7 +564,7 @@ func TestMixedEachByPack(t *testing.T) {
expected := make(map[restic.ID]int)
// create 50 packs with 2 blobs each
for i := 0; i < 50; i++ {
for range 50 {
packID := restic.NewRandomID()
expected[packID] = 1
blobs := pack.Blobs{
@@ -602,7 +602,7 @@ func TestEachByPackIgnoes(t *testing.T) {
ignores := restic.NewIDSet()
expected := make(map[restic.ID]int)
// create 50 packs with one blob each
for i := 0; i < 50; i++ {
for i := range 50 {
packID := restic.NewRandomID()
if i < 3 {
ignores.Insert(packID)
+5 -5
View File
@@ -42,7 +42,7 @@ func TestIndexMapForeach(t *testing.T) {
// empty iteration
}
for i := 0; i < N; i++ {
for i := range N {
var id restic.ID
id[0] = byte(i)
m.add(id, uint32(i), uint32(i), uint32(i), uint32(i/2))
@@ -90,11 +90,11 @@ func TestIndexMapForeachWithID(t *testing.T) {
rtest.Equals(t, 0, n)
// Test insertion and retrieval of duplicates.
for i := 0; i < ndups; i++ {
for i := range ndups {
m.add(id, uint32(i), 0, 0, 0)
}
for i := 0; i < 100; i++ {
for range 100 {
var otherid restic.ID
r.Read(otherid[:])
m.add(otherid, math.MaxUint32, 0, 0, 0)
@@ -116,13 +116,13 @@ func TestIndexMapForeachWithID(t *testing.T) {
func TestHashedArrayTree(t *testing.T) {
hat := newHAT()
const testSize = 1024
for i := uint(0); i < testSize; i++ {
for i := range uint(testSize) {
rtest.Assert(t, hat.Size() == i, "expected hat size %v got %v", i, hat.Size())
e, idx := hat.Alloc()
rtest.Assert(t, idx == i, "expected entry at idx %v got %v", i, idx)
e.length = uint32(i)
}
for i := uint(0); i < testSize; i++ {
for i := range uint(testSize) {
e := hat.Ref(i)
rtest.Assert(t, e.length == uint32(i), "expected entry to contain %v got %v", uint32(i), e.length)
}
+2 -2
View File
@@ -452,7 +452,7 @@ func (mi *MasterIndex) Rewrite(ctx context.Context, repo restic.Unpacked[restic.
// the index files are probably already cached at this point
loaderCount := runtime.GOMAXPROCS(0)
// run workers on ch
for i := 0; i < loaderCount; i++ {
for range loaderCount {
rewriteWg.Add(1)
wg.Go(loader)
}
@@ -668,7 +668,7 @@ func (mi *MasterIndex) ListPacks(ctx context.Context, packs restic.IDSet) <-chan
go func() {
defer close(out)
// only resort a part of the index to keep the memory overhead bounded
for i := byte(0); i < 16; i++ {
for i := range byte(16) {
packBlob := make(map[restic.ID]pack.Blobs)
for pack := range packs {
if pack[0]&0xf == i {
@@ -416,7 +416,7 @@ var (
func createFilledRepo(t testing.TB, snapshots int, version uint) (*repository.Repository, restic.Unpacked[restic.FileType]) {
repo, unpacked, _ := repository.TestRepositoryWithVersion(t, version)
for i := 0; i < snapshots; i++ {
for i := range snapshots {
data.TestCreateSnapshot(t, repo, snapshotTime.Add(time.Duration(i)*time.Second), depth)
}
return repo, unpacked
@@ -595,11 +595,11 @@ func TestRewriteOversizedIndex(t *testing.T) {
// build oversized index
idx := index.NewIndex()
numPacks := 5
for p := 0; p < numPacks; p++ {
for range numPacks {
packID := restic.NewRandomID()
packBlobs := make(pack.Blobs, 0, fullIndexCount)
for i := 0; i < fullIndexCount; i++ {
for i := range fullIndexCount {
blob := pack.Blob{
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
+1 -1
View File
@@ -164,7 +164,7 @@ func (l *lockHandle) checkForOtherLocks(ctx context.Context) error {
}
delay := initialWaitBetweenLockRetries
// retry locking a few times
for i := 0; i < 4; i++ {
for i := range 4 {
if i != 0 {
// sleep between retries to give backend some time to settle
if err := cancelableDelay(ctx, delay); err != nil {
+1 -1
View File
@@ -143,7 +143,7 @@ func verifyHeader(k *crypto.Key, header []byte, expected []Blob) error {
if len(decoded) != len(expected) {
return fmt.Errorf("pack header size mismatch")
}
for i := 0; i < len(decoded); i++ {
for i := range decoded {
if decoded[i] != expected[i] {
return fmt.Errorf("pack header entry mismatch got %v instead of %v", decoded[i], expected[i])
}
@@ -169,8 +169,8 @@ func TestReadRecords(t *testing.T) {
testReadRecords(dataSize+3, 1, 1)
testReadRecords(dataSize+4, 1, 1)
for i := 0; i < 2; i++ {
for j := 0; j < 2; j++ {
for i := range 2 {
for j := range 2 {
testReadRecords(dataSize, i, j)
}
}
+1 -1
View File
@@ -24,7 +24,7 @@ func randomID(rd io.Reader) restic.ID {
const maxBlobSize = 1 << 20
func fillPacks(t testing.TB, rnd *rand.Rand, pm *packerManager, buf []byte) (bytes int) {
for i := 0; i < 102; i++ {
for range 102 {
l := rnd.Intn(maxBlobSize)
id := randomID(rnd)
buf = buf[:l]
+1 -1
View File
@@ -33,7 +33,7 @@ func TestPruneMaxUnusedDuplicate(t *testing.T) {
const blobSize = 1024 * 1024
bufs := [][]byte{}
for i := 0; i < 4; i++ {
for range 4 {
// use uniform length for simpler control via MaxUnusedBytes
buf := make([]byte, blobSize)
random.Read(buf)
+1 -1
View File
@@ -134,7 +134,7 @@ func TestPruneSmall(t *testing.T) {
keep := restic.NewBlobSet()
rtest.OK(t, repo.WithBlobUploader(context.TODO(), func(ctx context.Context, uploader restic.BlobSaverWithAsync) error {
// we need a minimum of 11 packfiles, each packfile will be about 5 Mb long
for i := 0; i < numBlobsCreated; i++ {
for range numBlobsCreated {
buf := make([]byte, blobSize)
random.Read(buf)
+1 -1
View File
@@ -24,7 +24,7 @@ func TestLoadRaw(t *testing.T) {
repo, err := repository.New(b, repository.Options{})
rtest.OK(t, err)
for i := 0; i < 5; i++ {
for i := range 5 {
data := rtest.Random(23+i, 500*KiB)
id := restic.Hash(data)
+2 -2
View File
@@ -806,7 +806,7 @@ func (r *Repository) createIndexFromPacks(ctx context.Context, packsize map[rest
// decoding the pack header is usually quite fast, thus we are primarily IO-bound
workerCount := int(r.Connections())
// run workers on ch
for i := 0; i < workerCount; i++ {
for range workerCount {
wg.Go(worker)
}
@@ -1110,7 +1110,7 @@ func streamPack(ctx context.Context, beLoad backendLoadFn, loadBlobFn loadBlobFn
lastPos := blobs[0].Offset
const maxChunkSize = 2 * DefaultPackSize
for i := 0; i < len(blobs); i++ {
for i := range blobs {
if blobs[i].Offset < lastPos {
// don't wait for streamPackPart to fail
return errors.Errorf("overlapping blobs in pack %v", packID)
@@ -34,7 +34,7 @@ func TestSortCachedPacksFirst(t *testing.T) {
r = rand.New(rand.NewSource(1261))
)
for i := 0; i < len(blobs); i++ {
for i := range len(blobs) {
var id restic.ID
r.Read(id[:])
blobs[i] = &pack.PackedBlob{Pack: id, Blob: pack.Blob{}}
@@ -65,7 +65,7 @@ func BenchmarkSortCachedPacksFirst(b *testing.B) {
r = rand.New(rand.NewSource(1261))
)
for i := 0; i < nblobs; i++ {
for i := range nblobs {
var id restic.ID
r.Read(id[:])
blobs[i] = &pack.PackedBlob{Pack: id, Blob: pack.Blob{}}
@@ -96,7 +96,7 @@ func benchmarkLoadIndex(b *testing.B, version uint) {
repo, _, be := TestRepositoryWithVersion(b, version)
idx := index.NewIndex()
for i := 0; i < 5000; i++ {
for range 5000 {
idx.StorePack(restic.NewRandomID(), pack.Blobs{
{
BlobHandle: restic.NewRandomBlobHandle(),
+3 -3
View File
@@ -391,7 +391,7 @@ func TestRepositoryLoadUnpackedRetryBroken(t *testing.T) {
func saveRandomDataBlobs(t testing.TB, repo restic.Repository, num int, sizeMax int) {
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
rtest.OK(t, repo.WithBlobUploader(context.TODO(), func(ctx context.Context, uploader restic.BlobSaverWithAsync) error {
for i := 0; i < num; i++ {
for range num {
size := rnd.Int() % sizeMax
buf := make([]byte, size)
@@ -413,7 +413,7 @@ func testRepositoryIncrementalIndex(t *testing.T, version uint) {
repo, _, _ := repository.TestRepositoryWithVersion(t, version)
// add a few rounds of packs
for j := 0; j < 5; j++ {
for range 5 {
// add some packs and write index
saveRandomDataBlobs(t, repo, 20, 1<<15)
}
@@ -532,7 +532,7 @@ func TestSaveBlobAsync(t *testing.T) {
err := repo.WithBlobUploader(ctx, func(ctx context.Context, uploader restic.BlobSaverWithAsync) error {
var wg sync.WaitGroup
wg.Add(numCalls)
for i := 0; i < numCalls; i++ {
for i := range numCalls {
// Use unique data for each call
testData := fmt.Appendf(nil, "test blob data %d", i)
uploader.SaveBlobAsync(ctx, restic.DataBlob, testData, restic.ID{}, false,
+1 -1
View File
@@ -21,7 +21,7 @@ func TestBlobSetString(t *testing.T) {
rtest.Equals(t, "{<tree/11111111>}", s.String())
var h BlobHandle
for i := 0; i < 100; i++ {
for range 100 {
h.Type = DataBlob
_, _ = random.Read(h.ID[:])
s.Insert(h)
+1 -1
View File
@@ -44,7 +44,7 @@ func ParallelList(ctx context.Context, r Lister, t FileType, parallelism uint, f
}
// run workers on ch
for i := uint(0); i < parallelism; i++ {
for range parallelism {
wg.Go(worker)
}
+1 -1
View File
@@ -18,7 +18,7 @@ func TestZeroPrefixLen(t *testing.T) {
test.Equals(t, i, skipped)
}
// test buffers of various sizes
for i := 0; i < len(buf); i++ {
for i := range len(buf) {
skipped := restic.ZeroPrefixLen(buf[i:])
test.Equals(t, 0, skipped)
}
+1 -1
View File
@@ -328,7 +328,7 @@ func TestFileRestorerFrequentBlob(t *testing.T) {
blobs := []TestBlob{
{"data1-1", "pack1-1"},
}
for i := 0; i < 10000; i++ {
for range 10000 {
blobs = append(blobs, TestBlob{"a", "pack1-1"})
}
blobs = append(blobs, TestBlob{"end", "pack1-1"})
+1 -1
View File
@@ -41,7 +41,7 @@ func newFilesWriter(count int, allowRecursiveDelete bool) *filesWriter {
// use a large number of buckets to minimize bucket contention
// creating a new file can be slow, so make sure that files typically end up in different buckets.
buckets := make([]filesWriterBucket, 1024)
for b := 0; b < len(buckets); b++ {
for b := range buckets {
buckets[b].files = make(map[string]*partialFile)
}
+1 -1
View File
@@ -660,7 +660,7 @@ func (res *Restorer) VerifyFiles(ctx context.Context, dst string, countRestoredF
return err
})
for i := 0; i < nVerifyWorkers; i++ {
for range nVerifyWorkers {
g.Go(func() (err error) {
var buf []byte
for job := range work {
+2 -2
View File
@@ -1108,7 +1108,7 @@ func TestRestorerOverwriteBehavior(t *testing.T) {
func TestRestorerOverwritePartial(t *testing.T) {
parts := make([]string, 100)
size := 0
for i := 0; i < len(parts); i++ {
for i := range parts {
parts[i] = fmt.Sprint(i)
size += len(parts[i])
if i < 8 {
@@ -1503,7 +1503,7 @@ func TestRestorerLongPath(t *testing.T) {
tmp := t.TempDir()
longPath := tmp
for i := 0; i < 20; i++ {
for range 20 {
longPath = filepath.Join(longPath, "aaaaaaaaaaaaaaaaaaaa")
}
+1 -1
View File
@@ -30,7 +30,7 @@ func TestExtractToFileZip(t *testing.T) {
rtest.OK(t, zw.Close())
// run twice to test creating a new file and overwriting
for i := 0; i < 2; i++ {
for range 2 {
outfn := filepath.Join(dir, ext+"-out")
rtest.OK(t, extractToFile(archive.Bytes(), "src."+ext, outfn, printf))
+1 -1
View File
@@ -40,7 +40,7 @@ func TestCounter(t *testing.T) {
done := make(chan struct{})
go func() {
defer close(done)
for i := 0; i < N; i++ {
for range N {
time.Sleep(time.Millisecond)
c.Add(1)
}