Skip to content

Commit 6d6365b

Browse files
authored
GODRIVER-2057 Fix uri merging on options.ClientOptions (#689)
1 parent fcfd2a3 commit 6d6365b

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
@@ -873,7 +873,12 @@ func MergeClientOptions(opts ...*ClientOptions) *ClientOptions {
873873
if opt.err != nil {
874874
c.err = opt.err
875875
}
876-
876+
if opt.uri != "" {
877+
c.uri = opt.uri
878+
}
879+
if opt.cs != nil {
880+
c.cs = opt.cs
881+
}
877882
}
878883

879884
return c

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/uri", func(t *testing.T) {
180+
opt1, opt2 := Client(), Client()
181+
opt1.uri = "Test URI"
182+
183+
got := MergeClientOptions(nil, opt1, opt2)
184+
if got.uri != "Test URI" {
185+
t.Errorf("Merged client options do not match. got %v; want %v", got.uri, opt1.uri)
186+
}
187+
})
178188
})
179189
t.Run("ApplyURI", func(t *testing.T) {
180190
baseClient := func() *ClientOptions {

0 commit comments

Comments
 (0)