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