Skip to content

Commit 243cf93

Browse files
committed
Test Cli outputs of cmd with errors
1 parent 203c916 commit 243cf93

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

utils/tests/test_cli.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,32 @@ func (cli *JfrogCli) RunCliCmdWithOutput(t *testing.T, args ...string) string {
5252
return RunCmdWithOutput(t, func() error { return cli.Exec(args...) })
5353
}
5454

55-
// Run a command, redirect the stdout and return the output
56-
func RunCmdWithOutput(t *testing.T, executeCmd func() error) string {
55+
func (cli *JfrogCli) RunCliCmdWithOutputs(t *testing.T, args ...string) (string, error) {
56+
return RunCmdWithOutputs(t, func() error { return cli.Exec(args...) })
57+
}
58+
59+
func RunCmdWithOutputs(t *testing.T, executeCmd func() error) (output string, err error) {
5760
newStdout, stdWriter, cleanUp := redirectOutToPipe(t)
5861
defer cleanUp()
5962

6063
go func() {
61-
assert.NoError(t, executeCmd())
64+
err = executeCmd()
6265
// Closing the temp stdout in order to be able to read it's content.
6366
assert.NoError(t, stdWriter.Close())
6467
}()
6568

66-
content, err := io.ReadAll(newStdout)
69+
content, e := io.ReadAll(newStdout)
70+
assert.NoError(t, e)
71+
output = string(content)
72+
log.Debug(output)
73+
return
74+
}
75+
76+
// Run a command, redirect the stdout and return the output
77+
func RunCmdWithOutput(t *testing.T, executeCmd func() error) string {
78+
output, err := RunCmdWithOutputs(t, executeCmd)
6779
assert.NoError(t, err)
68-
log.Debug(string(content))
69-
return string(content)
80+
return output
7081
}
7182

7283
func redirectOutToPipe(t *testing.T) (*os.File, *os.File, func()) {

0 commit comments

Comments
 (0)