diff --git a/cmd/kubectl-testkube/commands/tests/common.go b/cmd/kubectl-testkube/commands/tests/common.go index eb233fe399e..601078c23df 100644 --- a/cmd/kubectl-testkube/commands/tests/common.go +++ b/cmd/kubectl-testkube/commands/tests/common.go @@ -3,6 +3,7 @@ package tests import ( "errors" "fmt" + "io" "os" "path" "regexp" @@ -30,7 +31,7 @@ const ( maxArgSize = int64(131072) // maximum argument size in linux-based systems is 128 KiB ) -func printExecutionDetails(cmd *cobra.Command, execution testkube.Execution) error { +func printExecutionDetails(cmd *cobra.Command, w io.Writer, execution testkube.Execution) error { outputFlag := cmd.Flag("output") outputType := render.OutputPretty if outputFlag != nil { @@ -60,14 +61,14 @@ func printExecutionDetails(cmd *cobra.Command, execution testkube.Execution) err ui.NL() ui.NL() case render.OutputYAML: - return render.RenderYaml(execution, os.Stdout) + return render.RenderYaml(execution, w) case render.OutputJSON: - return render.RenderJSON(execution, os.Stdout) + return render.RenderJSON(execution, w) case render.OutputGoTemplate: tpl := cmd.Flag("go-template").Value.String() - return render.RenderGoTemplate(execution, os.Stdout, tpl) + return render.RenderGoTemplate(execution, w, tpl) default: - return render.RenderYaml(execution, os.Stdout) + return render.RenderYaml(execution, w) } return nil diff --git a/cmd/kubectl-testkube/commands/tests/run.go b/cmd/kubectl-testkube/commands/tests/run.go index 231f652df1f..06892322704 100644 --- a/cmd/kubectl-testkube/commands/tests/run.go +++ b/cmd/kubectl-testkube/commands/tests/run.go @@ -341,7 +341,7 @@ func NewRunTestCmd() *cobra.Command { var execErrors []error for _, execution := range executions { - err = printExecutionDetails(cmd, execution) + err = printExecutionDetails(cmd, os.Stdout, execution) ui.ExitOnError("printing test execution "+execution.Id, err) if execution.ExecutionResult != nil && execution.ExecutionResult.ErrorMessage != "" { diff --git a/cmd/kubectl-testkube/commands/testsuites/common.go b/cmd/kubectl-testkube/commands/testsuites/common.go index ed89848b245..43c825359c7 100644 --- a/cmd/kubectl-testkube/commands/testsuites/common.go +++ b/cmd/kubectl-testkube/commands/testsuites/common.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "os" "path/filepath" "time" @@ -18,7 +19,7 @@ import ( "github.com/kubeshop/testkube/pkg/ui" ) -func printExecution(cmd *cobra.Command, execution testkube.TestSuiteExecution, startTime time.Time) error { +func printExecution(cmd *cobra.Command, w io.Writer, execution testkube.TestSuiteExecution, startTime time.Time) error { outputFlag := cmd.Flag("output") outputType := render.OutputPretty if outputFlag != nil { @@ -42,20 +43,20 @@ func printExecution(cmd *cobra.Command, execution testkube.TestSuiteExecution, s if execution.Id != "" { ui.Warn("Duration:", execution.CalculateDuration().String()+"\n") - ui.Table(execution, os.Stdout) + ui.Table(execution, w) } ui.NL() ui.NL() case render.OutputYAML: - return render.RenderYaml(execution, os.Stdout) + return render.RenderYaml(execution, w) case render.OutputJSON: - return render.RenderJSON(execution, os.Stdout) + return render.RenderJSON(execution, w) case render.OutputGoTemplate: tpl := cmd.Flag("go-template").Value.String() - return render.RenderGoTemplate(execution, os.Stdout, tpl) + return render.RenderGoTemplate(execution, w, tpl) default: - return render.RenderYaml(execution, os.Stdout) + return render.RenderYaml(execution, w) } return nil diff --git a/cmd/kubectl-testkube/commands/testsuites/run.go b/cmd/kubectl-testkube/commands/testsuites/run.go index 77dbbfc22d7..a423e8f0e7a 100644 --- a/cmd/kubectl-testkube/commands/testsuites/run.go +++ b/cmd/kubectl-testkube/commands/testsuites/run.go @@ -166,7 +166,7 @@ func NewRunTestSuiteCmd() *cobra.Command { ui.ExitOnError("watching test suite execution", resp.Error) if !silentMode { execution.TruncateErrorMessages(maxErrorMessageLength) - err = printExecution(cmd, execution, startTime) + err = printExecution(cmd, os.Stdout, execution, startTime) ui.ExitOnError("printing test suite execution "+execution.Id, err) } } @@ -178,7 +178,7 @@ func NewRunTestSuiteCmd() *cobra.Command { execution.TruncateErrorMessages(maxErrorMessageLength) ui.ExitOnError("getting recent execution data id:"+execution.Id, err) - err = printExecution(cmd, execution, startTime) + err = printExecution(cmd, os.Stdout, execution, startTime) ui.ExitOnError("printing test suite execution "+execution.Id, err) if outputPretty { diff --git a/cmd/kubectl-testkube/commands/testsuites/watch.go b/cmd/kubectl-testkube/commands/testsuites/watch.go index 2b781b37643..21e00768e70 100644 --- a/cmd/kubectl-testkube/commands/testsuites/watch.go +++ b/cmd/kubectl-testkube/commands/testsuites/watch.go @@ -29,12 +29,12 @@ func NewWatchTestSuiteExecutionCmd() *cobra.Command { watchResp := client.WatchTestSuiteExecution(executionID) for resp := range watchResp { ui.ExitOnError("watching test suite execution", resp.Error) - printExecution(cmd, resp.Execution, startTime) + printExecution(cmd, os.Stdout, resp.Execution, startTime) } execution, err := client.GetTestSuiteExecution(executionID) ui.ExitOnError("getting test suite excecution", err) - printExecution(cmd, execution, startTime) + printExecution(cmd, os.Stdout, execution, startTime) ui.ExitOnError("getting recent execution data id:"+execution.Id, err) err = uiPrintExecutionStatus(client, execution) diff --git a/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go b/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go index 154566b5485..05076da5af9 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go +++ b/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go @@ -2,7 +2,7 @@ package renderer import ( "fmt" - "os" + "io" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -13,7 +13,7 @@ import ( "github.com/kubeshop/testkube/pkg/ui" ) -func PrintTestWorkflowExecution(cmd *cobra.Command, execution testkube.TestWorkflowExecution) error { +func PrintTestWorkflowExecution(cmd *cobra.Command, w io.Writer, execution testkube.TestWorkflowExecution) error { outputFlag := cmd.Flag("output") outputType := render.OutputPretty if outputFlag != nil { @@ -22,16 +22,16 @@ func PrintTestWorkflowExecution(cmd *cobra.Command, execution testkube.TestWorkf switch outputType { case render.OutputPretty: - printPrettyOutput(ui.NewUI(ui.Verbose, os.Stdout), execution) + printPrettyOutput(ui.NewUI(ui.Verbose, w), execution) case render.OutputYAML: - return render.RenderYaml(execution, os.Stdout) + return render.RenderYaml(execution, w) case render.OutputJSON: - return render.RenderJSON(execution, os.Stdout) + return render.RenderJSON(execution, w) case render.OutputGoTemplate: tpl := cmd.Flag("go-template").Value.String() - return render.RenderGoTemplate(execution, os.Stdout, tpl) + return render.RenderGoTemplate(execution, w, tpl) default: - return render.RenderYaml(execution, os.Stdout) + return render.RenderYaml(execution, w) } return nil diff --git a/cmd/kubectl-testkube/commands/testworkflows/run.go b/cmd/kubectl-testkube/commands/testworkflows/run.go index fc26b4a4a36..8739eade6ed 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/run.go +++ b/cmd/kubectl-testkube/commands/testworkflows/run.go @@ -51,7 +51,7 @@ func NewRunTestWorkflowCmd() *cobra.Command { Config: config, }) ui.ExitOnError("execute test workflow "+name+" from namespace "+namespace, err) - err = renderer.PrintTestWorkflowExecution(cmd, execution) + err = renderer.PrintTestWorkflowExecution(cmd, os.Stdout, execution) ui.ExitOnError("render test workflow execution", err) var exitCode = 0