@@ -146,6 +146,35 @@ func TestClientOptions(t *testing.T) {
146146 }
147147 })
148148 }
149+
150+ t .Run ("MergeClientOptions/all set" , func (t * testing.T ) {
151+ want := optResult
152+ got := MergeClientOptions (nil , opt1 , opt2 )
153+ if diff := cmp .Diff (
154+ got , want ,
155+ cmp .AllowUnexported (readconcern.ReadConcern {}, writeconcern.WriteConcern {}, readpref.ReadPref {}),
156+ cmp .Comparer (func (r1 , r2 * bson.Registry ) bool { return r1 == r2 }),
157+ cmp .Comparer (func (cfg1 , cfg2 * tls.Config ) bool { return cfg1 == cfg2 }),
158+ cmp .Comparer (func (fp1 , fp2 * event.PoolMonitor ) bool { return fp1 == fp2 }),
159+ cmp .AllowUnexported (ClientOptions {}),
160+ cmpopts .IgnoreFields (http.Client {}, "Transport" ),
161+ ); diff != "" {
162+ t .Errorf ("diff:\n %s" , diff )
163+ t .Errorf ("Merged client options do not match. got %v; want %v" , got , want )
164+ }
165+ })
166+
167+ // go-cmp dont support error comparisons (https://github.com/google/go-cmp/issues/24)
168+ // Use specifique test for this
169+ t .Run ("MergeClientOptions/err" , func (t * testing.T ) {
170+ opt1 , opt2 := Client (), Client ()
171+ opt1 .err = errors .New ("Test error" )
172+
173+ got := MergeClientOptions (nil , opt1 , opt2 )
174+ if got .err .Error () != "Test error" {
175+ t .Errorf ("Merged client options do not match. got %v; want %v" , got .err .Error (), opt1 .err .Error ())
176+ }
177+ })
149178 })
150179 t .Run ("direct connection validation" , func (t * testing.T ) {
151180 t .Run ("multiple hosts" , func (t * testing.T ) {
0 commit comments