github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/tests/renderer/execution_obj.go (about)

     1  package renderer
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/render"
     7  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/renderer"
     8  	"github.com/kubeshop/testkube/pkg/api/v1/client"
     9  	"github.com/kubeshop/testkube/pkg/api/v1/testkube"
    10  	"github.com/kubeshop/testkube/pkg/ui"
    11  )
    12  
    13  func ExecutionRenderer(client client.Client, ui *ui.UI, obj interface{}) error {
    14  	execution, ok := obj.(testkube.Execution)
    15  	if !ok {
    16  		return fmt.Errorf("can't render execution, expecrted obj to be testkube.Execution but got '%T'", obj)
    17  	}
    18  
    19  	ui.Warn("ID:        ", execution.Id)
    20  	ui.Warn("Name:      ", execution.Name)
    21  	if execution.Number != 0 {
    22  		ui.Warn("Number:           ", fmt.Sprintf("%d", execution.Number))
    23  	}
    24  	ui.Warn("Test name:        ", execution.TestName)
    25  	ui.Warn("Test namespace:   ", execution.TestNamespace)
    26  	ui.Warn("Type:             ", execution.TestType)
    27  	if execution.ExecutionResult != nil && execution.ExecutionResult.Status != nil {
    28  		ui.Warn("Status:           ", string(*execution.ExecutionResult.Status))
    29  	}
    30  	ui.Warn("Start time:       ", execution.StartTime.String())
    31  	ui.Warn("End time:         ", execution.EndTime.String())
    32  	ui.Warn("Duration:         ", execution.Duration)
    33  	if execution.RunningContext != nil {
    34  		ui.Warn("Running context:")
    35  		ui.Warn("Type:   ", execution.RunningContext.Type_)
    36  		ui.Warn("Context:", execution.RunningContext.Context)
    37  	}
    38  
    39  	if len(execution.Labels) > 0 {
    40  		ui.Warn("Labels:           ", testkube.MapToString(execution.Labels))
    41  	}
    42  
    43  	renderer.RenderVariables(execution.Variables)
    44  
    45  	if len(execution.Command) > 0 {
    46  		ui.Warn("Command:          ", execution.Command...)
    47  	}
    48  
    49  	if len(execution.Args) > 0 {
    50  		ui.Warn("Args:             ", execution.Args...)
    51  	}
    52  
    53  	if execution.Content != nil && execution.Content.Repository != nil {
    54  		ui.Warn("Repository parameters:")
    55  		ui.Warn("  Branch:         ", execution.Content.Repository.Branch)
    56  		ui.Warn("  Commit:         ", execution.Content.Repository.Commit)
    57  		ui.Warn("  Path:           ", execution.Content.Repository.Path)
    58  		ui.Warn("  Working dir:    ", execution.Content.Repository.WorkingDir)
    59  		ui.Warn("  Certificate:    ", execution.Content.Repository.CertificateSecret)
    60  		ui.Warn("  Auth type:      ", execution.Content.Repository.AuthType)
    61  	}
    62  
    63  	if err := render.RenderExecutionResult(client, &execution, false, true); err != nil {
    64  		return err
    65  	}
    66  
    67  	ui.NL()
    68  
    69  	return nil
    70  }