@@ -12,6 +12,7 @@ import (
1212
1313 "github.com/google/go-cmp/cmp"
1414 "github.com/stretchr/testify/require"
15+ "go.mongodb.org/mongo-driver/internal/testutil/assert"
1516 "go.mongodb.org/mongo-driver/mongo/readpref"
1617 "go.mongodb.org/mongo-driver/tag"
1718 "go.mongodb.org/mongo-driver/x/mongo/driver/address"
@@ -506,6 +507,43 @@ func TestSelector_Secondary_with_tags(t *testing.T) {
506507 require .Equal ([]Server {readPrefTestSecondary2 }, result )
507508}
508509
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+
509547func TestSelector_Secondary_with_tags_that_do_not_match (t * testing.T ) {
510548 t .Parallel ()
511549
0 commit comments