github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/testsuites/watch.go (about)

     1  package testsuites
     2  
     3  import (
     4  	"os"
     5  	"time"
     6  
     7  	"github.com/spf13/cobra"
     8  
     9  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
    10  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/validator"
    11  	"github.com/kubeshop/testkube/pkg/ui"
    12  )
    13  
    14  func NewWatchTestSuiteExecutionCmd() *cobra.Command {
    15  	cmd := &cobra.Command{
    16  		Use:     "testsuiteexecution <executionName>",
    17  		Aliases: []string{"tse", "testsuites-execution", "testsuite-execution"},
    18  		Short:   "Watch test suite",
    19  		Long:    `Watch test suite by execution ID, returns results to console`,
    20  		Args:    validator.ExecutionName,
    21  		Run: func(cmd *cobra.Command, args []string) {
    22  
    23  			client, _, err := common.GetClient(cmd)
    24  			ui.ExitOnError("getting client", err)
    25  
    26  			startTime := time.Now()
    27  
    28  			executionID := args[0]
    29  			watchResp := client.WatchTestSuiteExecution(executionID)
    30  			for resp := range watchResp {
    31  				ui.ExitOnError("watching test suite execution", resp.Error)
    32  				printExecution(resp.Execution, startTime)
    33  			}
    34  
    35  			execution, err := client.GetTestSuiteExecution(executionID)
    36  			ui.ExitOnError("getting test suite excecution", err)
    37  			printExecution(execution, startTime)
    38  			ui.ExitOnError("getting recent execution data id:"+execution.Id, err)
    39  
    40  			err = uiPrintExecutionStatus(client, execution)
    41  			uiShellTestSuiteGetCommandBlock(execution.Id)
    42  			if err != nil {
    43  				os.Exit(1)
    44  			}
    45  		},
    46  	}
    47  
    48  	return cmd
    49  }