Skip to content

Commit

Permalink
e2e: write to output variables
Browse files Browse the repository at this point in the history
  • Loading branch information
msanft committed Dec 14, 2023
1 parent 82a19c2 commit 6d913a4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions e2e/internal/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ type versionContainer struct {
// runCommandWithSeparateOutputs runs the given command while separating buffers for
// stdout and stderr.
func runCommandWithSeparateOutputs(cmd *exec.Cmd) (stdout, stderr []byte, err error) {
stdout = []byte{}
stderr = []byte{}

stdoutIn, err := cmd.StdoutPipe()
if err != nil {
err = fmt.Errorf("create stdout pipe: %w", err)
Expand All @@ -475,7 +478,14 @@ func runCommandWithSeparateOutputs(cmd *exec.Cmd) (stdout, stderr []byte, err er
continuouslyPrintOutput := func(r io.Reader, prefix string) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
fmt.Printf("%s: %s\n", prefix, scanner.Text())
output := scanner.Text()
fmt.Printf("%s: %s\n", prefix, output)
switch prefix {
case "stdout":
stdout = append(stdout, output...)
case "stderr":
stderr = append(stderr, output...)
}
}
}

Expand All @@ -486,5 +496,5 @@ func runCommandWithSeparateOutputs(cmd *exec.Cmd) (stdout, stderr []byte, err er
err = fmt.Errorf("wait for command to finish: %w", err)
}

return
return stdout, stderr, err
}

0 comments on commit 6d913a4

Please sign in to comment.