@@ -270,14 +270,20 @@ func checkExpectations(mt *mtest.T, expectations *[]*expectation, id0, id1 bson.
270
270
return
271
271
}
272
272
273
- startedEvents := make ([]* cmdStartedEvt , len (* expectations ))
274
- succeededEvents := make ([]* cmdSucceededEvt , len (* expectations ))
275
- failedEvents := make ([]* cmdFailedEvt , len (* expectations ))
276
-
277
- for idx , expectation := range * expectations {
278
- startedEvents [idx ] = expectation .CommandStartedEvent
279
- succeededEvents [idx ] = expectation .CommandSucceededEvent
280
- failedEvents [idx ] = expectation .CommandFailedEvent
273
+ startedEvents := make ([]* cmdStartedEvt , 0 , len (* expectations ))
274
+ succeededEvents := make ([]* cmdSucceededEvt , 0 , len (* expectations ))
275
+ failedEvents := make ([]* cmdFailedEvt , 0 , len (* expectations ))
276
+
277
+ for _ , expectation := range * expectations {
278
+ if expectation .CommandStartedEvent != nil {
279
+ startedEvents = append (startedEvents , expectation .CommandStartedEvent )
280
+ }
281
+ if expectation .CommandSucceededEvent != nil {
282
+ succeededEvents = append (succeededEvents , expectation .CommandSucceededEvent )
283
+ }
284
+ if expectation .CommandFailedEvent != nil {
285
+ failedEvents = append (failedEvents , expectation .CommandFailedEvent )
286
+ }
281
287
}
282
288
283
289
var err error
@@ -310,9 +316,6 @@ func compareStartedEvents(mt *mtest.T, expectations []*cmdStartedEvt, id0, id1 b
310
316
}
311
317
312
318
compare := func (expected * cmdStartedEvt ) error {
313
- if expected == nil {
314
- return nil
315
- }
316
319
if len (expected .Extra ) > 0 {
317
320
return fmt .Errorf ("unrecognized fields for CommandStartedEvent: %v" , expected .Extra )
318
321
}
@@ -450,9 +453,6 @@ func compareSucceededEvents(mt *mtest.T, expectations []*cmdSucceededEvt) error
450
453
}
451
454
452
455
compare := func (expected * cmdSucceededEvt ) error {
453
- if expected == nil {
454
- return nil
455
- }
456
456
if len (expected .Extra ) > 0 {
457
457
return fmt .Errorf ("unrecognized fields for CommandSucceededEvent: %v" , expected .Extra )
458
458
}
@@ -514,9 +514,6 @@ func compareFailedEvents(mt *mtest.T, expectations []*cmdFailedEvt) error {
514
514
}
515
515
516
516
compare := func (expected * cmdFailedEvt ) error {
517
- if expected == nil {
518
- return nil
519
- }
520
517
if len (expected .Extra ) > 0 {
521
518
return fmt .Errorf ("unrecognized fields for CommandFailedEvent: %v" , expected .Extra )
522
519
}
0 commit comments