Skip to content

Commit

Permalink
Test magic dns with the correct urls
Browse files Browse the repository at this point in the history
  • Loading branch information
kradalby committed May 18, 2022
1 parent 4a9d3be commit 77ceeaf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
34 changes: 34 additions & 0 deletions integration_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,37 @@ func getDNSNames(

return hostnames, nil
}

func getMagicFQDN(
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] = fmt.Sprintf("%s.%s.headscale.net", listAll[index].GetGivenName(), listAll[index].GetNamespace().GetName())
}

return hostnames, nil
}
14 changes: 8 additions & 6 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,22 +636,24 @@ func (s *IntegrationTestSuite) TestPingAllPeersByHostname() {
}

func (s *IntegrationTestSuite) TestMagicDNS() {
for namespace, scales := range s.namespaces {
ips, err := getIPs(scales.tailscales)
assert.Nil(s.T(), err)
hostnames, err := getMagicFQDN(&s.headscale)
assert.Nil(s.T(), err)

log.Printf("Resolved hostnames: %#v", hostnames)

hostnames, err := getDNSNames(&s.headscale)
for _, scales := range s.namespaces {
ips, err := getIPs(scales.tailscales)
assert.Nil(s.T(), err)

for hostname, tailscale := range scales.tailscales {
for _, peername := range hostnames {
if strings.Contains(peername, hostname) {
continue
}

s.T().Run(fmt.Sprintf("%s-%s", hostname, peername), func(t *testing.T) {
command := []string{
"tailscale", "ip",
fmt.Sprintf("%s.%s.headscale.net", peername, namespace),
"tailscale", "ip", peername,
}

log.Printf(
Expand Down

0 comments on commit 77ceeaf

Please sign in to comment.