Skip to content
Snippets Groups Projects
Commit da1502d9 authored by Denis Yuji Shimizu's avatar Denis Yuji Shimizu
Browse files

ssh: Create the `SeparatedOutput` function for ssh execution


This commit copies the `SeparatedOutput` from the its local execution
analogous (`tast-tests/src/go.chromium.org/tast-tests/cros/common/testexec/testexec.go`)
to execute over `ssh` the tests currently written for local execution.
An example of such tests that uses `SeparatedOutput` is:
`tast-tests/src/go.chromium.org/tast-tests/cros/local/bundles/cros/video/platform_decoding.go`

Change-Id: Ie00822e61b24a271b0acd89d46591ca1bd4d98cd
Signed-off-by: default avatarDenis Yuji Shimizu <denis.shimizu@collabora.com>
parent f14f437b
Branches main
No related tags found
Loading
......@@ -7,6 +7,7 @@ package ssh
import (
"bytes"
"context"
"strings"
"fmt"
"io"
"sync"
......@@ -185,6 +186,32 @@ func (c *Cmd) CombinedOutput(opts ...RunOption) ([]byte, error) {
return buf.Bytes(), err
}
// SeparatedOutput runs an external command, waits for its completion and
// returns stdout/stderr output of the command separately.
func (c *Cmd) SeparatedOutput(opts ...RunOption) (stdout, stderr []byte, err error) {
if c.Stdout != nil {
return nil, nil, errStdoutSet
}
if c.Stderr != nil {
return nil, nil, errStderrSet
}
var outbuf, errbuf bytes.Buffer
c.Stdout = &outbuf
c.Stderr = &errbuf
if err := c.Start(); err != nil {
return nil, nil, err
}
err = c.Wait(opts...)
if err != nil {
err = errors.Wrapf(err, "command %q returned non-zero error code", strings.Join(c.Args, " "))
}
return outbuf.Bytes(), errbuf.Bytes(), err
}
// StdinPipe returns a pipe that will be connected to the command's standard input
// when the command starts.
//
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment