Skip to content

Commit e821f2d

Browse files
GODRIVER-3434 Revert builder-lister pattern for client options
1 parent 4f4f715 commit e821f2d

28 files changed

+377
-851
lines changed

internal/cmd/testatlas/atlas_test.go

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

1818
"go.mongodb.org/mongo-driver/v2/bson"
1919
"go.mongodb.org/mongo-driver/v2/internal/handshake"
20-
"go.mongodb.org/mongo-driver/v2/internal/mongoutil"
2120
"go.mongodb.org/mongo-driver/v2/mongo"
2221
"go.mongodb.org/mongo-driver/v2/mongo/options"
2322
)
@@ -46,12 +45,7 @@ func TestAtlas(t *testing.T) {
4645
t.Fatalf("error running test with TLS at index %d: %v", idx, err)
4746
}
4847

49-
args, err := mongoutil.NewOptions[options.ClientOptions](clientOpts)
50-
if err != nil {
51-
panic(fmt.Sprintf("failed to construct args from options: %v", err))
52-
}
53-
54-
tlsConfigSkipVerify := args.TLSConfig
48+
tlsConfigSkipVerify := clientOpts.TLSConfig
5549
tlsConfigSkipVerify.InsecureSkipVerify = true
5650

5751
// Run the connectivity test with InsecureSkipVerify to ensure SNI is done correctly even if verification is
@@ -66,7 +60,7 @@ func TestAtlas(t *testing.T) {
6660
t.Logf("Finished!")
6761
}
6862

