mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-25 01:07:52 +00:00
Retreive hostnames from headscale, now that they are random
This commit is contained in:
parent
e631c6f7e0
commit
9ebeb3d7e4
@ -5,10 +5,12 @@ package headscale
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||||
"github.com/ory/dockertest/v3"
|
"github.com/ory/dockertest/v3"
|
||||||
"github.com/ory/dockertest/v3/docker"
|
"github.com/ory/dockertest/v3/docker"
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
@ -212,3 +214,37 @@ func getIPs(
|
|||||||
|
|
||||||
return ips, nil
|
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
|
||||||
|
}
|
||||||
|
@ -353,11 +353,12 @@ func (s *IntegrationDERPTestSuite) saveLog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationDERPTestSuite) TestPingAllPeersByHostname() {
|
func (s *IntegrationDERPTestSuite) TestPingAllPeersByHostname() {
|
||||||
ips, err := getIPs(s.tailscales)
|
hostnames, err := getDNSNames(&s.headscale)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
for hostname, tailscale := range s.tailscales {
|
for hostname, tailscale := range s.tailscales {
|
||||||
for peername := range ips {
|
for _, peername := range hostnames {
|
||||||
if peername == hostname {
|
if strings.Contains(peername, hostname) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.T().Run(fmt.Sprintf("%s-%s", hostname, peername), func(t *testing.T) {
|
s.T().Run(fmt.Sprintf("%s-%s", hostname, peername), func(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user