diff --git a/client/tailscale/localclient_test.go b/client/tailscale/localclient_test.go index a5f4e289f..d992b1e44 100644 --- a/client/tailscale/localclient_test.go +++ b/client/tailscale/localclient_test.go @@ -35,6 +35,7 @@ func TestDeps(t *testing.T) { BadDeps: map[string]string{ // Make sure we don't again accidentally bring in a dependency on // drive or its transitive dependencies + "testing": "do not use testing package in production code", "tailscale.com/drive/driveimpl": "https://github.com/tailscale/tailscale/pull/10631", "github.com/studio-b12/gowebdav": "https://github.com/tailscale/tailscale/pull/10631", }, diff --git a/cmd/derper/depaware.txt b/cmd/derper/depaware.txt index b5839b4e9..780e9f2ee 100644 --- a/cmd/derper/depaware.txt +++ b/cmd/derper/depaware.txt @@ -235,7 +235,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa encoding/pem from crypto/tls+ errors from bufio+ expvar from github.com/prometheus/client_golang/prometheus+ - flag from tailscale.com/cmd/derper+ + flag from tailscale.com/cmd/derper fmt from compress/flate+ go/token from google.golang.org/protobuf/internal/strs hash from crypto+ @@ -277,7 +277,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa runtime/debug from github.com/prometheus/client_golang/prometheus+ runtime/metrics from github.com/prometheus/client_golang/prometheus+ runtime/pprof from net/http/pprof - runtime/trace from net/http/pprof+ + runtime/trace from net/http/pprof slices from tailscale.com/ipn/ipnstate+ sort from compress/flate+ strconv from compress/flate+ @@ -285,7 +285,6 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa sync from compress/flate+ sync/atomic from context+ syscall from crypto/rand+ - testing from tailscale.com/util/syspolicy text/tabwriter from runtime/pprof time from compress/gzip+ unicode from bytes+ diff --git a/cmd/derper/derper_test.go b/cmd/derper/derper_test.go index 551800309..79cde2a82 100644 --- a/cmd/derper/derper_test.go +++ b/cmd/derper/derper_test.go @@ -99,6 +99,7 @@ func TestNoContent(t *testing.T) { func TestDeps(t *testing.T) { deptest.DepChecker{ BadDeps: map[string]string{ + "testing": "do not use testing package in production code", "gvisor.dev/gvisor/pkg/buffer": "https://github.com/tailscale/tailscale/issues/9756", "gvisor.dev/gvisor/pkg/cpuid": "https://github.com/tailscale/tailscale/issues/9756", "gvisor.dev/gvisor/pkg/tcpip": "https://github.com/tailscale/tailscale/issues/9756", diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt index 5883507f0..4d8aa3b19 100644 --- a/cmd/tailscale/depaware.txt +++ b/cmd/tailscale/depaware.txt @@ -299,7 +299,6 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep regexp from github.com/coreos/go-iptables/iptables+ regexp/syntax from regexp runtime/debug from nhooyr.io/websocket/internal/xsync+ - runtime/trace from testing slices from tailscale.com/client/web+ sort from archive/tar+ strconv from archive/tar+ @@ -307,7 +306,6 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep sync from archive/tar+ sync/atomic from context+ syscall from archive/tar+ - testing from tailscale.com/util/syspolicy text/tabwriter from github.com/peterbourgon/ff/v3/ffcli+ text/template from html/template text/template/parse from html/template+ diff --git a/cmd/tailscale/tailscale_test.go b/cmd/tailscale/tailscale_test.go index 0a554aa82..6c8c497b2 100644 --- a/cmd/tailscale/tailscale_test.go +++ b/cmd/tailscale/tailscale_test.go @@ -12,6 +12,7 @@ import ( func TestDeps(t *testing.T) { deptest.DepChecker{ BadDeps: map[string]string{ + "testing": "do not use testing package in production code", "gvisor.dev/gvisor/pkg/buffer": "https://github.com/tailscale/tailscale/issues/9756", "gvisor.dev/gvisor/pkg/cpuid": "https://github.com/tailscale/tailscale/issues/9756", "gvisor.dev/gvisor/pkg/tcpip": "https://github.com/tailscale/tailscale/issues/9756", diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index b97160e22..54605d950 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -553,7 +553,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de regexp/syntax from regexp runtime/debug from github.com/aws/aws-sdk-go-v2/internal/sync/singleflight+ runtime/pprof from net/http/pprof+ - runtime/trace from net/http/pprof+ + runtime/trace from net/http/pprof slices from tailscale.com/appc+ sort from archive/tar+ strconv from archive/tar+ @@ -561,7 +561,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de sync from archive/tar+ sync/atomic from context+ syscall from archive/tar+ - testing from tailscale.com/util/syspolicy text/tabwriter from runtime/pprof text/template from html/template text/template/parse from html/template+ diff --git a/cmd/tailscaled/tailscaled_test.go b/cmd/tailscaled/tailscaled_test.go index bc7906522..5045468d6 100644 --- a/cmd/tailscaled/tailscaled_test.go +++ b/cmd/tailscaled/tailscaled_test.go @@ -20,6 +20,7 @@ func TestDeps(t *testing.T) { GOOS: "darwin", GOARCH: "arm64", BadDeps: map[string]string{ + "testing": "do not use testing package in production code", "gvisor.dev/gvisor/pkg/hostarch": "will crash on non-4K page sizes; see https://github.com/tailscale/tailscale/issues/8658", }, }.Check(t) @@ -28,6 +29,7 @@ func TestDeps(t *testing.T) { GOOS: "linux", GOARCH: "arm64", BadDeps: map[string]string{ + "testing": "do not use testing package in production code", "gvisor.dev/gvisor/pkg/hostarch": "will crash on non-4K page sizes; see https://github.com/tailscale/tailscale/issues/8658", }, }.Check(t) diff --git a/ipn/ipn_test.go b/ipn/ipn_test.go index bc9632fbb..cba70bccd 100644 --- a/ipn/ipn_test.go +++ b/ipn/ipn_test.go @@ -12,6 +12,7 @@ import ( func TestDeps(t *testing.T) { deptest.DepChecker{ BadDeps: map[string]string{ + "testing": "do not use testing package in production code", "gvisor.dev/gvisor/pkg/buffer": "https://github.com/tailscale/tailscale/issues/9756", "gvisor.dev/gvisor/pkg/cpuid": "https://github.com/tailscale/tailscale/issues/9756", "gvisor.dev/gvisor/pkg/tcpip": "https://github.com/tailscale/tailscale/issues/9756", diff --git a/tailcfg/tailcfg_test.go b/tailcfg/tailcfg_test.go index f1a314326..94b4b50d1 100644 --- a/tailcfg/tailcfg_test.go +++ b/tailcfg/tailcfg_test.go @@ -859,6 +859,7 @@ func TestDeps(t *testing.T) { BadDeps: map[string]string{ // Make sure we don't again accidentally bring in a dependency on // drive or its transitive dependencies + "testing": "do not use testing package in production code", "tailscale.com/drive/driveimpl": "https://github.com/tailscale/tailscale/pull/10631", "github.com/studio-b12/gowebdav": "https://github.com/tailscale/tailscale/pull/10631", }, diff --git a/tstest/iosdeps/iosdeps_test.go b/tstest/iosdeps/iosdeps_test.go index 78a526ab1..08df9a930 100644 --- a/tstest/iosdeps/iosdeps_test.go +++ b/tstest/iosdeps/iosdeps_test.go @@ -14,6 +14,7 @@ func TestDeps(t *testing.T) { GOOS: "ios", GOARCH: "arm64", BadDeps: map[string]string{ + "testing": "do not use testing package in production code", "text/template": "linker bloat (MethodByName)", "html/template": "linker bloat (MethodByName)", }, diff --git a/tstest/jsdeps/jsdeps_test.go b/tstest/jsdeps/jsdeps_test.go index c3dbcd39a..eb44df62e 100644 --- a/tstest/jsdeps/jsdeps_test.go +++ b/tstest/jsdeps/jsdeps_test.go @@ -14,6 +14,7 @@ func TestDeps(t *testing.T) { GOOS: "js", GOARCH: "wasm", BadDeps: map[string]string{ + "testing": "do not use testing package in production code", "runtime/pprof": "bloat", "golang.org/x/net/http2/h2c": "bloat", "net/http/pprof": "bloat", diff --git a/util/syspolicy/handler.go b/util/syspolicy/handler.go index 31129028e..f1fad9770 100644 --- a/util/syspolicy/handler.go +++ b/util/syspolicy/handler.go @@ -6,7 +6,6 @@ package syspolicy import ( "errors" "sync/atomic" - "testing" ) var ( @@ -69,7 +68,14 @@ func RegisterHandler(h Handler) { } } -func SetHandlerForTest(tb testing.TB, h Handler) { +// 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 { + Helper() + Cleanup(func()) +} + +func SetHandlerForTest(tb TB, h Handler) { tb.Helper() oldHandler := handler handler = h