69-
func runTest(ctx context.Context, clientOpts *options.ClientOptionsBuilder) error {
63+
func runTest(ctx context.Context, clientOpts *options.ClientOptions) error {
7064
client, err := mongo.Connect(clientOpts)
7165
if err != nil {
7266
return fmt.Errorf("Connect error: %w", err)

internal/integration/client_side_encryption_prose_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,7 @@ type cseProseTest struct {
30093009
cseStarted []*event.CommandStartedEvent
30103010
}
30113011

3012-
func setup(mt *mtest.T, aeo *options.AutoEncryptionOptionsBuilder, kvClientOpts options.Lister[options.ClientOptions],
3012+
func setup(mt *mtest.T, aeo *options.AutoEncryptionOptionsBuilder, kvClientOpts *options.ClientOptions,
30133013
ceo options.Lister[options.ClientEncryptionOptions]) *cseProseTest {
30143014
mt.Helper()
30153015
var cpt cseProseTest
@@ -3088,7 +3088,7 @@ func rawValueToCoreValue(rv bson.RawValue) bsoncore.Value {
30883088

30893089
type deadlockTest struct {
30903090
clientTest *mongo.Client
3091-
clientKeyVaultOpts *options.ClientOptionsBuilder
3091+
clientKeyVaultOpts *options.ClientOptions
30923092
clientKeyVaultEvents []startedEvent
30933093
clientEncryption *mongo.ClientEncryption
30943094
ciphertext bson.Binary

internal/integration/client_side_encryption_test.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright (C) MongoDB, Inc. 2021-present.
21
//
2+
// Copyright (C) MongoDB, Inc. 2021-present.
33
// Licensed under the Apache License, Version 2.0 (the "License"); you may
44
// not use this file except in compliance with the License. You may obtain
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -356,11 +356,7 @@ func TestClientSideEncryptionCustomCrypt(t *testing.T) {
356356
ApplyURI(mtest.ClusterURI()).
357357
SetAutoEncryptionOptions(aeOpts)
358358
cc := &customCrypt{}
359-
clientOpts.Opts = append(clientOpts.Opts, func(args *options.ClientOptions) error {
360-
args.Crypt = cc
361-
362-
return nil
363-
})
359+
clientOpts.Crypt = cc
364360
integtest.AddTestServerAPIVersion(clientOpts)
365361

366362
client, err := mongo.Connect(clientOpts)
@@ -683,11 +679,7 @@ func TestFLEIndexView(t *testing.T) {
683679
SetReadPreference(mtest.PrimaryRp)
684680

685681
cc := &customCrypt{}
686-
opts.Opts = append(opts.Opts, func(args *options.ClientOptions) error {
687-
args.Crypt = cc
688-
689-
return nil
690-
})
682+
opts.Crypt = cc
691683

692684
integtest.AddTestServerAPIVersion(opts)
693685

internal/integration/data_lake_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestAtlasDataLake(t *testing.T) {
9797
})
9898
}
9999

100-
func getBaseClientOptions(mt *mtest.T) *options.ClientOptionsBuilder {
100+
func getBaseClientOptions(mt *mtest.T) *options.ClientOptions {
101101
mt.Helper()
102102

103103
hosts, err := mongoutil.HostsFromURI(mtest.ClusterURI())

internal/integration/handshake_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestHandshakeProse(t *testing.T) {
9191
for _, test := range []struct {
9292
name string
9393
env map[string]string
94-
opts *options.ClientOptionsBuilder
94+
opts *options.ClientOptions
9595
want bson.D
9696
}{
9797
{

internal/integration/initial_dns_seedlist_discovery_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func runSeedlistDiscoveryDirectory(mt *mtest.T, subdirectory string) {
7474
}
7575

7676
// runSeedlistDiscoveryPingTest will create a new connection using the test URI and attempt to "ping" the server.
77-
func runSeedlistDiscoveryPingTest(mt *mtest.T, clientOpts *options.ClientOptionsBuilder) {
77+
func runSeedlistDiscoveryPingTest(mt *mtest.T, clientOpts *options.ClientOptions) {
7878
ctx := context.Background()
7979

8080
client, err := mongo.Connect(clientOpts)

internal/integration/json_helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func jsonFilesInDir(t testing.TB, dir string) []string {
6767
}
6868

6969
// create client options from a map
70-
func createClientOptions(t testing.TB, opts bson.Raw) *options.ClientOptionsBuilder {
70+
func createClientOptions(t testing.TB, opts bson.Raw) *options.ClientOptions {
7171
t.Helper()
7272

7373
clientOpts := options.Client()

internal/integration/mtest/mongotest.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ type T struct {
8181

8282
// options copied to sub-tests
8383
clientType ClientType
84-
clientOpts *options.ClientOptionsBuilder
84+
clientOpts *options.ClientOptions
8585
collOpts *options.CollectionOptionsBuilder
8686
shareClient *bool
8787

@@ -359,7 +359,7 @@ func (t *T) ClearEvents() {
359359
// If t.Coll is not-nil, it will be reset to use the new client. Should only be called if the existing client is
360360
// not nil. This will Disconnect the existing client but will not drop existing collections. To do so, ClearCollections
361361
// must be called before calling ResetClient.
362-
func (t *T) ResetClient(opts *options.ClientOptionsBuilder) {
362+
func (t *T) ResetClient(opts *options.ClientOptions) {
363363
if opts != nil {
364364
t.clientOpts = opts
365365
}
@@ -592,18 +592,13 @@ func (t *T) createTestClient() {
592592
clientOpts = options.Client().SetWriteConcern(MajorityWc).SetReadPreference(PrimaryRp)
593593
}
594594

595-
args, err := mongoutil.NewOptions[options.ClientOptions](clientOpts)
596-
if err != nil {
597-
t.Fatalf("failed to construct options from builder: %v", err)
598-
}
599-
600595
// set ServerAPIOptions to latest version if required
601-
if args.Deployment == nil && t.clientType != Mock && args.ServerAPIOptions == nil && testContext.requireAPIVersion {
596+
if clientOpts.Deployment == nil && t.clientType != Mock && clientOpts.ServerAPIOptions == nil && testContext.requireAPIVersion {
602597
clientOpts.SetServerAPIOptions(options.ServerAPI(driver.TestServerAPIVersion))
603598
}
604599

605600
// Setup command monitor
606-
var customMonitor = args.Monitor
601+
var customMonitor = clientOpts.Monitor
607602
clientOpts.SetMonitor(&event.CommandMonitor{
608603
Started: func(ctx context.Context, cse *event.CommandStartedEvent) {
609604
if customMonitor != nil && customMonitor.Started != nil {
@@ -631,8 +626,8 @@ func (t *T) createTestClient() {
631626
},
632627
})
633628
// only specify connection pool monitor if no deployment is given
634-
if args.Deployment == nil {
635-
previousPoolMonitor := args.PoolMonitor
629+
if clientOpts.Deployment == nil {
630+
previousPoolMonitor := clientOpts.PoolMonitor
636631

637632
clientOpts.SetPoolMonitor(&event.PoolMonitor{
638633
Event: func(evt *event.PoolEvent) {
@@ -650,6 +645,7 @@ func (t *T) createTestClient() {
650645
})
651646
}
652647

648+
var err error
653649
switch t.clientType {
654650
case Pinned:
655651
// pin to first mongos
@@ -658,15 +654,13 @@ func (t *T) createTestClient() {
658654
t.Client, err = mongo.Connect(uriOpts, clientOpts)
659655
case Mock:
660656
// clear pool monitor to avoid configuration error
661-
args, _ = mongoutil.NewOptions[options.ClientOptions](clientOpts)
662657

663-
args.PoolMonitor = nil
658+
clientOpts.PoolMonitor = nil
664659

665660
t.mockDeployment = drivertest.NewMockDeployment()
666-
args.Deployment = t.mockDeployment
661+
clientOpts.Deployment = t.mockDeployment
667662

668-
opts := mongoutil.NewOptionsLister(args, nil)
669-
t.Client, err = mongo.Connect(opts)
663+
t.Client, err = mongo.Connect(clientOpts)
670664
case Proxy:
671665
t.proxyDialer = newProxyDialer()
672666
clientOpts.SetDialer(t.proxyDialer)
@@ -676,8 +670,8 @@ func (t *T) createTestClient() {
676670
case Default:
677671
// Use a different set of options to specify the URI because clientOpts may already have a URI or host seedlist
678672
// specified.
679-
var uriOpts *options.ClientOptionsBuilder
680-
if args.Deployment == nil {
673+
var uriOpts *options.ClientOptions
674+
if clientOpts.Deployment == nil {
681675
// Only specify URI if the deployment is not set to avoid setting topology/server options along with the
682676
// deployment.
683677
uriOpts = options.Client().ApplyURI(testContext.connString.Original)

internal/integration/mtest/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (op *Options) CollectionOptions(opts *options.CollectionOptionsBuilder) *Op
134134
}
135135

136136
// ClientOptions sets the options to use when creating a client for a test.
137-
func (op *Options) ClientOptions(opts *options.ClientOptionsBuilder) *Options {
137+
func (op *Options) ClientOptions(opts *options.ClientOptions) *Options {
138138
op.optFuncs = append(op.optFuncs, func(t *T) {
139139
t.clientOpts = opts
140140
})

internal/integration/mtest/setup.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818

1919
"go.mongodb.org/mongo-driver/v2/bson"
2020
"go.mongodb.org/mongo-driver/v2/internal/integtest"
21-
"go.mongodb.org/mongo-driver/v2/internal/mongoutil"
2221
"go.mongodb.org/mongo-driver/v2/mongo"
2322
"go.mongodb.org/mongo-driver/v2/mongo/options"
2423
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
@@ -58,20 +57,15 @@ var testContext struct {
5857
serverless bool
5958
}
6059

61-
func setupClient(opts *options.ClientOptionsBuilder) (*mongo.Client, error) {
62-
args, err := mongoutil.NewOptions[options.ClientOptions](opts)
63-
if err != nil {
64-
return nil, fmt.Errorf("failed to construct options from builder: %w", err)
65-
}
66-
60+
func setupClient(opts *options.ClientOptions) (*mongo.Client, error) {
6761
wcMajority := writeconcern.Majority()
6862
// set ServerAPIOptions to latest version if required
69-
if args.ServerAPIOptions == nil && testContext.requireAPIVersion {
63+
if opts.ServerAPIOptions == nil && testContext.requireAPIVersion {
7064
opts.SetServerAPIOptions(options.ServerAPI(driver.TestServerAPIVersion))
7165
}
7266
// for sharded clusters, pin to one host. Due to how the cache is implemented on 4.0 and 4.2, behavior
7367
// can be inconsistent when multiple mongoses are used
74-
return mongo.Connect(opts.SetWriteConcern(wcMajority).SetHosts(args.Hosts[:1]))
68+
return mongo.Connect(opts.SetWriteConcern(wcMajority).SetHosts(opts.Hosts[:1]))
7569
}
7670

7771
// Setup initializes the current testing context.

0 commit comments

Comments
 (0)