@@ -497,6 +497,56 @@ func TestMoveTablesSwitchTrafficOperationTimeout(t *testing.T) {
497497 c .Assert (buf .String (), qt .Equals , "" )
498498}
499499
500+ func TestMoveTablesCancelWithFlags (t * testing.T ) {
501+ c := qt .New (t )
502+ setMoveTablesPollInterval (t , 0 )
503+
504+ org := "my-org"
505+ db := "my-db"
506+ branch := "my-branch"
507+
508+ keepData := false
509+ svc := & mock.MoveTablesService {
510+ CancelFn : func (ctx context.Context , req * ps.MoveTablesCancelRequest ) (* ps.VtctldOperationReference , error ) {
511+ c .Assert (req .Workflow , qt .Equals , "my-workflow" )
512+ c .Assert (req .TargetKeyspace , qt .Equals , "target-ks" )
513+ c .Assert (req .KeepData , qt .IsNotNil )
514+ c .Assert (* req .KeepData , qt .Equals , keepData )
515+ return & ps.VtctldOperationReference {ID : "cancel-op" }, nil
516+ },
517+ }
518+ vtctldSvc := & mock.VtctldService {
519+ GetOperationFn : func (ctx context.Context , req * ps.GetVtctldOperationRequest ) (* ps.VtctldOperation , error ) {
520+ c .Assert (req .Organization , qt .Equals , org )
521+ c .Assert (req .Database , qt .Equals , db )
522+ c .Assert (req .Branch , qt .Equals , branch )
523+ c .Assert (req .ID , qt .Equals , "cancel-op" )
524+
525+ return & ps.VtctldOperation {
526+ ID : "cancel-op" ,
527+ State : "completed" ,
528+ Completed : true ,
529+ Result : json .RawMessage (`{"summary":"cancelled"}` ),
530+ }, nil
531+ },
532+ }
533+
534+ var buf bytes.Buffer
535+ ch := moveTablesTestHelper (org , svc , vtctldSvc , & buf )
536+
537+ cmd := MoveTablesCmd (ch )
538+ cmd .SetArgs ([]string {"cancel" , db , branch ,
539+ "--workflow" , "my-workflow" ,
540+ "--target-keyspace" , "target-ks" ,
541+ "--keep-data=false" ,
542+ })
543+ err := cmd .Execute ()
544+ c .Assert (err , qt .IsNil )
545+ c .Assert (svc .CancelFnInvoked , qt .IsTrue )
546+ c .Assert (vtctldSvc .GetOperationFnInvoked , qt .IsTrue )
547+ c .Assert (buf .String (), qt .JSONEquals , map [string ]string {"summary" : "cancelled" })
548+ }
549+
500550func TestMoveTablesShow (t * testing.T ) {
501551 c := qt .New (t )
502552
0 commit comments