Skip to content

Commit a79aceb

Browse files
Lint fixes part 5 (#2628)
Co-authored-by: James Thomas <james9074@gmail.com>
1 parent 4f13789 commit a79aceb

File tree

10 files changed

+105
-49
lines changed

10 files changed

+105
-49
lines changed

e2e/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package e2e
22

33
import (
4-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
54
"google.golang.org/grpc"
5+
6+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
67
)
78

89
// Client holds versioned clients to spicedb that all share the same connection

e2e/newenemy/newenemy_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ import (
1515
"text/template"
1616
"time"
1717

18-
"github.com/authzed/authzed-go/pkg/requestmeta"
19-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
2018
"github.com/jackc/pgx/v5"
2119
"github.com/jackc/pgx/v5/pgtype"
2220
"github.com/stretchr/testify/require"
2321
"google.golang.org/grpc/metadata"
2422

25-
"github.com/authzed/spicedb/internal/datastore/revisions"
26-
"github.com/authzed/spicedb/pkg/zedtoken"
23+
"github.com/authzed/authzed-go/pkg/requestmeta"
24+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
2725

2826
"github.com/authzed/spicedb/e2e"
2927
"github.com/authzed/spicedb/e2e/cockroach"
3028
"github.com/authzed/spicedb/e2e/generator"
3129
"github.com/authzed/spicedb/e2e/spice"
30+
"github.com/authzed/spicedb/internal/datastore/revisions"
31+
"github.com/authzed/spicedb/pkg/zedtoken"
3232
)
3333

3434
type NamespaceNames struct {
@@ -277,7 +277,7 @@ func attemptFnsForProbeFns(vulnerableMax int, vulnerableProbe, protectedProbe pr
277277
return
278278
}
279279
}
280-
return
280+
return vulnerableFn, protectedFn
281281
}
282282

283283
// attemptFn runs a check and returns how many iterations it took to fail
@@ -322,7 +322,7 @@ func iterationsForHighConfidence(samples []int) (iterations int) {
322322
if *maxIterations != 0 && *maxIterations < iterations {
323323
iterations = *maxIterations
324324
}
325-
return
325+
return iterations
326326
}
327327

328328
var goodNs *NamespaceNames
@@ -534,7 +534,7 @@ func generateSchemaData(n int, batchSize int) (data []SchemaData) {
534534
}
535535
data = append(data, schema)
536536
}
537-
return
537+
return data
538538
}
539539

540540
func generateTuples(names NamespaceNames, n int, objIDGenerator *generator.UniqueGenerator) (allowlists []*v1.RelationshipUpdate, blocklists []*v1.RelationshipUpdate, allowusers []*v1.RelationshipUpdate, blockusers []*v1.RelationshipUpdate) {
@@ -611,7 +611,7 @@ func generateTuples(names NamespaceNames, n int, objIDGenerator *generator.Uniqu
611611
Relationship: tupleBlockuser,
612612
})
613613
}
614-
return
614+
return allowlists, blocklists, allowusers, blockusers
615615
}
616616

617617
// getLeaderNode returns the node with the lease leader for the range containing the tuple

e2e/spice/spicedb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88
"strconv"
99
"time"
1010

11-
"github.com/authzed/grpcutil"
1211
"google.golang.org/grpc"
1312
"google.golang.org/grpc/credentials/insecure"
1413

14+
"github.com/authzed/grpcutil"
15+
1516
"github.com/authzed/spicedb/e2e"
1617
"github.com/authzed/spicedb/e2e/cockroach"
1718
"github.com/authzed/spicedb/internal/grpchelpers"

