@@ -179,6 +179,94 @@ func TestClient(t *testing.T) {
179
179
client := setupClient (options .Client ().SetReadConcern (rc ))
180
180
assert .Equal (t , rc , client .readConcern , "expected read concern %v, got %v" , rc , client .readConcern )
181
181
})
182
+ t .Run ("min pool size from Set*PoolSize()" , func (t * testing.T ) {
183
+ testCases := []struct {
184
+ name string
185
+ opts * options.ClientOptions
186
+ err error
187
+ }{
188
+ {
189
+ name : "minPoolSize < default maxPoolSize" ,
190
+ opts : options .Client ().SetMinPoolSize (64 ),
191
+ err : nil ,
192
+ },
193
+ {
194
+ name : "minPoolSize > default maxPoolSize" ,
195
+ opts : options .Client ().SetMinPoolSize (128 ),
196
+ err : errors .New ("minPoolSize must be less than or equal to maxPoolSize, got minPoolSize=128 maxPoolSize=100" ),
197
+ },
198
+ {
199
+ name : "minPoolSize < maxPoolSize" ,
200
+ opts : options .Client ().SetMinPoolSize (128 ).SetMaxPoolSize (256 ),
201
+ err : nil ,
202
+ },
203
+ {
204
+ name : "minPoolSize == maxPoolSize" ,
205
+ opts : options .Client ().SetMinPoolSize (128 ).SetMaxPoolSize (128 ),
206
+ err : nil ,
207
+ },
208
+ {
209
+ name : "minPoolSize > maxPoolSize" ,
210
+ opts : options .Client ().SetMinPoolSize (64 ).SetMaxPoolSize (32 ),
211
+ err : errors .New ("minPoolSize must be less than or equal to maxPoolSize, got minPoolSize=64 maxPoolSize=32" ),
212
+ },
213
+ {
214
+ name : "maxPoolSize == 0" ,
215
+ opts : options .Client ().SetMinPoolSize (128 ).SetMaxPoolSize (0 ),
216
+ err : nil ,
217
+ },
218
+ }
219
+ for _ , tc := range testCases {
220
+ t .Run (tc .name , func (t * testing.T ) {
221
+ _ , err := NewClient (tc .opts )
222
+ assert .Equal (t , tc .err , err , "expected error %v, got %v" , tc .err , err )
223
+ })
224
+ }
225
+ })
226
+ t .Run ("min pool size from ApplyURI()" , func (t * testing.T ) {
227
+ testCases := []struct {
228
+ name string
229
+ opts * options.ClientOptions
230
+ err error
231
+ }{
232
+ {
233
+ name : "minPoolSize < default maxPoolSize" ,
234
+ opts : options .Client ().ApplyURI ("mongodb://localhost:27017/?minPoolSize=64" ),
235
+ err : nil ,
236
+ },
237
+ {
238
+ name : "minPoolSize > default maxPoolSize" ,
239
+ opts : options .Client ().ApplyURI ("mongodb://localhost:27017/?minPoolSize=128" ),
240
+ err : errors .New ("minPoolSize must be less than or equal to maxPoolSize, got minPoolSize=128 maxPoolSize=100" ),
241
+ },
242
+ {
243
+ name : "minPoolSize < maxPoolSize" ,
244
+ opts : options .Client ().ApplyURI ("mongodb://localhost:27017/?minPoolSize=128&maxPoolSize=256" ),
245
+ err : nil ,
246
+ },
247
+ {
248
+ name : "minPoolSize == maxPoolSize" ,
249
+ opts : options .Client ().ApplyURI ("mongodb://localhost:27017/?minPoolSize=128&maxPoolSize=128" ),
250
+ err : nil ,
251
+ },
252
+ {
253
+ name : "minPoolSize > maxPoolSize" ,
254
+ opts : options .Client ().ApplyURI ("mongodb://localhost:27017/?minPoolSize=64&maxPoolSize=32" ),
255
+ err : errors .New ("minPoolSize must be less than or equal to maxPoolSize, got minPoolSize=64 maxPoolSize=32" ),
256
+ },
257
+ {
258
+ name : "maxPoolSize == 0" ,
259
+ opts : options .Client ().ApplyURI ("mongodb://localhost:27017/?minPoolSize=128&maxPoolSize=0" ),
260
+ err : nil ,
261
+ },
262
+ }
263
+ for _ , tc := range testCases {
264
+ t .Run (tc .name , func (t * testing.T ) {
265
+ _ , err := NewClient (tc .opts )
266
+ assert .Equal (t , tc .err , err , "expected error %v, got %v" , tc .err , err )
267
+ })
268
+ }
269
+ })
182
270
t .Run ("retry writes" , func (t * testing.T ) {
183
271
retryWritesURI := "mongodb://localhost:27017/?retryWrites=false"
184
272
retryWritesErrorURI := "mongodb://localhost:27017/?retryWrites=foobar"
0 commit comments