mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
Formatting of integration tests
This commit is contained in:
parent
e8e573de62
commit
8218ef96ef
@ -8,16 +8,17 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"inet.af/netaddr"
|
|
||||||
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DOCKER_EXECUTE_TIMEOUT = 10 * time.Second
|
const DOCKER_EXECUTE_TIMEOUT = 10 * time.Second
|
||||||
|
|
||||||
var IpPrefix4 = netaddr.MustParseIPPrefix("100.64.0.0/10")
|
var (
|
||||||
var IpPrefix6 = netaddr.MustParseIPPrefix("fd7a:115c:a1e0::/48")
|
IpPrefix4 = netaddr.MustParseIPPrefix("100.64.0.0/10")
|
||||||
|
IpPrefix6 = netaddr.MustParseIPPrefix("fd7a:115c:a1e0::/48")
|
||||||
|
)
|
||||||
|
|
||||||
type ExecuteCommandConfig struct {
|
type ExecuteCommandConfig struct {
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
@ -375,7 +375,7 @@ func (s *IntegrationTestSuite) TestGetIpAddresses() {
|
|||||||
ips, err := getIPs(scales.tailscales)
|
ips, err := getIPs(scales.tailscales)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
for hostname, _ := range scales.tailscales {
|
for hostname := range scales.tailscales {
|
||||||
ips := ips[hostname]
|
ips := ips[hostname]
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
s.T().Run(hostname, func(t *testing.T) {
|
s.T().Run(hostname, func(t *testing.T) {
|
||||||
@ -464,32 +464,33 @@ func (s *IntegrationTestSuite) TestPingAllPeersByAddress() {
|
|||||||
if peername == hostname {
|
if peername == hostname {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.T().Run(fmt.Sprintf("%s-%s-%d", hostname, peername, i), func(t *testing.T) {
|
s.T().
|
||||||
// We are only interested in "direct ping" which means what we
|
Run(fmt.Sprintf("%s-%s-%d", hostname, peername, i), func(t *testing.T) {
|
||||||
// might need a couple of more attempts before reaching the node.
|
// We are only interested in "direct ping" which means what we
|
||||||
command := []string{
|
// might need a couple of more attempts before reaching the node.
|
||||||
"tailscale", "ping",
|
command := []string{
|
||||||
"--timeout=1s",
|
"tailscale", "ping",
|
||||||
"--c=10",
|
"--timeout=1s",
|
||||||
"--until-direct=true",
|
"--c=10",
|
||||||
ip.String(),
|
"--until-direct=true",
|
||||||
}
|
ip.String(),
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"Pinging from %s to %s (%s)\n",
|
"Pinging from %s to %s (%s)\n",
|
||||||
hostname,
|
hostname,
|
||||||
peername,
|
peername,
|
||||||
ip,
|
ip,
|
||||||
)
|
)
|
||||||
result, err := ExecuteCommand(
|
result, err := ExecuteCommand(
|
||||||
&tailscale,
|
&tailscale,
|
||||||
command,
|
command,
|
||||||
[]string{},
|
[]string{},
|
||||||
)
|
)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
fmt.Printf("Result for %s: %s\n", hostname, result)
|
fmt.Printf("Result for %s: %s\n", hostname, result)
|
||||||
assert.Contains(t, result, "pong")
|
assert.Contains(t, result, "pong")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -569,32 +570,33 @@ func (s *IntegrationTestSuite) TestSharedNodes() {
|
|||||||
if peername == hostname {
|
if peername == hostname {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.T().Run(fmt.Sprintf("%s-%s-%d", hostname, peername, i), func(t *testing.T) {
|
s.T().
|
||||||
// We are only interested in "direct ping" which means what we
|
Run(fmt.Sprintf("%s-%s-%d", hostname, peername, i), func(t *testing.T) {
|
||||||
// might need a couple of more attempts before reaching the node.
|
// We are only interested in "direct ping" which means what we
|
||||||
command := []string{
|
// might need a couple of more attempts before reaching the node.
|
||||||
"tailscale", "ping",
|
command := []string{
|
||||||
"--timeout=15s",
|
"tailscale", "ping",
|
||||||
"--c=20",
|
"--timeout=15s",
|
||||||
"--until-direct=true",
|
"--c=20",
|
||||||
ip.String(),
|
"--until-direct=true",
|
||||||
}
|
ip.String(),
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"Pinging from %s to %s (%s)\n",
|
"Pinging from %s to %s (%s)\n",
|
||||||
hostname,
|
hostname,
|
||||||
peername,
|
peername,
|
||||||
ip,
|
ip,
|
||||||
)
|
)
|
||||||
result, err := ExecuteCommand(
|
result, err := ExecuteCommand(
|
||||||
&tailscale,
|
&tailscale,
|
||||||
command,
|
command,
|
||||||
[]string{},
|
[]string{},
|
||||||
)
|
)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
fmt.Printf("Result for %s: %s\n", hostname, result)
|
fmt.Printf("Result for %s: %s\n", hostname, result)
|
||||||
assert.Contains(t, result, "pong")
|
assert.Contains(t, result, "pong")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -625,7 +627,7 @@ func (s *IntegrationTestSuite) TestTailDrop() {
|
|||||||
[]string{},
|
[]string{},
|
||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
for peername, _ := range ips {
|
for peername := range ips {
|
||||||
if peername == hostname {
|
if peername == hostname {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -705,7 +707,7 @@ func (s *IntegrationTestSuite) TestPingAllPeersByHostname() {
|
|||||||
ips, err := getIPs(scales.tailscales)
|
ips, err := getIPs(scales.tailscales)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
for hostname, tailscale := range scales.tailscales {
|
for hostname, tailscale := range scales.tailscales {
|
||||||
for peername, _ := range ips {
|
for peername := range ips {
|
||||||
if peername == hostname {
|
if peername == hostname {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -774,7 +776,9 @@ func (s *IntegrationTestSuite) TestMagicDNS() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIPs(tailscales map[string]dockertest.Resource) (map[string][]netaddr.IP, error) {
|
func getIPs(
|
||||||
|
tailscales map[string]dockertest.Resource,
|
||||||
|
) (map[string][]netaddr.IP, error) {
|
||||||
ips := make(map[string][]netaddr.IP)
|
ips := make(map[string][]netaddr.IP)
|
||||||
for hostname, tailscale := range tailscales {
|
for hostname, tailscale := range tailscales {
|
||||||
command := []string{"tailscale", "ip"}
|
command := []string{"tailscale", "ip"}
|
||||||
|
Loading…
Reference in New Issue
Block a user