github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/testworkflows/abort.go (about) 1 package testworkflows 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 8 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" 9 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/validator" 10 "github.com/kubeshop/testkube/pkg/ui" 11 ) 12 13 func NewAbortTestWorkflowExecutionCmd() *cobra.Command { 14 return &cobra.Command{ 15 Use: "testworkflowexecution <executionName>", 16 Aliases: []string{"twe", "testworkflows-execution", "testworkflow-execution"}, 17 Short: "Abort test workflow execution", 18 Args: validator.ExecutionName, 19 20 Run: func(cmd *cobra.Command, args []string) { 21 executionID := args[0] 22 23 client, _, err := common.GetClient(cmd) 24 ui.ExitOnError("getting client", err) 25 26 execution, err := client.GetTestWorkflowExecution(executionID) 27 ui.ExitOnError("get execution failed", err) 28 29 err = client.AbortTestWorkflowExecution(execution.Workflow.Name, execution.Id) 30 ui.ExitOnError(fmt.Sprintf("aborting testworkflow execution %s", executionID), err) 31 32 ui.SuccessAndExit("Succesfully aborted test workflow execution", executionID) 33 }, 34 } 35 } 36 37 func NewAbortTestWorkflowExecutionsCmd() *cobra.Command { 38 return &cobra.Command{ 39 Use: "testworkflowexecutions <testWorkflowName>", 40 Aliases: []string{"twes", "testworkflows-executions", "testworkflow-executions"}, 41 Short: "Abort all test workflow executions", 42 Args: cobra.ExactArgs(1), 43 44 Run: func(cmd *cobra.Command, args []string) { 45 testWorkflowName := args[0] 46 47 client, _, err := common.GetClient(cmd) 48 ui.ExitOnError("getting client", err) 49 50 err = client.AbortTestWorkflowExecutions(testWorkflowName) 51 ui.ExitOnError(fmt.Sprintf("aborting test workflow executions for test workflow %s", testWorkflowName), err) 52 53 ui.SuccessAndExit("Successfully aborted all test workflow executions", testWorkflowName) 54 }, 55 } 56 }