mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-13 22:47:30 +00:00
all: unify some redundant testing.TB interface copies
I added yet another one in 6d117d64a2
but that new one is at the
best place int he dependency graph and has the best name, so let's use
that one for everything possible.
types/lazy can't use it for circular dependency reasons, so unexport
that copy at least.
Updates #cleanup
Change-Id: I25db6b6a0d81dbb8e89a0a9080c7f15cbf7aa770
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
03b47a55c7
commit
265c76dbc5
@@ -120,9 +120,9 @@ func (z *SyncValue[T]) PeekErr() (v T, err error, ok bool) {
|
||||
return zero, nil, false
|
||||
}
|
||||
|
||||
// TB is a subset of testing.TB that we use to set up test helpers.
|
||||
// testing_TB is a subset of testing.TB that we use to set up test helpers.
|
||||
// It's defined here to avoid pulling in the testing package.
|
||||
type TB interface {
|
||||
type testing_TB interface {
|
||||
Helper()
|
||||
Cleanup(func())
|
||||
}
|
||||
@@ -132,7 +132,9 @@ type TB interface {
|
||||
// subtests complete.
|
||||
// It is not safe for concurrent use and must not be called concurrently with
|
||||
// any SyncValue methods, including another call to itself.
|
||||
func (z *SyncValue[T]) SetForTest(tb TB, val T, err error) {
|
||||
//
|
||||
// The provided tb should be a [*testing.T] or [*testing.B].
|
||||
func (z *SyncValue[T]) SetForTest(tb testing_TB, val T, err error) {
|
||||
tb.Helper()
|
||||
|
||||
oldErr, oldVal := z.err.Load(), z.v
|
||||
|
@@ -24,6 +24,7 @@ import (
|
||||
"go4.org/mem"
|
||||
"tailscale.com/envknob"
|
||||
"tailscale.com/util/ctxkey"
|
||||
"tailscale.com/util/testenv"
|
||||
)
|
||||
|
||||
// Logf is the basic Tailscale logger type: a printf-like func.
|
||||
@@ -384,16 +385,10 @@ func (a asJSONResult) Format(s fmt.State, verb rune) {
|
||||
s.Write(v)
|
||||
}
|
||||
|
||||
// TBLogger is the testing.TB subset needed by TestLogger.
|
||||
type TBLogger interface {
|
||||
Helper()
|
||||
Logf(format string, args ...any)
|
||||
}
|
||||
|
||||
// TestLogger returns a logger that logs to tb.Logf
|
||||
// with a prefix to make it easier to distinguish spam
|
||||
// from explicit test failures.
|
||||
func TestLogger(tb TBLogger) Logf {
|
||||
func TestLogger(tb testenv.TB) Logf {
|
||||
return func(format string, args ...any) {
|
||||
tb.Helper()
|
||||
tb.Logf(" ... "+format, args...)
|
||||
|
Reference in New Issue
Block a user