Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(cli/harness): use unused Verbose flag to pipe daemon outputs #10601

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading