Skip to content

Commit

Permalink
Retreive hostnames from headscale, now that they are random
Browse files Browse the repository at this point in the history
kradalby committed May 17, 2022

Unverified

The committer email address is not verified.
1 parent e631c6f commit 9ebeb3d
Showing 2 changed files with 40 additions and 3 deletions.
36 changes: 36 additions & 0 deletions integration_common_test.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 4 additions & 3 deletions integration_embedded_derp_test.go
Original file line number Diff line number Diff line change
@@ -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) {

0 comments on commit 9ebeb3d

Please sign in to comment.