From 9ebeb3d7e4612d967a6df44c5c4d1486fd462a59 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Tue, 17 May 2022 22:11:51 +0200 Subject: [PATCH] Retreive hostnames from headscale, now that they are random --- integration_common_test.go | 36 +++++++++++++++++++++++++++++++ integration_embedded_derp_test.go | 7 +++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/integration_common_test.go b/integration_common_test.go index d5ff7e8f..a7b948bb 100644 --- a/integration_common_test.go +++ b/integration_common_test.go @@ -5,10 +5,12 @@ package headscale import ( "bytes" + "encoding/json" "fmt" "strings" "time" + v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" "inet.af/netaddr" @@ -212,3 +214,37 @@ func getIPs( return ips, nil } + +func getDNSNames( + headscale *dockertest.Resource, +) ([]string, error) { + + listAllResult, err := ExecuteCommand( + headscale, + []string{ + "headscale", + "nodes", + "list", + "--output", + "json", + }, + []string{}, + ) + if err != nil { + return nil, err + } + + var listAll []v1.Machine + err = json.Unmarshal([]byte(listAllResult), &listAll) + if err != nil { + return nil, err + } + + hostnames := make([]string, len(listAll)) + + for index := range listAll { + hostnames[index] = listAll[index].GetGivenName() + } + + return hostnames, nil +} diff --git a/integration_embedded_derp_test.go b/integration_embedded_derp_test.go index 5e42fd75..69b427f7 100644 --- a/integration_embedded_derp_test.go +++ b/integration_embedded_derp_test.go @@ -353,11 +353,12 @@ func (s *IntegrationDERPTestSuite) saveLog( } func (s *IntegrationDERPTestSuite) TestPingAllPeersByHostname() { - ips, err := getIPs(s.tailscales) + hostnames, err := getDNSNames(&s.headscale) assert.Nil(s.T(), err) + for hostname, tailscale := range s.tailscales { - for peername := range ips { - if peername == hostname { + for _, peername := range hostnames { + if strings.Contains(peername, hostname) { continue } s.T().Run(fmt.Sprintf("%s-%s", hostname, peername), func(t *testing.T) {