Skip to content

Commit d8ec1cb

Browse files
authored
fix: separate stdout and stderr for TestGoImports (#2915)
Separate stdout and stderr from the `goimports` command, so that only the actual list of unformatted files from stdout is checked, while download progress messages in stderr are ignored unless an error occurs. This issue was first observed [here](#2913 (comment)) that download progress messages is reported as unformatted lines. This change is verified in #2913 ([log](https://github.com/googleapis/librarian/actions/runs/19375966778/job/55443348855)) .
1 parent 2578a2a commit d8ec1cb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

all_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ func TestGolangCILint(t *testing.T) {
226226

227227
func TestGoImports(t *testing.T) {
228228
cmd := exec.Command("go", "run", "golang.org/x/tools/cmd/[email protected]", "-d", ".")
229-
var out bytes.Buffer
230-
cmd.Stdout = &out
231-
cmd.Stderr = &out
229+
var stdout, stderr bytes.Buffer
230+
cmd.Stdout = &stdout
231+
cmd.Stderr = &stderr
232232

233233
if err := cmd.Run(); err != nil {
234-
t.Fatalf("goimports failed to run: %v\nOutput:\n%s", err, out.String())
234+
t.Fatalf("goimports failed to run: %v\nStdout:\n%s\nStderr:\n%s", err, stdout.String(), stderr.String())
235235
}
236-
if out.Len() > 0 {
237-
t.Errorf("goimports found unformatted files:\n%s", out.String())
236+
if stdout.Len() > 0 {
237+
t.Errorf("goimports found unformatted files:\n%s", stdout.String())
238238
}
239239
}
240240

0 commit comments

Comments
 (0)