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
+5 -7
View File
@@ -5,7 +5,6 @@
package wgengine
import (
"bytes"
"fmt"
"reflect"
"testing"
@@ -15,6 +14,7 @@ import (
"tailscale.com/net/dns"
"tailscale.com/net/tstun"
"tailscale.com/tailcfg"
"tailscale.com/tstest"
"tailscale.com/tstime/mono"
"tailscale.com/types/key"
"tailscale.com/types/netmap"
@@ -25,7 +25,7 @@ import (
func TestNoteReceiveActivity(t *testing.T) {
now := mono.Time(123456)
var logBuf bytes.Buffer
var logBuf tstest.MemLogger
confc := make(chan bool, 1)
gotConf := func() bool {
@@ -37,11 +37,9 @@ func TestNoteReceiveActivity(t *testing.T) {
}
}
e := &userspaceEngine{
timeNow: func() mono.Time { return now },
recvActivityAt: map[tailcfg.NodeKey]mono.Time{},
logf: func(format string, a ...interface{}) {
fmt.Fprintf(&logBuf, format, a...)
},
timeNow: func() mono.Time { return now },
recvActivityAt: map[tailcfg.NodeKey]mono.Time{},
logf: logBuf.Logf,
tundev: new(tstun.Wrapper),
testMaybeReconfigHook: func() { confc <- true },
trimmedNodes: map[tailcfg.NodeKey]bool{},