internal/datastore/mysql/watch.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,12 @@ func (mds *Datastore) loadChanges(
153153

154154
rows, err := mds.db.QueryContext(ctx, sql, args...)
155155
if err != nil {
156-
if errors.Is(ctx.Err(), context.Canceled) {
156+
switch {
157+
case errors.Is(ctx.Err(), context.Canceled):
157158
err = datastore.NewWatchCanceledErr()
158-
} else if common.IsCancellationError(err) {
159+
case common.IsCancellationError(err):
159160
err = datastore.NewWatchCanceledErr()
160-
} else if common.IsResettableError(err) {
161+
case common.IsResettableError(err):
161162
err = datastore.NewWatchTemporaryErr(err)
162163
}
163164
return changes, newRevision, err

internal/datastore/postgres/watch.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,14 @@ func (pgd *pgDatastore) Watch(
128128
for {
129129
newTxns, err := pgd.getNewRevisions(ctx, currentTxn)
130130
if err != nil {
131-
if errors.Is(ctx.Err(), context.Canceled) {
131+
switch {
132+
case errors.Is(ctx.Err(), context.Canceled):
132133
errs <- datastore.NewWatchCanceledErr()
133-
} else if common.IsCancellationError(err) {
134+
case common.IsCancellationError(err):
134135
errs <- datastore.NewWatchCanceledErr()
135-
} else if common.IsResettableError(err) {
136+
case common.IsResettableError(err):
136137
errs <- datastore.NewWatchTemporaryErr(err)
137-
} else {
138+
default:
138139
errs <- err
139140
}
140141
return
@@ -143,13 +144,14 @@ func (pgd *pgDatastore) Watch(
143144
if len(newTxns) > 0 {
144145
changesToWrite, err := pgd.loadChanges(ctx, newTxns, options)
145146
if err != nil {
146-
if errors.Is(ctx.Err(), context.Canceled) {
147+
switch {
148+
case errors.Is(ctx.Err(), context.Canceled):
147149
errs <- datastore.NewWatchCanceledErr()
148-
} else if common.IsCancellationError(err) {
150+
case common.IsCancellationError(err):
149151
errs <- datastore.NewWatchCanceledErr()
150-
} else if common.IsResettableError(err) {
152+
case common.IsResettableError(err):
151153
errs <- datastore.NewWatchTemporaryErr(err)
152-
} else {
154+
default:
153155
errs <- err
154156
}
155157
return

internal/datastore/proxy/schemacaching/watchingcache_test.go

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,39 +139,75 @@ func TestWatchingCacheParallelOperations(t *testing.T) {
139139
var wg sync.WaitGroup
140140
wg.Add(2)
141141

142+
firstErrs := make(chan error, 2)
143+
firstFallbackModes := make(chan bool, 1)
144+
firstNsDefNames := make(chan string, 1)
145+
146+
secondErrs := make(chan error, 2)
147+
secondFallbackModes := make(chan bool, 2)
148+
142149
go (func() {
150+
defer wg.Done()
151+
143152
// Read somenamespace (which should not be found)
144153
_, _, err := wcache.SnapshotReader(rev("1")).ReadNamespaceByName(t.Context(), "somenamespace")
145-
require.ErrorAs(t, err, &datastore.NamespaceNotFoundError{})
146-
require.False(t, wcache.namespaceCache.inFallbackMode)
154+
firstErrs <- err
155+
firstFallbackModes <- wcache.namespaceCache.inFallbackMode
147156

148157
// Write somenamespace.
149158
fakeDS.updateNamespace("somenamespace", &corev1.NamespaceDefinition{Name: "somenamespace"}, rev("2"))
150159

151160
// Read again (which should be found now)
152161
nsDef, _, err := wcache.SnapshotReader(rev("2")).ReadNamespaceByName(t.Context(), "somenamespace")
153-
require.NoError(t, err)
154-
require.Equal(t, "somenamespace", nsDef.Name)
155-
156-
wg.Done()
162+
firstErrs <- err
163+
firstNsDefNames <- nsDef.Name
157164
})()
158165

159166
go (func() {
167+
defer wg.Done()
168+
160169
// Read anothernamespace (which should not be found)
161170
_, _, err := wcache.SnapshotReader(rev("1")).ReadNamespaceByName(t.Context(), "anothernamespace")
162-
require.ErrorAs(t, err, &datastore.NamespaceNotFoundError{})
163-
require.False(t, wcache.namespaceCache.inFallbackMode)
171+
secondErrs <- err
172+
secondFallbackModes <- wcache.namespaceCache.inFallbackMode
164173

165174
// Read again (which should still not be found)
166175
_, _, err = wcache.SnapshotReader(rev("3")).ReadNamespaceByName(t.Context(), "anothernamespace")
167-
require.ErrorAs(t, err, &datastore.NamespaceNotFoundError{})
168-
require.False(t, wcache.namespaceCache.inFallbackMode)
169-
170-
wg.Done()
176+
secondErrs <- err
177+
secondFallbackModes <- wcache.namespaceCache.inFallbackMode
171178
})()
172179

173180
wg.Wait()
174181

182+
var nsNotFoundErr datastore.NamespaceNotFoundError
183+
184+
// Make the assertions
185+
// Assertions on first goroutine
186+
// Non-existent namespace
187+
err := <-firstErrs
188+
require.ErrorAs(t, err, &nsNotFoundErr)
189+
inFallbackMode := <-firstFallbackModes
190+
require.False(t, inFallbackMode)
191+
192+
// Namespace that we expect to exist
193+
err = <-firstErrs
194+
require.NoError(t, err, "expected namespace read from rev 2 to succeed")
195+
name := <-firstNsDefNames
196+
require.Equal(t, "somenamespace", name)
197+
198+
// Assertions on second goroutine
199+
// Reading a non-existent namespace
200+
err = <-secondErrs
201+
require.ErrorAs(t, err, &nsNotFoundErr)
202+
inFallbackMode = <-secondFallbackModes
203+
require.False(t, inFallbackMode)
204+
205+
// Reading another non-existent namespace
206+
err = <-secondErrs
207+
require.ErrorAs(t, err, &nsNotFoundErr)
208+
inFallbackMode = <-secondFallbackModes
209+
require.False(t, inFallbackMode)
210+
175211
// Close the proxy and ensure the background goroutines are terminated.
176212
wcache.Close()
177213
time.Sleep(10 * time.Millisecond)
@@ -208,22 +244,38 @@ func TestWatchingCacheParallelReaderWriter(t *testing.T) {
208244
wg.Done()
209245
})()
210246

247+
headRevisionErrors := make(chan error, 1000)
248+
snapshotReaderErrors := make(chan error, 1000)
249+
namespaceNames := make(chan string, 1000)
250+
211251
go (func() {
212252
// Start a loop to read a namespace a bunch of times.
213253
for i := 0; i < 1000; i++ {
214254
headRevision, err := fakeDS.HeadRevision(t.Context())
215-
require.NoError(t, err)
255+
headRevisionErrors <- err
216256

217257
nsDef, _, err := wcache.SnapshotReader(headRevision).ReadNamespaceByName(t.Context(), "somenamespace")
218-
require.NoError(t, err)
219-
require.Equal(t, "somenamespace", nsDef.Name)
258+
snapshotReaderErrors <- err
259+
namespaceNames <- nsDef.Name
220260
}
221261

222262
wg.Done()
223263
})()
224264

225265
wg.Wait()
226266

267+
// 1000 iterations, 3 channels
268+
for range 3000 {
269+
select {
270+
case headRevisionErr := <-headRevisionErrors:
271+
require.NoError(t, headRevisionErr, "unexpected error getting head revision")
272+
case snapshotReaderErr := <-snapshotReaderErrors:
273+
require.NoError(t, snapshotReaderErr, "unexpected error reading namespace")
274+
case namespaceName := <-namespaceNames:
275+
require.Equal(t, "somenamespace", namespaceName)
276+
}
277+
}
278+
227279
// Close the proxy and ensure the background goroutines are terminated.
228280
wcache.Close()
229281
time.Sleep(10 * time.Millisecond)

pkg/development/wasm/request.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
"fmt"
99
"syscall/js"
1010

11-
"github.com/authzed/spicedb/pkg/development"
12-
1311
"google.golang.org/protobuf/encoding/protojson"
1412

13+
"github.com/authzed/spicedb/pkg/development"
1514
devinterface "github.com/authzed/spicedb/pkg/proto/developer/v1"
1615
)
1716

pkg/schemadsl/parser/parser_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ func TestParser(t *testing.T) {
168168

169169
func getParseTree(currentNode *testNode, indentation int) string {
170170
parseTree := ""
171-
parseTree = parseTree + strings.Repeat(" ", indentation)
172-
parseTree = parseTree + fmt.Sprintf("%v", currentNode.nodeType)
173-
parseTree = parseTree + "\n"
171+
parseTree += strings.Repeat(" ", indentation)
172+
parseTree += fmt.Sprintf("%v", currentNode.nodeType)
173+
parseTree += "\n"
174174

175175
keys := make([]string, 0)
176176

@@ -181,9 +181,9 @@ func getParseTree(currentNode *testNode, indentation int) string {
181181
sort.Strings(keys)
182182

183183
for _, key := range keys {
184-
parseTree = parseTree + strings.Repeat(" ", indentation+2)
185-
parseTree = parseTree + fmt.Sprintf("%s = %v", key, currentNode.properties[key])
186-
parseTree = parseTree + "\n"
184+
parseTree += strings.Repeat(" ", indentation+2)
185+
parseTree += fmt.Sprintf("%s = %v", key, currentNode.properties[key])
186+
parseTree += "\n"
187187
}
188188

189189
keys = make([]string, 0)
@@ -196,11 +196,11 @@ func getParseTree(currentNode *testNode, indentation int) string {
196196

197197
for _, key := range keys {
198198
value := currentNode.children[key]
199-
parseTree = parseTree + fmt.Sprintf("%s%v =>", strings.Repeat(" ", indentation+2), key)
200-
parseTree = parseTree + "\n"
199+
parseTree += fmt.Sprintf("%s%v =>", strings.Repeat(" ", indentation+2), key)
200+
parseTree += "\n"
201201

202202
for e := value.Front(); e != nil; e = e.Next() {
203-
parseTree = parseTree + getParseTree(e.Value.(*testNode), indentation+4)
203+
parseTree += getParseTree(e.Value.(*testNode), indentation+4)
204204
}
205205
}
206206

tools/analyzers/cmd/analyzers/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"golang.org/x/tools/go/analysis/multichecker"
5+
46
"github.com/authzed/spicedb/tools/analyzers/closeafterusagecheck"
57
"github.com/authzed/spicedb/tools/analyzers/exprstatementcheck"
68
"github.com/authzed/spicedb/tools/analyzers/iferrafterrowclosecheck"
@@ -11,7 +13,6 @@ import (
1113
"github.com/authzed/spicedb/tools/analyzers/protomarshalcheck"
1214
"github.com/authzed/spicedb/tools/analyzers/telemetryconvcheck"
1315
"github.com/authzed/spicedb/tools/analyzers/zerologmarshalcheck"
14-
"golang.org/x/tools/go/analysis/multichecker"
1516
)
1617

1718
func main() {

tools/analyzers/mutexcheck/mutexcheck.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
"github.com/samber/lo"
12-
1312
"golang.org/x/tools/go/analysis"
1413
"golang.org/x/tools/go/analysis/passes/inspect"
1514
"golang.org/x/tools/go/ast/inspector"

0 commit comments

Comments
 (0)