aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel McCarney <daniel@binaryparadox.net>2025-07-09 14:08:52 -0400
committerGopher Robot <gobot@golang.org>2025-07-11 12:27:10 -0700
commitb903b535d3ef82fab12a9cc0fa50fccc396ced55 (patch)
tree54ab31b8987efd94653b1749a9fc9be04d78d4a2
parent459a9db11b9c43bb1d61722bfd371751d6de05c9 (diff)
downloadgo-x-crypto-b903b535d3ef82fab12a9cc0fa50fccc396ced55.tar.xz
acme: capture pebble test subprocess stdout/stderr
When spawning the pebble and pebble-challtestserv processes redirect stdout/stderr to bytes.Buffer instances and print their content at test end as appropriate. The stdout/stderr content for each process is printed if the test failed, or if testing is being done in verbose mode. Otherwise the output is swallowed. This makes debugging test failures much easier as output from the subprocesses from independent tests isn't intermingled. Updates golang/go#74437 Cq-Include-Trybots: luci.golang.try:x_crypto-gotip-linux-amd64-longtest Change-Id: Ia79a3609ce3522ef6248442de247554c39367162 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/686935 Auto-Submit: Daniel McCarney <daniel@binaryparadox.net> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--acme/pebble_test.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/acme/pebble_test.go b/acme/pebble_test.go
index 63e6cc5..af7aee6 100644
--- a/acme/pebble_test.go
+++ b/acme/pebble_test.go
@@ -776,14 +776,28 @@ func prepareBinaries(t *testing.T, pebbleDir string) string {
func spawnServerProcess(t *testing.T, dir string, cmd string, args ...string) {
t.Helper()
+ var stdout, stderr bytes.Buffer
+
cmdInstance := exec.Command("./"+cmd, args...)
cmdInstance.Dir = dir
- cmdInstance.Stdout = os.Stdout
- cmdInstance.Stderr = os.Stderr
+ cmdInstance.Stdout = &stdout
+ cmdInstance.Stderr = &stderr
+
if err := cmdInstance.Start(); err != nil {
t.Fatalf("failed to start %s: %v", cmd, err)
}
+
t.Cleanup(func() {
cmdInstance.Process.Kill()
+
+ if t.Failed() || testing.Verbose() {
+ t.Logf("=== %s output ===", cmd)
+ if stdout.Len() > 0 {
+ t.Logf("stdout:\n%s", strings.TrimSpace(stdout.String()))
+ }
+ if stderr.Len() > 0 {
+ t.Logf("stderr:\n%s", strings.TrimSpace(stderr.String()))
+ }
+ }
})
}