Skip to content

Commit 2731aa3

Browse files
authored
Fix lint issues after Go driver update. (#31)
1 parent 68fa286 commit 2731aa3

File tree

11 files changed

+48
-42
lines changed

11 files changed

+48
-42
lines changed

.github/workflows/all.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
# This is hard-coded by design in order to catch inadvertent changes
2424
# to the minimum-required Go version to build migration-verifier.
25-
- 1.19
25+
- '1.20'
2626
- stable
2727

2828
runs-on: ${{matrix.os.runsOn}}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/10gen/migration-verifier
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
github.com/deckarep/golang-set/v2 v2.3.0

internal/partitions/partition_test.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,50 +73,60 @@ func (suite *UnitTestSuite) TestVersioning() {
7373
expectedFilterWithTypeBracketing := makeExpectedFilterWithTypeBracketing(partition.Key.Lower, partition.Upper)
7474
// No version given, default to no bracketing
7575
findOptions := partition.GetFindOptions(nil, nil)
76-
filter := findOptions.Map()["filter"]
76+
filter := getFilterFromFindOptions(findOptions)
7777
suite.Require().Equal(expectedFilter, filter)
7878

7979
// 6.0 (int64)
8080
findOptions = partition.GetFindOptions(&bson.M{"versionArray": bson.A{int64(6), int64(0), int64(0), int64(0)}}, nil)
81-
filter = findOptions.Map()["filter"]
81+
filter = getFilterFromFindOptions(findOptions)
8282
suite.Require().Equal(expectedFilter, filter)
8383

8484
// 6.0
8585
findOptions = partition.GetFindOptions(&bson.M{"versionArray": bson.A{int32(6), int32(0), int32(0), int32(0)}}, nil)
86-
filter = findOptions.Map()["filter"]
86+
filter = getFilterFromFindOptions(findOptions)
8787
suite.Require().Equal(expectedFilter, filter)
8888

8989
// 5.3.0.9
9090
findOptions = partition.GetFindOptions(&bson.M{"versionArray": bson.A{int32(5), int32(3), int32(0), int32(9)}}, nil)
91-
filter = findOptions.Map()["filter"]
91+
filter = getFilterFromFindOptions(findOptions)
9292
suite.Require().Equal(expectedFilter, filter)
9393

9494
// 7.1.3.5
9595
findOptions = partition.GetFindOptions(&bson.M{"versionArray": bson.A{int32(7), int32(1), int32(3), int32(5)}}, nil)
96-
filter = findOptions.Map()["filter"]
96+
filter = getFilterFromFindOptions(findOptions)
9797
suite.Require().Equal(expectedFilter, filter)
9898

9999
// 4.4 (int64)
100100
findOptions = partition.GetFindOptions(&bson.M{"versionArray": bson.A{int64(4), int64(4), int64(0), int64(0)}}, nil)
101-
filter = findOptions.Map()["filter"]
101+
filter = getFilterFromFindOptions(findOptions)
102102
suite.Require().Equal(expectedFilterWithTypeBracketing, filter)
103103

104104
// 4.4
105105
findOptions = partition.GetFindOptions(&bson.M{"versionArray": bson.A{int32(4), int32(4), int32(0), int32(0)}}, nil)
106-
filter = findOptions.Map()["filter"]
106+
filter = getFilterFromFindOptions(findOptions)
107107
suite.Require().Equal(expectedFilterWithTypeBracketing, filter)
108108

109109
// 4.2
110110
findOptions = partition.GetFindOptions(&bson.M{"versionArray": bson.A{int32(4), int32(2), int32(0), int32(0)}}, nil)
111-
filter = findOptions.Map()["filter"]
111+
filter = getFilterFromFindOptions(findOptions)
112112
suite.Require().Equal(expectedFilterWithTypeBracketing, filter)
113113

114114
// No version array -- assume old, require type bracketing.
115115
findOptions = partition.GetFindOptions(&bson.M{"notVersionArray": bson.A{6, int32(0), int32(0), int32(0)}}, nil)
116-
filter = findOptions.Map()["filter"]
116+
filter = getFilterFromFindOptions(findOptions)
117117
suite.Require().Equal(expectedFilterWithTypeBracketing, filter)
118118
}
119119

120+
func getFilterFromFindOptions(opts bson.D) any {
121+
for _, el := range opts {
122+
if el.Key == "filter" {
123+
return el.Value
124+
}
125+
}
126+
127+
return nil
128+
}
129+
120130
func makeTestPartition() (Partition, bson.D) {
121131
partition := Partition{
122132
Key: PartitionKey{

internal/util/uuid.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/google/uuid"
7+
"go.mongodb.org/mongo-driver/bson"
78
"go.mongodb.org/mongo-driver/bson/bsoncodec"
89
"go.mongodb.org/mongo-driver/bson/bsontype"
910
"go.mongodb.org/mongo-driver/bson/primitive"
@@ -21,10 +22,10 @@ const (
2122
type UUID uuid.UUID
2223

2324
var (
24-
_ bsoncodec.ValueMarshaler = UUID{}
25-
_ bsoncodec.ValueUnmarshaler = (*UUID)(nil)
26-
_ bsoncodec.KeyMarshaler = UUID{}
27-
_ bsoncodec.KeyUnmarshaler = (*UUID)(nil)
25+
_ bson.ValueMarshaler = UUID{}
26+
_ bson.ValueUnmarshaler = (*UUID)(nil)
27+
_ bsoncodec.KeyMarshaler = UUID{}
28+
_ bsoncodec.KeyUnmarshaler = (*UUID)(nil)
2829
)
2930

3031
// NewUUID constructs a new, randomly-generated UUID.
@@ -36,13 +37,13 @@ func NewUUID() UUID {
3637
// ValueMarshaler interface.
3738
func (u UUID) MarshalBSONValue() (bsontype.Type, []byte, error) {
3839
val := bsoncore.AppendBinary(nil, uuidBinarySubtype, u[:])
39-
return bsontype.Binary, val, nil
40+
return bson.TypeBinary, val, nil
4041
}
4142

4243
// UnmarshalBSONValue is used to unmarshal BSON into UUID objects. This implements the
4344
// ValueUnmarshaler interface.
4445
func (u *UUID) UnmarshalBSONValue(bsonType bsontype.Type, data []byte) error {
45-
if bsonType != bsontype.Binary {
46+
if bsonType != bson.TypeBinary {
4647
return fmt.Errorf("cannot decoded BSON value of type %s as a UUID", bsonType)
4748
}
4849

internal/verifier/bson_compare.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"go.mongodb.org/mongo-driver/bson"
7-
"go.mongodb.org/mongo-driver/bson/bsontype"
87
)
98

109
type MismatchDetails struct {
@@ -109,9 +108,9 @@ func bsonUnorderedCompareRawValue(srcValue, dstValue bson.RawValue) (bool, error
109108
}
110109

111110
switch srcValue.Type {
112-
case bsontype.Array:
111+
case bson.TypeArray:
113112
return bsonUnorderedCompareRawArray(srcValue.Array(), dstValue.Array())
114-
case bsontype.EmbeddedDocument:
113+
case bson.TypeEmbeddedDocument:
115114
return BsonUnorderedCompareRawDocument(srcValue.Document(), dstValue.Document())
116115
default:
117116
return srcValue.Equal(dstValue), nil

internal/verifier/change_stream.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type DocKey struct {
3737
func (verifier *Verifier) HandleChangeStreamEvent(ctx context.Context, changeEvent *ParsedEvent) error {
3838
if changeEvent.ClusterTime != nil &&
3939
(verifier.lastChangeEventTime == nil ||
40-
primitive.CompareTimestamp(*verifier.lastChangeEventTime, *changeEvent.ClusterTime) < 0) {
40+
verifier.lastChangeEventTime.Compare(*changeEvent.ClusterTime) < 0) {
4141
verifier.lastChangeEventTime = changeEvent.ClusterTime
4242
}
4343
switch changeEvent.OpType {
@@ -175,7 +175,7 @@ func (verifier *Verifier) StartChangeStream(ctx context.Context, startTime *prim
175175
}
176176

177177
verifier.logger.Debug().Msgf("Initial cluster time is %+v", clusterTimeTs)
178-
if primitive.CompareTimestamp(clusterTimeTs, resumeTokenTime) < 0 {
178+
if clusterTimeTs.Compare(resumeTokenTime) < 0 {
179179
verifier.srcStartAtTs = &clusterTimeTs
180180
}
181181
}

internal/verifier/change_stream_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/stretchr/testify/require"
88
"go.mongodb.org/mongo-driver/bson"
9-
"go.mongodb.org/mongo-driver/bson/primitive"
109
"go.mongodb.org/mongo-driver/mongo"
1110
)
1211

@@ -77,7 +76,7 @@ func (suite *MultiSourceVersionTestSuite) TestStartAtTimeWithChanges() {
7776
suite.Require().NoError(err)
7877
newStartTs := sess.OperationTime()
7978
suite.Require().NotNil(newStartTs)
80-
suite.Require().Less(primitive.CompareTimestamp(*origStartTs, *newStartTs), 0)
79+
suite.Require().Negative(origStartTs.Compare(*newStartTs))
8180
verifier.changeStreamEnderChan <- struct{}{}
8281
<-verifier.changeStreamDoneChan
8382
suite.Require().Equal(verifier.srcStartAtTs, newStartTs)
@@ -98,6 +97,5 @@ func (suite *MultiSourceVersionTestSuite) TestNoStartAtTime() {
9897
err = verifier.StartChangeStream(ctx, nil)
9998
suite.Require().NoError(err)
10099
suite.Require().NotNil(verifier.srcStartAtTs)
101-
suite.Require().LessOrEqual(primitive.CompareTimestamp(
102-
*origStartTs, *verifier.srcStartAtTs), 0)
100+
suite.Require().LessOrEqual(origStartTs.Compare(*verifier.srcStartAtTs), 0)
103101
}

internal/verifier/migration_verifier.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (verifier *Verifier) getClientOpts(uri string) *options.ClientOptions {
211211
AppName: &appName,
212212
}
213213
opts.ApplyURI(uri)
214-
opts.SetWriteConcern(writeconcern.New(writeconcern.WMajority()))
214+
opts.SetWriteConcern(writeconcern.Majority())
215215

216216
verifier.doIfForceReadConcernMajority(func() {
217217
opts.SetReadConcern(readconcern.Majority())
@@ -714,12 +714,11 @@ func (verifier *Verifier) logChunkInfo(ctx context.Context, namespaceAndUUID *uu
714714
}
715715
defer cursor.Close(ctx)
716716
for cursor.Next(ctx) {
717-
var result bson.D
718-
if err = cursor.Decode(&result); err != nil {
717+
var resultMap bson.M
718+
if err = cursor.Decode(&resultMap); err != nil {
719719
verifier.logger.Error().Msgf("Error decoding chunk info for %s: %v", namespace, err)
720720
return
721721
}
722-
resultMap := result.Map()
723722
verifier.logger.Debug().Msgf(" Chunk of %s on %v, range %v to %v", namespace, resultMap["shard"],
724723
resultMap["min"], resultMap["max"])
725724
}
@@ -986,7 +985,7 @@ func (verifier *Verifier) markCollectionFailed(workerNum int, task *Verification
986985
Details: Failed + fmt.Sprintf(" %v", err)})
987986
}
988987

989-
func verifyIndexes(ctx context.Context, workerNum int, task *VerificationTask, srcColl, dstColl *mongo.Collection,
988+
func verifyIndexes(ctx context.Context, _ int, _ *VerificationTask, srcColl, dstColl *mongo.Collection,
990989
srcIdIndexSpec, dstIdIndexSpec *mongo.IndexSpecification) ([]VerificationResult, error) {
991990
srcSpecs, err := srcColl.Indexes().ListSpecifications(ctx)
992991
if err != nil {
@@ -1209,12 +1208,12 @@ func (verifier *Verifier) doIfForceReadConcernMajority(f func()) {
12091208

12101209
func (verifier *Verifier) verificationDatabase() *mongo.Database {
12111210
db := verifier.metaClient.Database(verifier.metaDBName)
1212-
if db.WriteConcern().GetW() != "majority" {
1211+
if db.WriteConcern().W != "majority" {
12131212
verifier.logger.Fatal().Msgf("Verification metadata is not using write concern majority: %+v", db.WriteConcern())
12141213
}
12151214

12161215
verifier.doIfForceReadConcernMajority(func() {
1217-
if db.ReadConcern().GetLevel() != "majority" {
1216+
if db.ReadConcern().Level != "majority" {
12181217
verifier.logger.Fatal().Msgf("Verification metadata is not using read concern majority: %+v", db.ReadConcern())
12191218
}
12201219
})
@@ -1234,7 +1233,7 @@ func (verifier *Verifier) srcClientDatabase(dbName string) *mongo.Database {
12341233
db := verifier.srcClient.Database(dbName)
12351234
// No need to check the write concern because we do not write to the source database.
12361235
verifier.doIfForceReadConcernMajority(func() {
1237-
if db.ReadConcern().GetLevel() != "majority" {
1236+
if db.ReadConcern().Level != "majority" {
12381237
verifier.logger.Fatal().Msgf("Source client is not using read concern majority: %+v", db.ReadConcern())
12391238
}
12401239
})
@@ -1245,7 +1244,7 @@ func (verifier *Verifier) dstClientDatabase(dbName string) *mongo.Database {
12451244
db := verifier.dstClient.Database(dbName)
12461245
// No need to check the write concern because we do not write to the target database.
12471246
verifier.doIfForceReadConcernMajority(func() {
1248-
if db.ReadConcern().GetLevel() != "majority" {
1247+
if db.ReadConcern().Level != "majority" {
12491248
verifier.logger.Fatal().Msgf("Source client is not using read concern majority: %+v", db.ReadConcern())
12501249
}
12511250
})
@@ -1460,11 +1459,10 @@ func getBuildInfo(ctx context.Context, client *mongo.Client) (*bson.M, error) {
14601459
if commandResult.Err() != nil {
14611460
return nil, commandResult.Err()
14621461
}
1463-
var buildInfo bson.D
1464-
err := commandResult.Decode(&buildInfo)
1462+
var buildInfoMap bson.M
1463+
err := commandResult.Decode(&buildInfoMap)
14651464
if err != nil {
14661465
return nil, err
14671466
}
1468-
buildInfoMap := buildInfo.Map()
14691467
return &buildInfoMap, nil
14701468
}

internal/verifier/migration_verifier_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (suite *MultiDataVersionTestSuite) TestVerifierFetchDocuments() {
161161
func() {
162162
doc := srcMap.Fetch(both[0])
163163
val := doc.Lookup("num")
164-
suite.Assert().Less(val.AsInt32(), int32(100))
164+
suite.Assert().Less(val.AsInt64(), int64(100))
165165
},
166166
"doc is fetched",
167167
)

internal/verifier/unit_test_util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func (suite *WithMongodsTestSuite) SetupSuite() {
8383
err := startTestMongods(suite.T(), &suite.srcMongoInstance, &suite.dstMongoInstance, &suite.metaMongoInstance)
8484
suite.Require().NoError(err)
8585
ctx := context.Background()
86-
clientOpts := options.Client().ApplyURI("mongodb://localhost:" + suite.srcMongoInstance.port).SetAppName("Verifier Test Suite").SetWriteConcern(writeconcern.New(writeconcern.WMajority()))
86+
clientOpts := options.Client().ApplyURI("mongodb://localhost:" + suite.srcMongoInstance.port).SetAppName("Verifier Test Suite").SetWriteConcern(writeconcern.Majority())
8787
suite.srcMongoClient, err = mongo.Connect(ctx, clientOpts)
8888
suite.Require().NoError(err)
89-
clientOpts = options.Client().ApplyURI("mongodb://localhost:" + suite.dstMongoInstance.port).SetAppName("Verifier Test Suite").SetWriteConcern(writeconcern.New(writeconcern.WMajority()))
89+
clientOpts = options.Client().ApplyURI("mongodb://localhost:" + suite.dstMongoInstance.port).SetAppName("Verifier Test Suite").SetWriteConcern(writeconcern.Majority())
9090
suite.dstMongoClient, err = mongo.Connect(ctx, clientOpts)
9191
suite.Require().NoError(err)
9292
clientOpts = options.Client().ApplyURI("mongodb://localhost:" + suite.metaMongoInstance.port).SetAppName("Verifier Test Suite")

0 commit comments

Comments
 (0)