Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.NotNil(t, got)
})

t.Run("MergeClientOptions multiple nil options", func(t *testing.T) {
got := MergeClientOptions(nil, nil)
assert.NotNil(t, got)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we assert the initialization of got for better coverage instead of merely a NotNil?

})
t.Run("direct connection validation", func(t *testing.T) {
t.Run("multiple hosts", func(t *testing.T) {
Expand Down
Loading