Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-3452 MergeClientOptions returns object when given nil arguments #1917

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading