@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/google/go-cmp/cmp"
14
14
"github.com/stretchr/testify/require"
15
+ "go.mongodb.org/mongo-driver/internal/testutil/assert"
15
16
"go.mongodb.org/mongo-driver/mongo/readpref"
16
17
"go.mongodb.org/mongo-driver/tag"
17
18
"go.mongodb.org/mongo-driver/x/mongo/driver/address"
@@ -506,6 +507,43 @@ func TestSelector_Secondary_with_tags(t *testing.T) {
506
507
require .Equal ([]Server {readPrefTestSecondary2 }, result )
507
508
}
508
509
510
+ func TestSelector_Secondary_with_empty_tag_set (t * testing.T ) {
511
+ t .Parallel ()
512
+
513
+ primaryNoTags := Server {
514
+ Addr : address .Address ("localhost:27017" ),
515
+ Kind : RSPrimary ,
516
+ WireVersion : & VersionRange {Min : 0 , Max : 5 },
517
+ }
518
+ firstSecondaryNoTags := Server {
519
+ Addr : address .Address ("localhost:27018" ),
520
+ Kind : RSSecondary ,
521
+ WireVersion : & VersionRange {Min : 0 , Max : 5 },
522
+ }
523
+ secondSecondaryNoTags := Server {
524
+ Addr : address .Address ("localhost:27019" ),
525
+ Kind : RSSecondary ,
526
+ WireVersion : & VersionRange {Min : 0 , Max : 5 },
527
+ }
528
+ topologyNoTags := Topology {
529
+ Kind : ReplicaSetWithPrimary ,
530
+ Servers : []Server {primaryNoTags , firstSecondaryNoTags , secondSecondaryNoTags },
531
+ }
532
+
533
+ nonMatchingSet := tag.Set {
534
+ {Name : "foo" , Value : "bar" },
535
+ }
536
+ emptyTagSet := tag.Set {}
537
+ rp := readpref .Secondary (
538
+ readpref .WithTagSets (nonMatchingSet , emptyTagSet ),
539
+ )
540
+
541
+ result , err := ReadPrefSelector (rp ).SelectServer (topologyNoTags , topologyNoTags .Servers )
542
+ assert .Nil (t , err , "SelectServer error: %v" , err )
543
+ expectedResult := []Server {firstSecondaryNoTags , secondSecondaryNoTags }
544
+ assert .Equal (t , expectedResult , result , "expected result %v, got %v" , expectedResult , result )
545
+ }
546
+
509
547
func TestSelector_Secondary_with_tags_that_do_not_match (t * testing.T ) {
510
548
t .Parallel ()
511
549
0 commit comments