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/node/core/curator/impl_leader_test.go b/metropolis/node/core/curator/impl_leader_test.go
index 465de13..b5b46de 100644
--- a/metropolis/node/core/curator/impl_leader_test.go
+++ b/metropolis/node/core/curator/impl_leader_test.go
@@ -44,6 +44,8 @@
// implementations without the overhead of having to wait for a leader election.
func fakeLeader(t *testing.T) fakeLeaderData {
t.Helper()
+ lt := logtree.New()
+ logtree.PipeAllToTest(t, lt)
// Set up context whose cancel function will be returned to the user for
// terminating all harnesses started by this function.
ctx, ctxC := context.WithCancel(context.Background())
@@ -145,9 +147,6 @@
}
leader := newCuratorLeader(leadership, &nodeCredentials.Node)
- lt := logtree.New()
- logtree.PipeAllToStderr(t, lt)
-
// Create a curator gRPC server which performs authentication as per the created
// ServerSecurity and is backed by the created leader.
srv := grpc.NewServer(sec.GRPCOptions(lt.MustLeveledFor("leader"))...)
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())
}
}
}()
diff --git a/metropolis/pkg/supervisor/supervisor_testhelpers.go b/metropolis/pkg/supervisor/supervisor_testhelpers.go
index 017c9f9..1a72ad8 100644
--- a/metropolis/pkg/supervisor/supervisor_testhelpers.go
+++ b/metropolis/pkg/supervisor/supervisor_testhelpers.go
@@ -57,7 +57,7 @@
verbose = true
}
if verbose {
- logtree.PipeAllToStderr(t, lt)
+ logtree.PipeAllToTest(t, lt)
}
sup := New(ctx, func(ctx context.Context) error {