Skip to content

Commit 71e025b

Browse files
GODRIVER-3452 MergeClientOptions returns object when given nil arguments (#1917) [release/2.0] (#1948)
Co-authored-by: Preston Vasquez <[email protected]>
1 parent 3dcf4f8 commit 71e025b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mongo/options/clientoptions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,10 @@ func extractX509UsernameFromSubject(subject string) string {
12651265
// precedence.
12661266
func MergeClientOptions(opts ...*ClientOptions) *ClientOptions {
12671267
if len(opts) == 1 {
1268+
if opts[0] == nil {
1269+
return Client()
1270+
}
1271+
12681272
return opts[0]
12691273
}
12701274

mongo/options/clientoptions_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ func TestClientOptions(t *testing.T) {
175175
t.Errorf("Merged client options do not match. got %v; want %v", got.err.Error(), opt1.err.Error())
176176
}
177177
})
178+
179+
t.Run("MergeClientOptions single nil option", func(t *testing.T) {
180+
got := MergeClientOptions(nil)
181+
assert.Equal(t, Client(), got)
182+
})
183+
184+
t.Run("MergeClientOptions multiple nil options", func(t *testing.T) {
185+
got := MergeClientOptions(nil, nil)
186+
assert.Equal(t, Client(), got)
187+
})
178188
})
179189
t.Run("direct connection validation", func(t *testing.T) {
180190
t.Run("multiple hosts", func(t *testing.T) {

0 commit comments

Comments
 (0)