Skip to content

Commit

Permalink
GODRIVER-3452 MergeClientOptions returns object when given nil argume…
Browse files Browse the repository at this point in the history
…nts (#1917)
  • Loading branch information
prestonvasquez authored Jan 15, 2025
1 parent 91e55bd commit ab61be4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mongo/options/clientoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,10 @@ func extractX509UsernameFromSubject(subject string) string {
// precedence.
func MergeClientOptions(opts ...*ClientOptions) *ClientOptions {
if len(opts) == 1 {
if opts[0] == nil {
return Client()
}

return opts[0]
}

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 single nil option", func(t *testing.T) {
got := MergeClientOptions(nil)
assert.Equal(t, Client(), got)
})

t.Run("MergeClientOptions multiple nil options", func(t *testing.T) {
got := MergeClientOptions(nil, nil)
assert.Equal(t, Client(), got)
})
})
t.Run("direct connection validation", func(t *testing.T) {
t.Run("multiple hosts", func(t *testing.T) {
Expand Down

0 comments on commit ab61be4

Please sign in to comment.