From db2f37d7c63d01cf37892dc94e5704173b6b3ae5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 17 Sep 2023 04:17:59 -0500 Subject: [PATCH] ipn/ipnlocal: add some test accessors Updates tailscale/corp#12990 Change-Id: I82801ac4c003d2c7e1352c514adb908dbf01be87 Signed-off-by: Brad Fitzpatrick --- cmd/tailscaled/depaware.txt | 2 +- ipn/ipnlocal/local.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index 94e44ddd8..f56dbf600 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -387,7 +387,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de golang.org/x/crypto/salsa20/salsa from golang.org/x/crypto/nacl/box+ LD golang.org/x/crypto/ssh from tailscale.com/ssh/tailssh+ golang.org/x/exp/constraints from github.com/dblohm7/wingoes/pe+ - golang.org/x/exp/maps from tailscale.com/wgengine/magicsock + golang.org/x/exp/maps from tailscale.com/wgengine/magicsock+ golang.org/x/net/bpf from github.com/mdlayher/genetlink+ golang.org/x/net/dns/dnsmessage from net+ golang.org/x/net/http/httpguts from golang.org/x/net/http2+ diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 97894fd32..a413e00bf 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -31,6 +31,7 @@ import ( "go4.org/mem" "go4.org/netipx" + xmaps "golang.org/x/exp/maps" "gvisor.dev/gvisor/pkg/tcpip" "tailscale.com/client/tailscale/apitype" "tailscale.com/control/controlclient" @@ -1335,6 +1336,27 @@ func (b *LocalBackend) SetControlClientGetterForTesting(newControlClient func(co b.ccGen = newControlClient } +// NodeViewByIDForTest returns the state of the node with the given ID +// for integration tests in another repo. +func (b *LocalBackend) NodeViewByIDForTest(id tailcfg.NodeID) (_ tailcfg.NodeView, ok bool) { + b.mu.Lock() + defer b.mu.Unlock() + n, ok := b.peers[id] + return n, ok +} + +// PeersForTest returns all the current peers, sorted by Node.ID, +// for integration tests in another repo. +func (b *LocalBackend) PeersForTest() []tailcfg.NodeView { + b.mu.Lock() + defer b.mu.Unlock() + ret := xmaps.Values(b.peers) + slices.SortFunc(ret, func(a, b tailcfg.NodeView) int { + return cmpx.Compare(a.ID(), b.ID()) + }) + return ret +} + func (b *LocalBackend) getNewControlClientFunc() clientGen { b.mu.Lock() defer b.mu.Unlock()