@@ -52,21 +52,37 @@ 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
63+ errCh := make (chan error , 1 )
64+
6065 go func () {
61- assert . NoError ( t , executeCmd () )
66+ errCh <- executeCmd ()
6267 // Closing the temp stdout in order to be able to read it's content.
6368 assert .NoError (t , stdWriter .Close ())
6469 }()
6570
66- content , err := io .ReadAll (newStdout )
71+ content , e := io .ReadAll (newStdout )
72+ assert .NoError (t , e )
73+ output = string (content )
74+ log .Debug (output )
75+
76+ err = <- errCh
77+
78+ return
79+ }
80+
81+ // Run a command, redirect the stdout and return the output
82+ func RunCmdWithOutput (t * testing.T , executeCmd func () error ) string {
83+ output , err := RunCmdWithOutputs (t , executeCmd )
6784 assert .NoError (t , err )
68- log .Debug (string (content ))
69- return string (content )
85+ return output
7086}
7187
7288func redirectOutToPipe (t * testing.T ) (* os.File , * os.File , func ()) {
0 commit comments