Skip to content

Commit

Permalink
testsuite: fix defer in loop
Browse files Browse the repository at this point in the history
Defers in a bounded number of iterations is harmless, however,
static-analysis can have a hard time understanding when something is
bounded.

Change-Id: I0a415d55893d7000484b5c92d86c7a29b3ba7511
  • Loading branch information
egonelbre committed Jul 20, 2023
1 parent 97b4f29 commit 358f7f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions testsuite/buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"golang.org/x/exp/maps"

"storj.io/common/testcontext"
"storj.io/storj/private/testplanet"
Expand Down Expand Up @@ -75,13 +76,15 @@ func TestListBuckets_TwoBuckets(t *testing.T) {
}

for bucket := range expectedBuckets {
bucket := bucket
createBucket(t, ctx, project, bucket)
defer func() {
}
bucketsToDelete := maps.Keys(expectedBuckets)
defer func() {
for _, bucket := range bucketsToDelete {
_, err := project.DeleteBucket(ctx, bucket)
require.NoError(t, err)
}()
}
}
}()

list := listBuckets(ctx, t, project, nil)

Expand Down Expand Up @@ -178,12 +181,14 @@ func TestListBuckets_AutoPaging(t *testing.T) {
bucketName := fmt.Sprintf("bucket%d", i)
expectedBuckets[bucketName] = true
createBucket(t, ctx, project, bucketName)

defer func() {
}
bucketsToDelete := maps.Keys(expectedBuckets)
defer func() {
for _, bucketName := range bucketsToDelete {
_, err := project.DeleteBucket(ctx, bucketName)
require.NoError(t, err)
}()
}
}
}()

list := listBuckets(ctx, t, project, nil)

Expand Down
2 changes: 1 addition & 1 deletion testsuite/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3
github.com/zeebo/errs v1.3.0
go.uber.org/zap v1.16.0
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db
storj.io/common v0.0.0-20230602145716-d6ea82d58b3d
storj.io/drpc v0.0.33
storj.io/storj v0.12.1-0.20230502161034-25f2305e0078
Expand Down Expand Up @@ -85,7 +86,6 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
Expand Down

0 comments on commit 358f7f9

Please sign in to comment.