From 76689c221defb450d20937bfdfa5c669d4110c45 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 24 Oct 2022 14:58:02 +0200 Subject: [PATCH 1/4] remove fixed todo Signed-off-by: Kristoffer Dalby --- integration/tsic/tsic.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integration/tsic/tsic.go b/integration/tsic/tsic.go index 11ce7c4..b748245 100644 --- a/integration/tsic/tsic.go +++ b/integration/tsic/tsic.go @@ -156,7 +156,6 @@ func (t *TailscaleInContainer) Up( return nil } -// TODO(kradalby): Make cached/lazy. func (t *TailscaleInContainer) IPs() ([]netip.Addr, error) { if t.ips != nil && len(t.ips) != 0 { return t.ips, nil From 7015d7291187ed5fd89aa6474ed7762addc63fc2 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 24 Oct 2022 14:59:14 +0200 Subject: [PATCH 2/4] port resolve magicdns test Signed-off-by: Kristoffer Dalby --- integration/general_test.go | 83 +++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/integration/general_test.go b/integration/general_test.go index 7292c45..5edd0ef 100644 --- a/integration/general_test.go +++ b/integration/general_test.go @@ -2,6 +2,7 @@ package integration import ( "fmt" + "strings" "testing" "time" @@ -255,3 +256,85 @@ func TestTaildrop(t *testing.T) { t.Errorf("failed to tear down scenario: %s", err) } } + +func TestResolveMagicDNS(t *testing.T) { + IntegrationSkip(t) + + scenario, err := NewScenario() + if err != nil { + t.Errorf("failed to create scenario: %s", err) + } + + spec := map[string]int{ + // Omit 1.16.2 (-1) because it does not have the FQDN field + "magicdns1": len(TailscaleVersions) - 1, + "magicdns2": len(TailscaleVersions) - 1, + } + + err = scenario.CreateHeadscaleEnv(spec) + if err != nil { + t.Errorf("failed to create headscale environment: %s", err) + } + + allClients, err := scenario.ListTailscaleClients() + if err != nil { + t.Errorf("failed to get clients: %s", err) + } + + err = scenario.WaitForTailscaleSync() + if err != nil { + t.Errorf("failed wait for tailscale clients to be in sync: %s", err) + } + + // Poor mans cache + _, err = scenario.ListTailscaleClientsFQDNs() + if err != nil { + t.Errorf("failed to get FQDNs: %s", err) + } + + _, err = scenario.ListTailscaleClientsIPs() + if err != nil { + t.Errorf("failed to get IPs: %s", err) + } + + for _, client := range allClients { + for _, peer := range allClients { + // It is safe to ignore this error as we handled it when caching it + peerFQDN, _ := peer.FQDN() + + command := []string{ + "tailscale", + "ip", peerFQDN, + } + result, err := client.Execute(command) + if err != nil { + t.Errorf( + "failed to execute resolve/ip command %s from %s: %s", + peerFQDN, + client.Hostname(), + err, + ) + } + + ips, err := peer.IPs() + if err != nil { + t.Errorf( + "failed to get ips for %s: %s", + peer.Hostname(), + err, + ) + } + + for _, ip := range ips { + if !strings.Contains(result, ip.String()) { + t.Errorf("ip %s is not found in \n%s\n", ip.String(), result) + } + } + } + } + + err = scenario.Shutdown() + if err != nil { + t.Errorf("failed to tear down scenario: %s", err) + } +} From 54e3a0d3722aea8ee3265e1ae183bd749d2f58d7 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Tue, 25 Oct 2022 08:44:25 +0200 Subject: [PATCH 3/4] Test with a longer timeout Signed-off-by: Kristoffer Dalby --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 36b6418..cb91e8c 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ test_integration_v2_general: -v $$PWD:$$PWD -w $$PWD/integration \ -v /var/run/docker.sock:/var/run/docker.sock \ golang:1 \ - go test ./... -timeout 30m + go test ./... -timeout 60m coverprofile_func: go tool cover -func=coverage.out From fe4e05b0bcba5ecbccc17ffbb0e341caef6b9886 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Tue, 25 Oct 2022 09:24:05 +0200 Subject: [PATCH 4/4] only print stdout on err Signed-off-by: Kristoffer Dalby --- integration/tsic/tsic.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration/tsic/tsic.go b/integration/tsic/tsic.go index b748245..14c627d 100644 --- a/integration/tsic/tsic.go +++ b/integration/tsic/tsic.go @@ -121,6 +121,10 @@ func (t *TailscaleInContainer) Execute( if err != nil { log.Printf("command stderr: %s\n", stderr) + if stdout != "" { + log.Printf("command stdout: %s\n", stdout) + } + if strings.Contains(stderr, "NeedsLogin") { return "", errTailscaleNotLoggedIn } @@ -128,10 +132,6 @@ func (t *TailscaleInContainer) Execute( return "", err } - if stdout != "" { - log.Printf("command stdout: %s\n", stdout) - } - return stdout, nil }