Skip to content

Commit be28a1c

Browse files
hoonminiwysiu
authored andcommitted
GODRIVER-2057 Fix uri merging on options.ClientOptions (#689)
1 parent e0ed5a0 commit be28a1c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

mongo/options/clientoptions.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,12 @@ func MergeClientOptions(opts ...*ClientOptions) *ClientOptions {
819819
if opt.err != nil {
820820
c.err = opt.err
821821
}
822-
822+
if opt.uri != "" {
823+
c.uri = opt.uri
824+
}
825+
if opt.cs != nil {
826+
c.cs = opt.cs
827+
}
823828
}
824829

825830
return c

mongo/options/clientoptions_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ func TestClientOptions(t *testing.T) {
174174
t.Errorf("Merged client options do not match. got %v; want %v", got.err.Error(), opt1.err.Error())
175175
}
176176
})
177+
178+
t.Run("MergeClientOptions/uri", func(t *testing.T) {
179+
opt1, opt2 := Client(), Client()
180+
opt1.uri = "Test URI"
181+
182+
got := MergeClientOptions(nil, opt1, opt2)
183+
if got.uri != "Test URI" {
184+
t.Errorf("Merged client options do not match. got %v; want %v", got.uri, opt1.uri)
185+
}
186+
})
177187
})
178188
t.Run("ApplyURI", func(t *testing.T) {
179189
baseClient := func() *ClientOptions {

0 commit comments

Comments
 (0)