@@ -220,6 +220,24 @@ func TestIndexView(t *testing.T) {
220
220
})
221
221
}
222
222
})
223
+ // Needs to run on these versions for failpoints
224
+ mt .RunOpts ("replace error" , mtest .NewOptions ().Topologies (mtest .ReplicaSet ).MinServerVersion ("4.0" ), func (mt * mtest.T ) {
225
+ mt .SetFailPoint (mtest.FailPoint {
226
+ ConfigureFailPoint : "failCommand" ,
227
+ Mode : "alwaysOn" ,
228
+ Data : mtest.FailPointData {
229
+ FailCommands : []string {"createIndexes" },
230
+ ErrorCode : 100 ,
231
+ },
232
+ })
233
+
234
+ _ , err := mt .Coll .Indexes ().CreateOne (mtest .Background , mongo.IndexModel {Keys : bson.D {{"x" , 1 }}})
235
+ assert .NotNil (mt , err , "expected CreateOne error, got nil" )
236
+ cmdErr , ok := err .(mongo.CommandError )
237
+ assert .True (mt , ok , "expected mongo.CommandError, got %T" , err )
238
+ assert .Equal (mt , int32 (100 ), cmdErr .Code , "expected error code 100, got %v" , cmdErr .Code )
239
+
240
+ })
223
241
})
224
242
mt .Run ("create many" , func (mt * mtest.T ) {
225
243
mt .Run ("success" , func (mt * mtest.T ) {
@@ -279,9 +297,12 @@ func TestIndexView(t *testing.T) {
279
297
majority := options .CreateIndexes ().SetCommitQuorumMajority ()
280
298
votingMembers := options .CreateIndexes ().SetCommitQuorumVotingMembers ()
281
299
282
- indexModel := mongo.IndexModel {
300
+ indexModel1 := mongo.IndexModel {
283
301
Keys : bson.D {{"x" , 1 }},
284
302
}
303
+ indexModel2 := mongo.IndexModel {
304
+ Keys : bson.D {{"y" , 1 }},
305
+ }
285
306
286
307
testCases := []struct {
287
308
name string
@@ -301,13 +322,13 @@ func TestIndexView(t *testing.T) {
301
322
mtOpts := mtest .NewOptions ().MinServerVersion (tc .minServerVersion ).MaxServerVersion (tc .maxServerVersion )
302
323
mt .RunOpts (tc .name , mtOpts , func (mt * mtest.T ) {
303
324
mt .ClearEvents ()
304
- _ , err := mt .Coll .Indexes ().CreateOne (mtest .Background , indexModel , tc .opts )
325
+ _ , err := mt .Coll .Indexes ().CreateMany (mtest .Background , []mongo. IndexModel { indexModel1 , indexModel2 } , tc .opts )
305
326
if tc .expectError {
306
- assert .NotNil (mt , err , "expected CreateOne error, got nil" )
327
+ assert .NotNil (mt , err , "expected CreateMany error, got nil" )
307
328
return
308
329
}
309
330
310
- assert .Nil (mt , err , "CreateOne error: %v" , err )
331
+ assert .Nil (mt , err , "CreateMany error: %v" , err )
311
332
cmd := mt .GetStartedEvent ().Command
312
333
sentBSONValue , err := cmd .LookupErr ("commitQuorum" )
313
334
assert .Nil (mt , err , "expected commitQuorum in command %s" , cmd )
@@ -321,6 +342,31 @@ func TestIndexView(t *testing.T) {
321
342
})
322
343
}
323
344
})
345
+ // Needs to run on these versions for failpoints
346
+ mt .RunOpts ("replace error" , mtest .NewOptions ().Topologies (mtest .ReplicaSet ).MinServerVersion ("4.0" ), func (mt * mtest.T ) {
347
+ mt .SetFailPoint (mtest.FailPoint {
348
+ ConfigureFailPoint : "failCommand" ,
349
+ Mode : "alwaysOn" ,
350
+ Data : mtest.FailPointData {
351
+ FailCommands : []string {"createIndexes" },
352
+ ErrorCode : 100 ,
353
+ },
354
+ })
355
+
356
+ _ , err := mt .Coll .Indexes ().CreateMany (mtest .Background , []mongo.IndexModel {
357
+ {
358
+ Keys : bson.D {{"foo" , int32 (- 1 )}},
359
+ },
360
+ {
361
+ Keys : bson.D {{"bar" , int32 (1 )}, {"baz" , int32 (- 1 )}},
362
+ },
363
+ })
364
+ assert .NotNil (mt , err , "expected CreateMany error, got nil" )
365
+ cmdErr , ok := err .(mongo.CommandError )
366
+ assert .True (mt , ok , "expected mongo.CommandError, got %T" , err )
367
+ assert .Equal (mt , int32 (100 ), cmdErr .Code , "expected error code 100, got %v" , cmdErr .Code )
368
+
369
+ })
324
370
})
325
371
mt .RunOpts ("list specifications" , noClientOpts , func (mt * mtest.T ) {
326
372
mt .Run ("verify results" , func (mt * mtest.T ) {
0 commit comments