ipn/ipnlocal: convert more tests to use policytest, de-global-ify

Now that we have policytest and the policyclient.Client interface, we
can de-global-ify many of the tests, letting them run concurrently
with each other, and just removing global variable complexity.

This does ~half of the LocalBackend ones.

Updates #16998

Change-Id: Iece754e1ef4e49744ccd967fa83629d0dca6f66a
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2025-09-02 18:47:48 -07:00
committed by Brad Fitzpatrick
parent 21f21bd2a2
commit d06d9007a6
3 changed files with 125 additions and 71 deletions
+12 -1
View File
@@ -35,6 +35,7 @@ import (
"tailscale.com/types/netmap"
"tailscale.com/util/mak"
"tailscale.com/util/must"
"tailscale.com/util/syspolicy/policyclient"
"tailscale.com/wgengine"
)
@@ -870,7 +871,7 @@ func mustCreateURL(t *testing.T, u string) url.URL {
return *uParsed
}
func newTestBackend(t *testing.T) *LocalBackend {
func newTestBackend(t *testing.T, opts ...any) *LocalBackend {
var logf logger.Logf = logger.Discard
const debug = true
if debug {
@@ -878,6 +879,16 @@ func newTestBackend(t *testing.T) *LocalBackend {
}
sys := tsd.NewSystem()
for _, o := range opts {
switch v := o.(type) {
case policyclient.Client:
sys.PolicyClient.Set(v)
default:
panic(fmt.Sprintf("unsupported option type %T", v))
}
}
e, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
SetSubsystem: sys.Set,
HealthTracker: sys.HealthTracker(),