Skip to content

Commit

Permalink
tests(cli/harness): use unused Verbose flag to pipe daemon outputs (#…
Browse files Browse the repository at this point in the history
…10601)

Obtain actual daemon output on the screen while
debugging tests. 
Might be useful in the future even though it needs to
manually set verbose somewhere.
  • Loading branch information
hsanjuan authored Nov 27, 2024
1 parent 3b2c269 commit 02995d5
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions test/cli/harness/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package harness
import (
"fmt"
"io"
"os"
"os/exec"
"strings"
)
Expand Down Expand Up @@ -60,8 +61,27 @@ func environToMap(environ []string) map[string]string {

func (r *Runner) Run(req RunRequest) *RunResult {
cmd := exec.Command(req.Path, req.Args...)
stdout := &Buffer{}
stderr := &Buffer{}
var stdout io.Writer
var stderr io.Writer
outbuf := &Buffer{}
errbuf := &Buffer{}

if r.Verbose {
or, ow := io.Pipe()
errr, errw := io.Pipe()
stdout = io.MultiWriter(outbuf, ow)
stderr = io.MultiWriter(errbuf, errw)
go func() {
_, _ = io.Copy(os.Stdout, or)
}()
go func() {
_, _ = io.Copy(os.Stderr, errr)
}()
} else {
stdout = outbuf
stderr = errbuf
}

cmd.Stdout = stdout
cmd.Stderr = stderr
cmd.Dir = r.Dir
Expand All @@ -83,8 +103,8 @@ func (r *Runner) Run(req RunRequest) *RunResult {
err := req.RunFunc(cmd)

result := RunResult{
Stdout: stdout,
Stderr: stderr,
Stdout: outbuf,
Stderr: errbuf,
Cmd: cmd,
Err: err,
}
Expand Down

0 comments on commit 02995d5

Please sign in to comment.