Skip to content

Commit

Permalink
fix: cli
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Dec 2, 2024
1 parent 5136c31 commit 6b89ab0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
28 changes: 18 additions & 10 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ func NewRunTestWorkflowCmd() *cobra.Command {
ui.NL()
if !execution.FailedToInitialize() {
if watchEnabled && len(args) > 0 {
exitCode = uiWatch(execution, serviceName, serviceIndex, parallelStepName, parallelStepIndex, client)
var pServiceName, pParallelStepName *string
if cmd.Flag("service-name").Changed || cmd.Flag("service-index").Changed {
pServiceName = &serviceName
}
if cmd.Flag("parallel-step-name").Changed || cmd.Flag("parallel-step-index").Changed {
pParallelStepName = &parallelStepName
}

exitCode = uiWatch(execution, pServiceName, serviceIndex, pParallelStepName, parallelStepIndex, client)
ui.NL()
if downloadArtifactsEnabled {
tests.DownloadTestWorkflowArtifacts(execution.Id, downloadDir, format, masks, client, outputPretty)
Expand Down Expand Up @@ -194,27 +202,27 @@ func NewRunTestWorkflowCmd() *cobra.Command {
return cmd
}

func uiWatch(execution testkube.TestWorkflowExecution, serviceName string, serviceIndex int,
parallelStepName string, parallelStepIndex int, client apiclientv1.Client) int {
func uiWatch(execution testkube.TestWorkflowExecution, serviceName *string, serviceIndex int,
parallelStepName *string, parallelStepIndex int, client apiclientv1.Client) int {
var result *testkube.TestWorkflowResult
var err error

switch {
case serviceName != "":
case serviceName != nil:
found := false
if execution.Workflow != nil {
found = execution.Workflow.HasService(serviceName)
found = execution.Workflow.HasService(*serviceName)
}

if !found {
ui.Failf("unknown service '%s' for test workflow execution %s", serviceName, execution.Id)
ui.Failf("unknown service '%s' for test workflow execution %s", *serviceName, execution.Id)
}

result, err = watchTestWorkflowServiceLogs(execution.Id, serviceName, serviceIndex, execution.Signature, client)
case parallelStepName != "":
ref := execution.GetParallelStepReference(parallelStepName)
result, err = watchTestWorkflowServiceLogs(execution.Id, *serviceName, serviceIndex, execution.Signature, client)
case parallelStepName != nil:
ref := execution.GetParallelStepReference(*parallelStepName)
if ref == "" {
ui.Failf("unknown parallel step '%s' for test workflow execution %s", parallelStepName, execution.Id)
ui.Failf("unknown parallel step '%s' for test workflow execution %s", *parallelStepName, execution.Id)
}

result, err = watchTestWorkflowParallelStepLogs(execution.Id, ref, parallelStepIndex, execution.Signature, client)
Expand Down
10 changes: 9 additions & 1 deletion cmd/kubectl-testkube/commands/testworkflows/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ func NewWatchTestWorkflowExecutionCmd() *cobra.Command {
ui.ExitOnError("render test workflow execution", err)

ui.NL()
exitCode := uiWatch(execution, serviceName, serviceIndex, parallelStepName, parallelStepIndex, client)
var pServiceName, pParallelStepName *string
if cmd.Flag("service-name").Changed || cmd.Flag("service-index").Changed {
pServiceName = &serviceName
}
if cmd.Flag("parallel-step-name").Changed || cmd.Flag("parallel-step-index").Changed {
pParallelStepName = &parallelStepName
}

exitCode := uiWatch(execution, pServiceName, serviceIndex, pParallelStepName, parallelStepIndex, client)
ui.NL()

execution, err = client.GetTestWorkflowExecution(execution.Id)
Expand Down

0 comments on commit 6b89ab0

Please sign in to comment.