From ca9d37ed9a424308535ebb0500e8ece1807a6abd Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 14 Mar 2025 15:54:45 +0100 Subject: [PATCH] make traceroute func Signed-off-by: Kristoffer Dalby --- integration/route_test.go | 11 +++++++---- integration/tailscale.go | 1 + integration/tsic/tsic.go | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/integration/route_test.go b/integration/route_test.go index be1503e3..56144077 100644 --- a/integration/route_test.go +++ b/integration/route_test.go @@ -1036,6 +1036,10 @@ func assertNodeRouteCount(t *testing.T, node *v1.Node, announced, approved, subn assert.Len(t, node.GetSubnetRoutes(), subnet) } +// TestSubnetRouterMultiNetwork is an evolution of the subnet router test. +// This test will set up multiple docker networks and use two isolated tailscale +// clients and a service available in one of the networks to validate that a +// subnet router is working as expected. func TestSubnetRouterMultiNetwork(t *testing.T) { IntegrationSkip(t) t.Parallel() @@ -1130,8 +1134,7 @@ func TestSubnetRouterMultiNetwork(t *testing.T) { assert.Len(t, nodes, 2) assertNodeRouteCount(t, nodes[0], 1, 1, 1) - // Verify that no routes has been sent to the client, - // they are not yet enabled. + // Verify that the routes have been sent to the client. status, err = user2c.Status() require.NoError(t, err) @@ -1159,8 +1162,8 @@ func TestSubnetRouterMultiNetwork(t *testing.T) { require.NoError(t, err) assert.Len(t, result, 13) - stdout, stderr, err := user2c.Execute([]string{"traceroute", webip.String()}) - assert.Contains(t, stdout+stderr, user1c.MustIPv4().String()) + tr, err := user2c.Traceroute(webip) + assert.Contains(t, tr, user1c.MustIPv4().String()) } // requirePeerSubnetRoutes asserts that the peer has the expected subnet routes. diff --git a/integration/tailscale.go b/integration/tailscale.go index 2b383c2c..804b6cda 100644 --- a/integration/tailscale.go +++ b/integration/tailscale.go @@ -41,6 +41,7 @@ type TailscaleClient interface { WaitForPeers(expected int) error Ping(hostnameOrIP string, opts ...tsic.PingOption) error Curl(url string, opts ...tsic.CurlOption) (string, error) + Traceroute(netip.Addr) (string, error) ID() string ReadFile(path string) ([]byte, error) diff --git a/integration/tsic/tsic.go b/integration/tsic/tsic.go index 18373fc3..d1313ecb 100644 --- a/integration/tsic/tsic.go +++ b/integration/tsic/tsic.go @@ -1130,6 +1130,21 @@ func (t *TailscaleInContainer) Curl(url string, opts ...CurlOption) (string, err return result, nil } +func (t *TailscaleInContainer) Traceroute(ip netip.Addr) (string, error) { + command := []string{ + "traceroute", + ip.String(), + } + + var result string + result, _, err := t.Execute(command) + if err != nil { + return result, err + } + + return result, nil +} + // WriteFile save file inside the Tailscale container. func (t *TailscaleInContainer) WriteFile(path string, data []byte) error { return integrationutil.WriteFileToContainer(t.pool, t.container, path, data)