Skip to content

Commit f29d01d

Browse files
author
Divjot Arora
authored
GODRIVER-1394 Remove receiver from mongotest functions (#516)
1 parent 5f52e42 commit f29d01d

18 files changed

+85
-74
lines changed

mongo/integration/change_stream_spec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func runChangeStreamTest(mt *mtest.T, test changeStreamTest, testFile changeStre
109109

110110
// Pin to a single mongos because some tests set fail points and in a sharded cluster, the failpoint and command
111111
// that fail must be sent to the same mongos.
112-
if mt.TopologyKind() == mtest.Sharded {
112+
if mtest.ClusterTopologyKind() == mtest.Sharded {
113113
mtOpts = mtOpts.ClientType(mtest.Pinned)
114114
}
115115

@@ -192,7 +192,7 @@ func runChangeStreamOperations(mt *mtest.T, test changeStreamTest) error {
192192
}, false)
193193
}
194194
// Use the global client to run the operations so they don't show up in the expectations
195-
mt.DB = mt.GlobalClient().Database(op.Database)
195+
mt.DB = mtest.GlobalClient().Database(op.Database)
196196
mt.Coll = mt.DB.Collection(op.Collection)
197197

198198
var err error

mongo/integration/client_side_encryption_prose_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
5151

5252
assert.NotEqual(mt, keyID, "", "%s env var not set", awsAccessKeyID)
5353
assert.NotEqual(mt, secretAccessKey, "", "%s env var not set", awsSecretAccessKey)
54-
defaultKvClientOptions := options.Client().ApplyURI(mt.ConnString())
54+
defaultKvClientOptions := options.Client().ApplyURI(mtest.ClusterURI())
5555

5656
mt.RunOpts("data key and double encryption", noClientOpts, func(mt *mtest.T) {
5757
// set up options structs
@@ -100,7 +100,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
100100
startedEvents = append(startedEvents, evt)
101101
},
102102
}
103-
kvClientOpts := options.Client().ApplyURI(mt.ConnString()).SetMonitor(monitor)
103+
kvClientOpts := options.Client().ApplyURI(mtest.ClusterURI()).SetMonitor(monitor)
104104
cpt := setup(mt, aeo, kvClientOpts, ceo)
105105
defer cpt.teardown(mt)
106106

@@ -188,7 +188,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
188188
kvClientOpts := defaultKvClientOptions
189189

190190
if tc.externalVault {
191-
externalKvOpts := options.Client().ApplyURI(mt.ConnString()).SetAuth(options.Credential{
191+
externalKvOpts := options.Client().ApplyURI(mtest.ClusterURI()).SetAuth(options.Credential{
192192
Username: "fake-user",
193193
Password: "fake-password",
194194
})
@@ -842,7 +842,7 @@ func setup(mt *mtest.T, aeo *options.AutoEncryptionOptions, kvClientOpts *option
842842
cpt.cseStarted = append(cpt.cseStarted, evt)
843843
},
844844
}
845-
opts := options.Client().ApplyURI(mt.ConnString()).SetWriteConcern(mtest.MajorityWc).
845+
opts := options.Client().ApplyURI(mtest.ClusterURI()).SetWriteConcern(mtest.MajorityWc).
846846
SetReadPreference(mtest.PrimaryRp).SetAutoEncryptionOptions(aeo).SetMonitor(cseMonitor)
847847
cpt.cseClient, err = mongo.Connect(mtest.Background, opts)
848848
assert.Nil(mt, err, "Connect error for encrypted client: %v", err)

mongo/integration/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestClient(t *testing.T) {
100100
).Err()
101101
assert.Nil(mt, err, "createUser error: %v", err)
102102

103-
baseConnString := mt.ConnString()
103+
baseConnString := mtest.ClusterURI()
104104
// remove username/password from base conn string
105105
revisedConnString := "mongodb://"
106106
split := strings.Split(baseConnString, "@")
@@ -269,7 +269,7 @@ func TestClient(t *testing.T) {
269269
})
270270
mt.RunOpts("watch", noClientOpts, func(mt *mtest.T) {
271271
mt.Run("disconnected", func(mt *mtest.T) {
272-
c, err := mongo.NewClient(options.Client().ApplyURI(mt.ConnString()))
272+
c, err := mongo.NewClient(options.Client().ApplyURI(mtest.ClusterURI()))
273273
assert.Nil(mt, err, "NewClient error: %v", err)
274274
_, err = c.Watch(mtest.Background, mongo.Pipeline{})
275275
assert.Equal(mt, mongo.ErrClientDisconnected, err, "expected error %v, got %v", mongo.ErrClientDisconnected, err)
@@ -404,7 +404,7 @@ func TestClient(t *testing.T) {
404404
})
405405

406406
// Test that direct connections work as expected.
407-
firstServerAddr := mt.GlobalTopology().Description().Servers[0].Addr
407+
firstServerAddr := mtest.GlobalTopology().Description().Servers[0].Addr
408408
directConnectionOpts := options.Client().
409409
ApplyURI(fmt.Sprintf("mongodb://%s", firstServerAddr)).
410410
SetReadPreference(readpref.Primary()).

mongo/integration/command_monitoring_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func runMonitoringTest(mt *mtest.T, test monitoringTest, testFile monitoringTest
7676
// ignored topologies have to be handled separately because mtest only accepts topologies to run on, not
7777
// topologies to ignore
7878
for _, top := range test.IgnoredTopologies {
79-
if top == mt.TopologyKind() {
79+
if top == mtest.ClusterTopologyKind() {
8080
mt.Skipf("skipping topology %v", top)
8181
}
8282
}
8383

84-
setupColl := mt.GlobalClient().Database(mt.DB.Name()).Collection(mt.Coll.Name())
84+
setupColl := mtest.GlobalClient().Database(mt.DB.Name()).Collection(mt.Coll.Name())
8585
insertDocuments(mt, setupColl, testFile.Data)
8686
mt.ClearEvents()
8787
runMonitoringOperation(mt, test.Operation)

mongo/integration/crud_helpers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ func killSessions(mt *mtest.T) {
115115
// replica sets, the command is run against the primary. sharded clusters, the command is run against each mongos.
116116
func runCommandOnAllServers(mt *mtest.T, commandFn func(client *mongo.Client) error) error {
117117
opts := options.Client().
118-
ApplyURI(mt.ConnString())
118+
ApplyURI(mtest.ClusterURI())
119119

120-
if mt.TopologyKind() != mtest.Sharded {
120+
if mtest.ClusterTopologyKind() != mtest.Sharded {
121121
client, err := mongo.Connect(mtest.Background, opts)
122122
if err != nil {
123123
return fmt.Errorf("error creating replica set client: %v", err)
@@ -1405,7 +1405,7 @@ func executeCreateCollection(mt *mtest.T, sess mongo.Session, args bson.Raw) err
14051405

14061406
func executeAdminCommand(mt *mtest.T, op *operation) {
14071407
// Per the streamable isMaster test format description, a separate client must be used to execute this operation.
1408-
clientOpts := options.Client().ApplyURI(mt.ConnString())
1408+
clientOpts := options.Client().ApplyURI(mtest.ClusterURI())
14091409
client, err := mongo.Connect(mtest.Background, clientOpts)
14101410
assert.Nil(mt, err, "Connect error: %v", err)
14111411
defer func() {

mongo/integration/data_lake_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ func TestAtlasDataLake(t *testing.T) {
9696
}
9797

9898
func getBaseClientOptions(mt *mtest.T) *options.ClientOptions {
99-
opts := options.Client().ApplyURI(mt.ConnString())
99+
opts := options.Client().ApplyURI(mtest.ClusterURI())
100100
return options.Client().SetHosts(opts.Hosts)
101101
}
102102

103103
func getBaseCredential(mt *mtest.T) options.Credential {
104104
mt.Helper()
105105

106-
cred := options.Client().ApplyURI(mt.ConnString()).Auth
107-
assert.NotNil(mt, cred, "expected options for URI %q to have a non-nil Auth field", mt.ConnString())
106+
cred := options.Client().ApplyURI(mtest.ClusterURI()).Auth
107+
assert.NotNil(mt, cred, "expected options for URI %q to have a non-nil Auth field", mtest.ClusterURI())
108108
return *cred
109109
}

mongo/integration/database_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ func TestDatabase(t *testing.T) {
260260
ReadOnly: false,
261261
Options: bson.Raw(optionsDoc),
262262
}
263-
if mtest.CompareServerVersions(mt.ServerVersion(), "3.6") >= 0 {
263+
if mtest.CompareServerVersions(mtest.ServerVersion(), "3.6") >= 0 {
264264
uuidSubtype, uuidData := cursor.Current.Lookup("info", "uuid").Binary()
265265
expectedSpec.UUID = &primitive.Binary{Subtype: uuidSubtype, Data: uuidData}
266266
}
267-
if mtest.CompareServerVersions(mt.ServerVersion(), "3.4") >= 0 {
267+
if mtest.CompareServerVersions(mtest.ServerVersion(), "3.4") >= 0 {
268268
keysDoc := bsoncore.NewDocumentBuilder().
269269
AppendInt32("_id", 1).
270270
Build()

mongo/integration/errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestErrors(t *testing.T) {
5151
},
5252
})
5353

54-
client, err := mongo.Connect(mtest.Background, options.Client().ApplyURI(mt.ConnString()))
54+
client, err := mongo.Connect(mtest.Background, options.Client().ApplyURI(mtest.ClusterURI()))
5555
assert.Nil(mt, err, "Connect error: %v", err)
5656
defer client.Disconnect(mtest.Background)
5757

mongo/integration/index_view_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func TestIndexView(t *testing.T) {
331331
KeysDocument: bson.Raw(keysDoc),
332332
Version: 2,
333333
}
334-
if mtest.CompareServerVersions(mt.ServerVersion(), "3.4") < 0 {
334+
if mtest.CompareServerVersions(mtest.ServerVersion(), "3.4") < 0 {
335335
expectedSpec.Version = 1
336336
}
337337

mongo/integration/mongos_pinning_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestMongosPinning(t *testing.T) {
2525
mt := mtest.New(t, mtOpts)
2626
defer mt.Close()
2727

28-
if len(options.Client().ApplyURI(mt.ConnString()).Hosts) < 2 {
28+
if len(options.Client().ApplyURI(mtest.ClusterURI()).Hosts) < 2 {
2929
mt.Skip("skipping because at least 2 mongoses are required")
3030
}
3131

0 commit comments

Comments
 (0)