@@ -511,41 +511,70 @@ func TestTransitionTimedOut(t *testing.T) {
511511}
512512
513513func TestTransitionTerminated (t * testing.T ) {
514- ctx := & chasm.MockMutableContext {
515- MockContext : chasm.MockContext {
516- HandleNow : func (chasm.Component ) time.Time { return defaultTime },
514+ testCases := []struct {
515+ name string
516+ startStatus nexusoperationpb.OperationStatus
517+ }{
518+ {
519+ name : "terminated from scheduled" ,
520+ startStatus : nexusoperationpb .OPERATION_STATUS_SCHEDULED ,
521+ },
522+ {
523+ name : "terminated from started" ,
524+ startStatus : nexusoperationpb .OPERATION_STATUS_STARTED ,
525+ },
526+ {
527+ name : "terminated from backing off" ,
528+ startStatus : nexusoperationpb .OPERATION_STATUS_BACKING_OFF ,
529+ },
530+ {
531+ name : "terminated from canceled" ,
532+ startStatus : nexusoperationpb .OPERATION_STATUS_CANCELED ,
517533 },
518534 }
519535
520- operation := newTestOperation ()
521- operation .Status = nexusoperationpb .OPERATION_STATUS_SCHEDULED
536+ for _ , tc := range testCases {
537+ t .Run (tc .name , func (t * testing.T ) {
538+ ctx := & chasm.MockMutableContext {
539+ MockContext : chasm.MockContext {
540+ HandleNow : func (chasm.Component ) time.Time { return defaultTime },
541+ },
542+ }
543+ operation := newTestOperation ()
544+ operation .Status = tc .startStatus
522545
523- err := TransitionTerminated .Apply (operation , ctx , EventTerminated {
524- TerminateComponentRequest : chasm.TerminateComponentRequest {
525- RequestID : "terminate-request-id" ,
526- Reason : "test reason" ,
527- Identity : "test-identity" ,
528- },
529- })
530- require .NoError (t , err )
546+ event := EventTerminated {TerminateComponentRequest : chasm.TerminateComponentRequest {
547+ RequestID : "terminate-request-id" ,
548+ Reason : "test reason" ,
549+ Identity : "test-identity" ,
550+ }}
531551
532- require .Equal (t , nexusoperationpb .OPERATION_STATUS_TERMINATED , operation .Status )
533- require .Equal (t , defaultTime , operation .ClosedTime .AsTime ())
534- protorequire .ProtoEqual (t , & nexusoperationpb.NexusOperationTerminateState {
535- RequestId : "terminate-request-id" ,
536- Identity : "test-identity" ,
537- }, operation .TerminateState )
538- protorequire .ProtoEqual (t , & nexusoperationpb.OperationOutcome {
539- Variant : & nexusoperationpb.OperationOutcome_Failed_ {
540- Failed : & nexusoperationpb.OperationOutcome_Failed {
541- Failure : & failurepb.Failure {
542- Message : "test reason" ,
543- FailureInfo : & failurepb.Failure_TerminatedFailureInfo {
544- TerminatedFailureInfo : & failurepb.TerminatedFailureInfo {},
552+ err := TransitionTerminated .Apply (operation , ctx , event )
553+ require .NoError (t , err )
554+
555+ require .Equal (t , nexusoperationpb .OPERATION_STATUS_TERMINATED , operation .Status )
556+ require .Equal (t , defaultTime , operation .ClosedTime .AsTime ())
557+ protorequire .ProtoEqual (t , & nexusoperationpb.NexusOperationTerminateState {
558+ RequestId : "terminate-request-id" ,
559+ Identity : "test-identity" ,
560+ }, operation .TerminateState )
561+
562+ // Verify outcome failure is set with terminated info and reason as message.
563+ protorequire .ProtoEqual (t , & nexusoperationpb.OperationOutcome {
564+ Variant : & nexusoperationpb.OperationOutcome_Failed_ {
565+ Failed : & nexusoperationpb.OperationOutcome_Failed {
566+ Failure : & failurepb.Failure {
567+ Message : "test reason" ,
568+ FailureInfo : & failurepb.Failure_TerminatedFailureInfo {
569+ TerminatedFailureInfo : & failurepb.TerminatedFailureInfo {},
570+ },
571+ },
545572 },
546573 },
547- },
548- },
549- }, operation .Outcome .Get (ctx ))
550- require .Empty (t , ctx .Tasks )
574+ }, operation .Outcome .Get (ctx ))
575+
576+ // Terminal state - no tasks should be emitted
577+ require .Empty (t , ctx .Tasks )
578+ })
579+ }
551580}
0 commit comments