Skip to content

Commit 1ded655

Browse files
authored
style: run new go fix with modernizers (#2906)
1 parent ad1115b commit 1ded655

File tree

154 files changed

+180
-565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+180
-565
lines changed

.github/workflows/benchmark.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
name: "Main"
33
on: # yamllint disable-line rule:truthy
4+
# NOTE! Do NOT add any other "on", because this workflow has permission to write to the repo!
45
push:
56
branches:
67
- "main"
7-
# NOTE! Do NOT add any other "on", because this workflow has permission to write to the repo!
88

99
permissions:
1010
# permission to update benchmark contents in gh-pages branch

docker-compose.postgres.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ services:
5858
container_name: "migrate"
5959
environment:
6060
- "SPICEDB_DATASTORE_ENGINE=postgres"
61-
# Run migrations on primary
61+
# Run migrations on primary
6262
- "SPICEDB_DATASTORE_CONN_URI=postgres://spicedb:spicedb@postgres-primary:5432/spicedb?sslmode=disable"
6363
command: "datastore migrate head"
6464
networks:

internal/auth/presharedkey_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func TestPresharedKeys(t *testing.T) {
3030
}
3131

3232
for _, testcase := range testcases {
33-
testcase := testcase
3433
t.Run(testcase.name, func(t *testing.T) {
3534
f := MustRequirePresharedKey(testcase.presharedkeys)
3635
ctx := t.Context()
@@ -84,7 +83,6 @@ func TestPresharedKeyEdgeCases(t *testing.T) {
8483
}
8584

8685
for _, testcase := range testcases {
87-
testcase := testcase
8886
t.Run(testcase.name, func(t *testing.T) {
8987
f := MustRequirePresharedKey(testcase.presharedkeys)
9088
ctx := withTokenMetadata("bearer " + testcase.token)

internal/caveats/builder_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func TestShortcircuitedOr(t *testing.T) {
3939
}
4040

4141
for _, tc := range tcs {
42-
tc := tc
4342
t.Run(fmt.Sprintf("%v-%v", tc.first, tc.second), func(t *testing.T) {
4443
testutil.RequireProtoEqual(t, tc.expected, ShortcircuitedOr(tc.first, tc.second), "mismatch")
4544
})
@@ -87,7 +86,6 @@ func TestOr(t *testing.T) {
8786
}
8887

8988
for _, tc := range tcs {
90-
tc := tc
9189
t.Run(fmt.Sprintf("%v-%v", tc.first, tc.second), func(t *testing.T) {
9290
testutil.RequireProtoEqual(t, tc.expected, Or(tc.first, tc.second), "mismatch")
9391
})
@@ -135,7 +133,6 @@ func TestAnd(t *testing.T) {
135133
}
136134

137135
for _, tc := range tcs {
138-
tc := tc
139136
t.Run(fmt.Sprintf("%v-%v", tc.first, tc.second), func(t *testing.T) {
140137
testutil.RequireProtoEqual(t, tc.expected, And(tc.first, tc.second), "mismatch")
141138
})
@@ -165,7 +162,6 @@ func TestInvert(t *testing.T) {
165162
}
166163

167164
for _, tc := range tcs {
168-
tc := tc
169165
t.Run(fmt.Sprintf("%v", tc.first), func(t *testing.T) {
170166
testutil.RequireProtoEqual(t, tc.expected, Invert(tc.first), "mismatch")
171167
})
@@ -199,7 +195,6 @@ func TestCaveatAsExpr(t *testing.T) {
199195
}
200196

201197
for _, tc := range tcs {
202-
tc := tc
203198
t.Run(tc.name, func(t *testing.T) {
204199
testutil.RequireProtoEqual(t, tc.expected, CaveatAsExpr(tc.caveat), "mismatch")
205200
})
@@ -284,7 +279,6 @@ func TestSubtract(t *testing.T) {
284279
}
285280

286281
for _, tc := range tcs {
287-
tc := tc
288282
t.Run(tc.name, func(t *testing.T) {
289283
result := Subtract(tc.caveat, tc.subtracted)
290284
testutil.RequireProtoEqual(t, tc.expected, result, "mismatch")

internal/caveats/run_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ func TestRunCaveatExpressions(t *testing.T) {
447447
}
448448

449449
for _, tc := range tcs {
450-
tc := tc
451450
t.Run(tc.name, func(t *testing.T) {
452451
req := require.New(t)
453452

@@ -476,7 +475,6 @@ func TestRunCaveatExpressions(t *testing.T) {
476475
RunCaveatExpressionNoDebugging,
477476
RunCaveatExpressionWithDebugInformation,
478477
} {
479-
debugOption := debugOption
480478
t.Run(fmt.Sprintf("%v", debugOption), func(t *testing.T) {
481479
req := require.New(t)
482480

internal/cursorediterator/blocks.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ func CursoredParallelIterators[I any](
241241
tr := taskrunner.NewPreloadedTaskRunner(ctx, concurrency, len(itersToRun))
242242
collectors := make([]chan item[I], len(itersToRun))
243243
for i, iter := range itersToRun {
244-
i := i
245-
iter := iter
246244
collector := make(chan item[I], parallelIteratorResultsBufferSize)
247245
collectors[i] = collector
248246

internal/cursorediterator/primitives_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ func TestSpanned(t *testing.T) {
610610
defer cleanup()
611611

612612
source := func(yield func(string, error) bool) {
613-
for i := 0; i < 5; i++ {
613+
for range 5 {
614614
if !yield("item", nil) {
615615
return
616616
}

internal/datasets/basesubjectset.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func (bss BaseSubjectSet[T]) Subtract(toRemove T) {
126126
updatedWildcard, concretesToAdd := subtractWildcardFromWildcard(existing, toRemove, bss.constructor)
127127
bss.wildcard.setOrNil(updatedWildcard)
128128
for _, concrete := range concretesToAdd {
129-
concrete := concrete
130129
bss.setConcrete(concrete.GetSubjectId(), &concrete)
131130
}
132131
return

internal/datasets/subjectset_test.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ func TestSubjectSetAdd(t *testing.T) {
228228
}
229229

230230
for _, tc := range tcs {
231-
tc := tc
232-
233231
t.Run(tc.name, func(t *testing.T) {
234232
existingSet := NewSubjectSet()
235233
for _, existing := range tc.existing {
@@ -597,8 +595,6 @@ func TestSubjectSetSubtract(t *testing.T) {
597595
}
598596

599597
for _, tc := range tcs {
600-
tc := tc
601-
602598
t.Run(tc.name, func(t *testing.T) {
603599
existingSet := NewSubjectSet()
604600
for _, existing := range tc.existing {
@@ -933,8 +929,6 @@ func TestSubjectSetIntersection(t *testing.T) {
933929
}
934930

935931
for _, tc := range tcs {
936-
tc := tc
937-
938932
t.Run(tc.name, func(t *testing.T) {
939933
existingSet := NewSubjectSet()
940934
for _, existing := range tc.existing {
@@ -1308,8 +1302,6 @@ func TestMultipleOperations(t *testing.T) {
13081302
}
13091303

13101304
for _, tc := range tcs {
1311-
tc := tc
1312-
13131305
t.Run(tc.name, func(t *testing.T) {
13141306
set := NewSubjectSet()
13151307
tc.runOps(set)
@@ -1355,8 +1347,6 @@ func TestSubtractAll(t *testing.T) {
13551347
}
13561348

13571349
for _, tc := range tcs {
1358-
tc := tc
1359-
13601350
t.Run(tc.name, func(t *testing.T) {
13611351
set := NewSubjectSet()
13621352

@@ -1464,7 +1454,6 @@ var testSets = [][]*v1.FoundSubject{
14641454

14651455
func TestUnionCommutativity(t *testing.T) {
14661456
for _, pair := range allSubsets(testSets, 2) {
1467-
pair := pair
14681457
t.Run(fmt.Sprintf("%v", pair), func(t *testing.T) {
14691458
left1, left2 := NewSubjectSet(), NewSubjectSet()
14701459
for _, l := range pair[0] {
@@ -1491,7 +1480,6 @@ func TestUnionCommutativity(t *testing.T) {
14911480

14921481
func TestUnionAssociativity(t *testing.T) {
14931482
for _, triple := range allSubsets(testSets, 3) {
1494-
triple := triple
14951483
t.Run(fmt.Sprintf("%s U %s U %s", testutil.FormatSubjects(triple[0]), testutil.FormatSubjects(triple[1]), testutil.FormatSubjects(triple[2])), func(t *testing.T) {
14961484
// A U (B U C) == (A U B) U C
14971485

@@ -1528,7 +1516,6 @@ func TestUnionAssociativity(t *testing.T) {
15281516

15291517
func TestIntersectionCommutativity(t *testing.T) {
15301518
for _, pair := range allSubsets(testSets, 2) {
1531-
pair := pair
15321519
t.Run(fmt.Sprintf("%v", pair), func(t *testing.T) {
15331520
left1, left2 := NewSubjectSet(), NewSubjectSet()
15341521
for _, l := range pair[0] {
@@ -1554,7 +1541,6 @@ func TestIntersectionCommutativity(t *testing.T) {
15541541

15551542
func TestIntersectionAssociativity(t *testing.T) {
15561543
for _, triple := range allSubsets(testSets, 3) {
1557-
triple := triple
15581544
t.Run(fmt.Sprintf("%s ∩ %s ∩ %s", testutil.FormatSubjects(triple[0]), testutil.FormatSubjects(triple[1]), testutil.FormatSubjects(triple[2])), func(t *testing.T) {
15591545
// A ∩ (B ∩ C) == (A ∩ B) ∩ C
15601546

@@ -1591,7 +1577,6 @@ func TestIntersectionAssociativity(t *testing.T) {
15911577

15921578
func TestIdempotentUnion(t *testing.T) {
15931579
for _, set := range testSets {
1594-
set := set
15951580
t.Run(fmt.Sprintf("%v", set), func(t *testing.T) {
15961581
// A U A == A
15971582
A1, A2 := NewSubjectSet(), NewSubjectSet()
@@ -1610,7 +1595,6 @@ func TestIdempotentUnion(t *testing.T) {
16101595

16111596
func TestIdempotentIntersection(t *testing.T) {
16121597
for _, set := range testSets {
1613-
set := set
16141598
t.Run(fmt.Sprintf("%v", set), func(t *testing.T) {
16151599
// A ∩ A == A
16161600
A1, A2 := NewSubjectSet(), NewSubjectSet()
@@ -1725,8 +1709,6 @@ func TestUnionWildcardWithWildcard(t *testing.T) {
17251709
}
17261710

17271711
for _, tc := range tcs {
1728-
tc := tc
1729-
17301712
t.Run(fmt.Sprintf("%s U %s", testutil.FormatSubject(tc.existing), testutil.FormatSubject(tc.toUnion)), func(t *testing.T) {
17311713
existing := wrap(tc.existing)
17321714
produced, err := unionWildcardWithWildcard(existing, tc.toUnion, subjectSetConstructor)
@@ -1845,8 +1827,6 @@ func TestUnionWildcardWithConcrete(t *testing.T) {
18451827
}
18461828

18471829
for _, tc := range tcs {
1848-
tc := tc
1849-
18501830
t.Run(fmt.Sprintf("%s U %s", testutil.FormatSubject(tc.existing), testutil.FormatSubject(tc.toUnion)), func(t *testing.T) {
18511831
existing := wrap(tc.existing)
18521832
produced := unionWildcardWithConcrete(existing, tc.toUnion, subjectSetConstructor)
@@ -1905,8 +1885,6 @@ func TestUnionConcreteWithConcrete(t *testing.T) {
19051885
}
19061886

19071887
for _, tc := range tcs {
1908-
tc := tc
1909-
19101888
t.Run(fmt.Sprintf("%s U %s", testutil.FormatSubject(tc.existing), testutil.FormatSubject(tc.toUnion)), func(t *testing.T) {
19111889
existing := wrap(tc.existing)
19121890
toUnion := wrap(tc.toUnion)
@@ -2048,8 +2026,6 @@ func TestSubtractWildcardFromWildcard(t *testing.T) {
20482026
}
20492027

20502028
for _, tc := range tcs {
2051-
tc := tc
2052-
20532029
t.Run(fmt.Sprintf("%s - %s", testutil.FormatSubject(tc.existing), testutil.FormatSubject(tc.toSubtract)), func(t *testing.T) {
20542030
existing := wrap(tc.existing)
20552031

@@ -2157,8 +2133,6 @@ func TestSubtractWildcardFromConcrete(t *testing.T) {
21572133
}
21582134

21592135
for _, tc := range tcs {
2160-
tc := tc
2161-
21622136
t.Run(fmt.Sprintf("%v - %v", testutil.FormatSubject(tc.existing), testutil.FormatSubject(tc.toSubtract)), func(t *testing.T) {
21632137
produced := subtractWildcardFromConcrete(tc.existing, tc.toSubtract, subjectSetConstructor)
21642138
testutil.RequireExpectedSubject(t, tc.expected, produced)
@@ -2208,8 +2182,6 @@ func TestSubtractConcreteFromConcrete(t *testing.T) {
22082182
}
22092183

22102184
for _, tc := range tcs {
2211-
tc := tc
2212-
22132185
t.Run(fmt.Sprintf("%s - %s", testutil.FormatSubject(tc.existing), testutil.FormatSubject(tc.toSubtract)), func(t *testing.T) {
22142186
produced := subtractConcreteFromConcrete(tc.existing, tc.toSubtract, subjectSetConstructor)
22152187
testutil.RequireExpectedSubject(t, tc.expected, produced)
@@ -2283,8 +2255,6 @@ func TestSubtractConcreteFromWildcard(t *testing.T) {
22832255
}
22842256

22852257
for _, tc := range tcs {
2286-
tc := tc
2287-
22882258
t.Run(fmt.Sprintf("%s - %s", testutil.FormatSubject(tc.existing), testutil.FormatSubject(tc.toSubtract)), func(t *testing.T) {
22892259
produced := subtractConcreteFromWildcard(tc.existing, tc.toSubtract, subjectSetConstructor)
22902260
testutil.RequireExpectedSubject(t, tc.expected, produced)
@@ -2341,8 +2311,6 @@ func TestIntersectConcreteWithConcrete(t *testing.T) {
23412311
}
23422312

23432313
for _, tc := range tcs {
2344-
tc := tc
2345-
23462314
t.Run(fmt.Sprintf("%s ∩ %s", testutil.FormatSubject(tc.first), testutil.FormatSubject(tc.second)), func(t *testing.T) {
23472315
second := wrap(tc.second)
23482316

@@ -2453,8 +2421,6 @@ func TestIntersectWildcardWithWildcard(t *testing.T) {
24532421
}
24542422

24552423
for _, tc := range tcs {
2456-
tc := tc
2457-
24582424
t.Run(fmt.Sprintf("%s ∩ %s", testutil.FormatSubject(tc.first), testutil.FormatSubject(tc.second)), func(t *testing.T) {
24592425
first := wrap(tc.first)
24602426
second := wrap(tc.second)
@@ -2582,8 +2548,6 @@ func TestIntersectConcreteWithWildcard(t *testing.T) {
25822548
}
25832549

25842550
for _, tc := range tcs {
2585-
tc := tc
2586-
25872551
t.Run(fmt.Sprintf("%s ∩ %s", testutil.FormatSubject(tc.concrete), testutil.FormatSubject(tc.wildcard)), func(t *testing.T) {
25882552
wildcard := wrap(tc.wildcard)
25892553

@@ -2601,7 +2565,7 @@ func allSubsets[T any](objs []T, n int) [][]T {
26012565
maxInt := uint64(math.Exp2(float64(len(objs)))) - 1
26022566
all := make([][]T, 0)
26032567

2604-
for i := uint64(0); i < maxInt; i++ {
2568+
for i := range maxInt {
26052569
set := make([]T, 0, n)
26062570
for digit := uint64(0); digit < uint64(len(objs)); digit++ {
26072571
mask := uint64(1) << digit

internal/datastore/benchmark/driver_bench_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ func BenchmarkDatastoreDriver(b *testing.B) {
8080
ds, _ = testfixtures.StandardDatastoreWithSchema(ds, require.New(b))
8181

8282
// Write a fair amount of data, much more than a functional test
83-
for docNum := 0; docNum < numDocuments; docNum++ {
83+
for docNum := range numDocuments {
8484
_, err := ds.ReadWriteTx(ctx, func(ctx context.Context, rwt datastore.ReadWriteTransaction) error {
8585
var updates []tuple.RelationshipUpdate
86-
for userNum := 0; userNum < usersPerDoc; userNum++ {
86+
for userNum := range usersPerDoc {
8787
updates = append(updates, tuple.Create(docViewer(strconv.Itoa(docNum), strconv.Itoa(userNum))))
8888
}
8989

@@ -133,7 +133,6 @@ func BenchmarkDatastoreDriver(b *testing.B) {
133133
})
134134
b.Run("SortedSnapshotReadOnlyNamespace", func(b *testing.B) {
135135
for orderName, order := range sortOrders {
136-
order := order
137136
b.Run(orderName, func(b *testing.B) {
138137
for n := 0; n < b.N; n++ {
139138
iter, err := ds.SnapshotReader(headRev).QueryRelationships(ctx, datastore.RelationshipsFilter{
@@ -151,7 +150,6 @@ func BenchmarkDatastoreDriver(b *testing.B) {
151150
})
152151
b.Run("SortedSnapshotReadWithRelation", func(b *testing.B) {
153152
for orderName, order := range sortOrders {
154-
order := order
155153
b.Run(orderName, func(b *testing.B) {
156154
for n := 0; n < b.N; n++ {
157155
iter, err := ds.SnapshotReader(headRev).QueryRelationships(ctx, datastore.RelationshipsFilter{
@@ -170,7 +168,6 @@ func BenchmarkDatastoreDriver(b *testing.B) {
170168
})
171169
b.Run("SortedSnapshotReadAllResourceFields", func(b *testing.B) {
172170
for orderName, order := range sortOrders {
173-
order := order
174171
b.Run(orderName, func(b *testing.B) {
175172
for n := 0; n < b.N; n++ {
176173
randDocNum := rand.Intn(numDocuments) //nolint:gosec
@@ -207,12 +204,11 @@ func BenchmarkDatastoreDriver(b *testing.B) {
207204
b.Run("CreateAndTouch", func(b *testing.B) {
208205
const totalRelationships = 1000
209206
for _, portionCreate := range []float64{0, 0.10, 0.25, 0.50, 1} {
210-
portionCreate := portionCreate
211207
b.Run(fmt.Sprintf("%v_", portionCreate), func(b *testing.B) {
212208
for n := 0; n < b.N; n++ {
213209
portionCreateIndex := int(math.Floor(portionCreate * totalRelationships))
214210
mutations := make([]tuple.RelationshipUpdate, 0, totalRelationships)
215-
for index := 0; index < totalRelationships; index++ {
211+
for index := range totalRelationships {
216212
if index >= portionCreateIndex {
217213
stableID := fmt.Sprintf("id-%d", index)
218214
rel := docViewer(stableID, stableID)

0 commit comments

Comments
 (0)