m/p/logtree: pipe to t.Log in tests instead of stdout
Change-Id: I12506a0553810d934872aa0dd03478a66ba6e95f
Reviewed-on: https://review.monogon.dev/c/monogon/+/1488
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/metropolis/pkg/logtree/testhelpers.go b/metropolis/pkg/logtree/testhelpers.go
index fe69017..45bcaf2 100644
--- a/metropolis/pkg/logtree/testhelpers.go
+++ b/metropolis/pkg/logtree/testhelpers.go
@@ -2,17 +2,15 @@
import (
"context"
- "fmt"
- "os"
"testing"
)
-// PipeAllToStderr starts a goroutine that will forward all logtree entries
-// into stderr, in the canonical logtree payload representation.
+// PipeAllToTest starts a goroutine that will forward all logtree entries
+// t.Logf(), in the canonical logtree payload representation.
//
// It's designed to be used in tests, and will automatically stop when the
// test/benchmark it's running in exits.
-func PipeAllToStderr(t testing.TB, lt *LogTree) {
+func PipeAllToTest(t testing.TB, lt *LogTree) {
t.Helper()
reader, err := lt.Read("", WithChildren(), WithStream())
@@ -26,12 +24,13 @@
t.Cleanup(ctxC)
go func() {
+ t.Helper()
for {
select {
case <-ctx.Done():
return
case p := <-reader.Stream:
- fmt.Fprintf(os.Stderr, "%s\n", p.String())
+ t.Logf("%s", p.String())
}
}
}()