@@ -321,19 +321,21 @@ func compareStartedEvents(mt *mtest.T, expectations []*cmdStartedEvt, id0, id1 b
321321 }
322322
323323 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+ }
332334 }
333- }
334335
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+ }
337339 }
338340 if expected .DatabaseName != "" && expected .DatabaseName != evt .DatabaseName {
339341 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
458460 }
459461
460462 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+ }
469473 }
470- }
471474
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+ }
474478 }
475479
476480 eElems , err := expected .Reply .Elements ()
@@ -519,19 +523,21 @@ func compareFailedEvents(mt *mtest.T, expectations []*cmdFailedEvt) error {
519523 }
520524
521525 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+ }
530536 }
531- }
532537
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+ }
535541 }
536542 return nil
537543 }
0 commit comments