Skip to content

Commit

Permalink
GODRIVER-2057 Fix uri merging on options.ClientOptions (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoonmin authored Jun 29, 2021
1 parent fcfd2a3 commit 6d6365b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mongo/options/clientoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,12 @@ func MergeClientOptions(opts ...*ClientOptions) *ClientOptions {
if opt.err != nil {
c.err = opt.err
}

if opt.uri != "" {
c.uri = opt.uri
}
if opt.cs != nil {
c.cs = opt.cs
}
}

return c
Expand Down
10 changes: 10 additions & 0 deletions mongo/options/clientoptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ func TestClientOptions(t *testing.T) {
t.Errorf("Merged client options do not match. got %v; want %v", got.err.Error(), opt1.err.Error())
}
})

t.Run("MergeClientOptions/uri", func(t *testing.T) {
opt1, opt2 := Client(), Client()
opt1.uri = "Test URI"

got := MergeClientOptions(nil, opt1, opt2)
if got.uri != "Test URI" {
t.Errorf("Merged client options do not match. got %v; want %v", got.uri, opt1.uri)
}
})
})
t.Run("ApplyURI", func(t *testing.T) {
baseClient := func() *ClientOptions {
Expand Down

0 comments on commit 6d6365b

Please sign in to comment.