From 6d913a4a17e6b16c4840ea26c0b236009ad977d7 Mon Sep 17 00:00:00 2001 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:13:41 +0100 Subject: [PATCH] e2e: write to output variables --- e2e/internal/upgrade/upgrade_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/e2e/internal/upgrade/upgrade_test.go b/e2e/internal/upgrade/upgrade_test.go index 7e8e7fe5b8..bf9da20e2b 100644 --- a/e2e/internal/upgrade/upgrade_test.go +++ b/e2e/internal/upgrade/upgrade_test.go @@ -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) @@ -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...) + } } } @@ -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 }