Skip to content

Commit 7ca7298

Browse files
committed
Update tests to use separate string.Builder-s for stdout and stderr
string.Builder is a non-comparable type which is not safe for concurrent use when shared by Cmd.Stdout and Cmd.Stderr. Causes a race condition when accessing the the builder when Cmd is running.
1 parent d6a9ddc commit 7ca7298

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tfexec/internal/e2etest/util_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,21 @@ func runTestVersions(t *testing.T, versions []string, fixtureName string, cb fun
9191
}
9292
}
9393

94-
var stdouterr strings.Builder
95-
tf.SetStdout(&stdouterr)
96-
tf.SetStderr(&stdouterr)
94+
// Separate strings.Builder because it's not concurrent safe
95+
var stdout strings.Builder
96+
tf.SetStdout(&stdout)
97+
var stderr strings.Builder
98+
tf.SetStderr(&stderr)
9799

98100
tf.SetLogger(&testingPrintfer{t})
99101

100102
// TODO: capture panics here?
101103
cb(t, runningVersion, tf)
102104

103-
t.Logf("CLI Output:\n%s", stdouterr.String())
105+
t.Logf("CLI Output:\n%s", stdout.String())
106+
if len(stderr.String()) > 0 {
107+
t.Logf("CLI Error:\n%s", stderr.String())
108+
}
104109
})
105110
}
106111
}

0 commit comments

Comments
 (0)