Skip to content

Commit 3150543

Browse files
Mathieuskriptble
authored andcommitted
GODRIVER-908 Fix err merging on options.ClientOptions
1 parent 7951779 commit 3150543

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

mongo/client.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ func Connect(ctx context.Context, opts ...*options.ClientOptions) (*Client, erro
7676
func NewClient(opts ...*options.ClientOptions) (*Client, error) {
7777
clientOpt := options.MergeClientOptions(opts...)
7878

79-
err := clientOpt.Validate()
80-
if err != nil {
81-
return nil, err
82-
}
83-
8479
id, err := uuid.New()
8580
if err != nil {
8681
return nil, err

mongo/options/clientoptions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ func MergeClientOptions(opts ...*ClientOptions) *ClientOptions {
505505
if opt.ZlibLevel != nil {
506506
c.ZlibLevel = opt.ZlibLevel
507507
}
508+
if opt.err != nil {
509+
c.err = opt.err
510+
}
508511
}
509512

510513
return c

mongo/options/clientoptions_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ func TestClientOptions(t *testing.T) {
151151
t.Errorf("Merged client options do not match. got %v; want %v", got, want)
152152
}
153153
})
154+
155+
// go-cmp dont support error comparisons (https://github.com/google/go-cmp/issues/24)
156+
// Use specifique test for this
157+
t.Run("MergeClientOptions/err", func(t *testing.T) {
158+
opt1, opt2 := Client(), Client()
159+
opt1.err = errors.New("Test error")
160+
161+
got := MergeClientOptions(nil, opt1, opt2)
162+
if got.err.Error() != "Test error" {
163+
t.Errorf("Merged client options do not match. got %v; want %v", got.err.Error(), opt1.err.Error())
164+
}
165+
})
154166
})
155167
t.Run("ApplyURI", func(t *testing.T) {
156168
baseClient := func() *ClientOptions {

0 commit comments

Comments
 (0)