tstest: add MemLogger bytes.Buffer wrapper with Logf method

We use it tons of places. Updated three at least in this PR.

Another use in next commit.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-09-07 15:17:39 -07:00
committed by Brad Fitzpatrick
parent 30a614f9b9
commit 4c68b7df7c
4 changed files with 26 additions and 20 deletions

View File

@ -5,12 +5,13 @@
package wgengine
import (
"bytes"
"fmt"
"runtime"
"strings"
"testing"
"time"
"tailscale.com/tstest"
)
func TestWatchdog(t *testing.T) {
@ -52,11 +53,9 @@ func TestWatchdog(t *testing.T) {
wdEngine := e.(*watchdogEngine)
wdEngine.maxWait = maxWaitMultiple * 100 * time.Millisecond
logBuf := new(bytes.Buffer)
logBuf := new(tstest.MemLogger)
fatalCalled := make(chan struct{})
wdEngine.logf = func(format string, args ...interface{}) {
fmt.Fprintf(logBuf, format+"\n", args...)
}
wdEngine.logf = logBuf.Logf
wdEngine.fatalf = func(format string, args ...interface{}) {
t.Logf("FATAL: %s", fmt.Sprintf(format, args...))
fatalCalled <- struct{}{}