Skip to content

Commit deb8aff

Browse files
staticcheck: fix warnings in mongo
1 parent 0cbfb19 commit deb8aff

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

mongo/collection_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import (
2525
)
2626

2727
const (
28-
testDbName = "unitTestDb"
28+
testDBName = "unitTestDB"
2929
)
3030

3131
func setupColl(name string, opts ...options.Lister[options.CollectionOptions]) *Collection {
32-
db := setupDb(testDbName)
32+
db := setupDB(testDBName)
3333
return db.Collection(name, opts...)
3434
}
3535

@@ -72,7 +72,7 @@ func TestCollection(t *testing.T) {
7272
rcLocal := readconcern.Local()
7373
wc1 := &writeconcern.WriteConcern{W: 10}
7474

75-
db := setupDb("foo", options.Database().SetReadPreference(rpPrimary).SetReadConcern(rcLocal))
75+
db := setupDB("foo", options.Database().SetReadPreference(rpPrimary).SetReadConcern(rcLocal))
7676
coll := db.Collection("bar", options.Collection().SetWriteConcern(wc1))
7777
expected := &Collection{
7878
readPreference: rpPrimary,
@@ -143,7 +143,7 @@ func TestCollection(t *testing.T) {
143143
t.Run("database accessor", func(t *testing.T) {
144144
coll := setupColl("bar")
145145
dbName := coll.Database().Name()
146-
assert.Equal(t, testDbName, dbName, "expected db name %v, got %v", testDbName, dbName)
146+
assert.Equal(t, testDBName, dbName, "expected db name %v, got %v", testDBName, dbName)
147147
})
148148
t.Run("nil document error", func(t *testing.T) {
149149
coll := setupColl("foo")

mongo/database.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ import (
2929
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/session"
3030
)
3131

32-
var (
33-
defaultRunCmdOpts = []options.Lister[options.RunCmdOptions]{options.RunCmd().SetReadPreference(readpref.Primary())}
34-
)
32+
var defaultRunCmdOpts = []options.Lister[options.RunCmdOptions]{options.RunCmd().SetReadPreference(readpref.Primary())}
3533

3634
// Database is a handle to a MongoDB database. It is safe for concurrent use by multiple goroutines.
3735
type Database struct {
@@ -576,8 +574,8 @@ func (db *Database) ListCollectionNames(
576574
// The opts parameter can be used to specify options for change stream creation (see the options.ChangeStreamOptions
577575
// documentation).
578576
func (db *Database) Watch(ctx context.Context, pipeline any,
579-
opts ...options.Lister[options.ChangeStreamOptions]) (*ChangeStream, error) {
580-
577+
opts ...options.Lister[options.ChangeStreamOptions],
578+
) (*ChangeStream, error) {
581579
csConfig := changeStreamConfig{
582580
readConcern: db.readConcern,
583581
readPreference: db.readPreference,
@@ -700,7 +698,7 @@ func (db *Database) createCollectionWithEncryptedFields(
700698
defer conn.Close()
701699
wireVersionRange := conn.Description().WireVersion
702700
if wireVersionRange.Max < QEv2WireVersion {
703-
return fmt.Errorf("Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption. Got maxWireVersion %v but need maxWireVersion >= %v", wireVersionRange.Max, QEv2WireVersion)
701+
return fmt.Errorf("driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption. Got maxWireVersion %v but need maxWireVersion >= %v", wireVersionRange.Max, QEv2WireVersion)
704702
}
705703
}
706704

@@ -897,8 +895,8 @@ func (db *Database) createCollectionOperation(
897895
// See https://www.mongodb.com/docs/manual/core/views/ for more information
898896
// about views.
899897
func (db *Database) CreateView(ctx context.Context, viewName, viewOn string, pipeline any,
900-
opts ...options.Lister[options.CreateViewOptions]) error {
901-
898+
opts ...options.Lister[options.CreateViewOptions],
899+
) error {
902900
pipelineArray, _, err := marshalAggregatePipeline(pipeline, db.bsonOpts, db.registry)
903901
if err != nil {
904902
return err
@@ -979,7 +977,7 @@ func (db *Database) GridFSBucket(opts ...options.Lister[options.BucketOptions])
979977
b.rp = bo.ReadPreference
980978
}
981979

982-
var collOpts = options.Collection().SetWriteConcern(b.wc).SetReadConcern(b.rc).SetReadPreference(b.rp)
980+
collOpts := options.Collection().SetWriteConcern(b.wc).SetReadConcern(b.rc).SetReadPreference(b.rp)
983981

984982
b.chunksColl = db.Collection(b.name+".chunks", collOpts)
985983
b.filesColl = db.Collection(b.name+".files", collOpts)

mongo/database_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology"
2323
)
2424

25-
func setupDb(name string, opts ...options.Lister[options.DatabaseOptions]) *Database {
25+
func setupDB(name string, opts ...options.Lister[options.DatabaseOptions]) *Database {
2626
client := setupClient()
2727
return client.Database(name, opts...)
2828
}
@@ -42,7 +42,7 @@ func compareDbs(t *testing.T, expected, got *Database) {
4242
func TestDatabase(t *testing.T) {
4343
t.Run("initialize", func(t *testing.T) {
4444
name := "foo"
45-
db := setupDb(name)
45+
db := setupDB(name)
4646
assert.Equal(t, name, db.Name(), "expected db name %v, got %v", name, db.Name())
4747
assert.NotNil(t, db.Client(), "expected valid client, got nil")
4848
})
@@ -64,7 +64,7 @@ func TestDatabase(t *testing.T) {
6464
writeConcern: wc2,
6565
registry: reg,
6666
}
67-
got := setupDb("foo", opts)
67+
got := setupDB("foo", opts)
6868
compareDbs(t, expected, got)
6969
})
7070
t.Run("inherit", func(t *testing.T) {
@@ -85,7 +85,7 @@ func TestDatabase(t *testing.T) {
8585
})
8686
})
8787
t.Run("replaceErrors for disconnected topology", func(t *testing.T) {
88-
db := setupDb("foo")
88+
db := setupDB("foo")
8989

9090
topo, ok := db.client.deployment.(*topology.Topology)
9191
require.True(t, ok, "client deployment is not a topology")
@@ -138,7 +138,7 @@ func TestDatabase(t *testing.T) {
138138
})
139139
})
140140
t.Run("nil document error", func(t *testing.T) {
141-
db := setupDb("foo")
141+
db := setupDB("foo")
142142

143143
err := db.RunCommand(bgCtx, nil).Err()
144144
assert.True(t, errors.Is(err, ErrNilDocument), "expected error %v, got %v", ErrNilDocument, err)

0 commit comments

Comments
 (0)