@@ -9,6 +9,7 @@ package topology
9
9
import (
10
10
"context"
11
11
"errors"
12
+ "fmt"
12
13
"sync/atomic"
13
14
"testing"
14
15
"time"
@@ -84,6 +85,54 @@ func TestServerSelection(t *testing.T) {
84
85
t .Errorf ("Incorrect sever selected. got %s; want %s" , srvs [0 ].Addr , desc .Servers [0 ].Addr )
85
86
}
86
87
})
88
+ t .Run ("Compatibility Error Min Version Too High" , func (t * testing.T ) {
89
+ topo , err := New ()
90
+ noerr (t , err )
91
+ desc := description.Topology {
92
+ Kind : description .Single ,
93
+ Servers : []description.Server {
94
+ {Addr : address .Address ("one:27017" ), Kind : description .Standalone , WireVersion : & description.VersionRange {Max : 11 , Min : 11 }},
95
+ {Addr : address .Address ("two:27017" ), Kind : description .Standalone , WireVersion : & description.VersionRange {Max : 9 , Min : 2 }},
96
+ {Addr : address .Address ("three:27017" ), Kind : description .Standalone , WireVersion : & description.VersionRange {Max : 9 , Min : 2 }},
97
+ },
98
+ }
99
+ want := fmt .Errorf (
100
+ "server at %s requires wire version %d, but this version of the Go driver only supports up to %d" ,
101
+ desc .Servers [0 ].Addr .String (),
102
+ desc .Servers [0 ].WireVersion .Min ,
103
+ supportedWireVersions .Max ,
104
+ )
105
+ desc .CompatibilityErr = want
106
+ atomic .StoreInt32 (& topo .connectionstate , connected )
107
+ topo .desc .Store (desc )
108
+ _ , err = topo .SelectServer (context .Background (), selectFirst )
109
+ assert .Equal (t , err , want , "expected %v, got %v" , want , err )
110
+ })
111
+ t .Run ("Compatibility Error Max Version Too Low" , func (t * testing.T ) {
112
+ topo , err := New ()
113
+ noerr (t , err )
114
+ desc := description.Topology {
115
+ Kind : description .Single ,
116
+ Servers : []description.Server {
117
+ {Addr : address .Address ("one:27017" ), Kind : description .Standalone , WireVersion : & description.VersionRange {Max : 1 , Min : 1 }},
118
+ {Addr : address .Address ("two:27017" ), Kind : description .Standalone , WireVersion : & description.VersionRange {Max : 9 , Min : 2 }},
119
+ {Addr : address .Address ("three:27017" ), Kind : description .Standalone , WireVersion : & description.VersionRange {Max : 9 , Min : 2 }},
120
+ },
121
+ }
122
+ want := fmt .Errorf (
123
+ "server at %s reports wire version %d, but this version of the Go driver requires " +
124
+ "at least %d (MongoDB %s)" ,
125
+ desc .Servers [0 ].Addr .String (),
126
+ desc .Servers [0 ].WireVersion .Max ,
127
+ supportedWireVersions .Min ,
128
+ minSupportedMongoDBVersion ,
129
+ )
130
+ desc .CompatibilityErr = want
131
+ atomic .StoreInt32 (& topo .connectionstate , connected )
132
+ topo .desc .Store (desc )
133
+ _ , err = topo .SelectServer (context .Background (), selectFirst )
134
+ assert .Equal (t , err , want , "expected %v, got %v" , want , err )
135
+ })
87
136
t .Run ("Updated" , func (t * testing.T ) {
88
137
topo , err := New ()
89
138
noerr (t , err )
0 commit comments