diff --git a/utils/tests/test_cli.go b/utils/tests/test_cli.go index 8c300f45d..8c4a1cc6c 100644 --- a/utils/tests/test_cli.go +++ b/utils/tests/test_cli.go @@ -52,21 +52,37 @@ func (cli *JfrogCli) RunCliCmdWithOutput(t *testing.T, args ...string) string { return RunCmdWithOutput(t, func() error { return cli.Exec(args...) }) } -// Run a command, redirect the stdout and return the output -func RunCmdWithOutput(t *testing.T, executeCmd func() error) string { +func (cli *JfrogCli) RunCliCmdWithOutputs(t *testing.T, args ...string) (string, error) { + return RunCmdWithOutputs(t, func() error { return cli.Exec(args...) }) +} + +func RunCmdWithOutputs(t *testing.T, executeCmd func() error) (output string, err error) { newStdout, stdWriter, cleanUp := redirectOutToPipe(t) defer cleanUp() + errCh := make(chan error, 1) + go func() { - assert.NoError(t, executeCmd()) + errCh <- executeCmd() // Closing the temp stdout in order to be able to read it's content. assert.NoError(t, stdWriter.Close()) }() - content, err := io.ReadAll(newStdout) + content, e := io.ReadAll(newStdout) + assert.NoError(t, e) + output = string(content) + log.Debug(output) + + err = <-errCh + + return +} + +// Run a command, redirect the stdout and return the output +func RunCmdWithOutput(t *testing.T, executeCmd func() error) string { + output, err := RunCmdWithOutputs(t, executeCmd) assert.NoError(t, err) - log.Debug(string(content)) - return string(content) + return output } func redirectOutToPipe(t *testing.T) (*os.File, *os.File, func()) {