@@ -321,19 +321,21 @@ func compareStartedEvents(mt *mtest.T, expectations []*cmdStartedEvt, id0, id1 b
321
321
}
322
322
323
323
var evt * event.CommandStartedEvent
324
- // skip events not in expectations
325
- for {
326
- evt = mt .GetStartedEvent ()
327
- if evt == nil {
328
- return errors .New ("expected CommandStartedEvent, got nil" )
329
- }
330
- if v , ok := expectedCmds [evt .CommandName ]; ok && v {
331
- break
324
+ if expected .CommandName != "" {
325
+ // skip events not in expectations
326
+ for {
327
+ evt = mt .GetStartedEvent ()
328
+ if evt == nil {
329
+ return fmt .Errorf ("expected CommandStartedEvent %s, got nil" , expected .CommandName )
330
+ }
331
+ if v , ok := expectedCmds [evt .CommandName ]; ok && v {
332
+ break
333
+ }
332
334
}
333
- }
334
335
335
- if expected .CommandName != "" && expected .CommandName != evt .CommandName {
336
- return fmt .Errorf ("command name mismatch for started event; expected %s, got %s" , expected .CommandName , evt .CommandName )
336
+ if expected .CommandName != evt .CommandName {
337
+ return fmt .Errorf ("command name mismatch for started event; expected %s, got %s" , expected .CommandName , evt .CommandName )
338
+ }
337
339
}
338
340
if expected .DatabaseName != "" && expected .DatabaseName != evt .DatabaseName {
339
341
return fmt .Errorf ("database name mismatch; expected %s, got %s" , expected .DatabaseName , evt .DatabaseName )
@@ -458,19 +460,21 @@ func compareSucceededEvents(mt *mtest.T, expectations []*cmdSucceededEvt) error
458
460
}
459
461
460
462
var evt * event.CommandSucceededEvent
461
- // skip events not in expectations
462
- for {
463
- evt = mt .GetSucceededEvent ()
464
- if evt == nil {
465
- return errors .New ("expected CommandSucceededEvent, got nil" )
466
- }
467
- if v , ok := expectedCmds [evt .CommandName ]; ok && v {
468
- break
463
+ if expected .CommandName != "" {
464
+ // skip events not in expectations
465
+ for expected .CommandName != "" {
466
+ evt = mt .GetSucceededEvent ()
467
+ if evt == nil {
468
+ return fmt .Errorf ("expected CommandSucceededEvent %s, got nil" , expected .CommandName )
469
+ }
470
+ if v , ok := expectedCmds [evt .CommandName ]; ok && v {
471
+ break
472
+ }
469
473
}
470
- }
471
474
472
- if expected .CommandName != "" && expected .CommandName != evt .CommandName {
473
- return fmt .Errorf ("command name mismatch for succeeded event; expected %s, got %s" , expected .CommandName , evt .CommandName )
475
+ if expected .CommandName != evt .CommandName {
476
+ return fmt .Errorf ("command name mismatch for succeeded event; expected %s, got %s" , expected .CommandName , evt .CommandName )
477
+ }
474
478
}
475
479
476
480
eElems , err := expected .Reply .Elements ()
@@ -519,19 +523,21 @@ func compareFailedEvents(mt *mtest.T, expectations []*cmdFailedEvt) error {
519
523
}
520
524
521
525
var evt * event.CommandFailedEvent
522
- // skip events not in expectations
523
- for {
524
- evt = mt .GetFailedEvent ()
525
- if evt == nil {
526
- return errors .New ("expected CommandFailedEvent, got nil" )
527
- }
528
- if v , ok := expectedCmds [evt .CommandName ]; ok && v {
529
- break
526
+ if expected .CommandName != "" {
527
+ // skip events not in expectations
528
+ for expected .CommandName != "" {
529
+ evt = mt .GetFailedEvent ()
530
+ if evt == nil {
531
+ return fmt .Errorf ("expected CommandFailedEvent %s, got nil" , expected .CommandName )
532
+ }
533
+ if v , ok := expectedCmds [evt .CommandName ]; ok && v {
534
+ break
535
+ }
530
536
}
531
- }
532
537
533
- if expected .CommandName != "" && expected .CommandName != evt .CommandName {
534
- return fmt .Errorf ("command name mismatch for failed event; expected %s, got %s" , expected .CommandName , evt .CommandName )
538
+ if expected .CommandName != evt .CommandName {
539
+ return fmt .Errorf ("command name mismatch for failed event; expected %s, got %s" , expected .CommandName , evt .CommandName )
540
+ }
535
541
}
536
542
return nil
537
543
}
0 commit comments