mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-24 08:47:49 +00:00
Add version support to integration support
This commit adds a list of tailscale versions to use in the integration test. An equal distribution of versions will be used across the clients.
This commit is contained in:
parent
bf26e37e0e
commit
d68d201722
@ -1,9 +1,11 @@
|
|||||||
FROM ubuntu:latest
|
FROM ubuntu:latest
|
||||||
|
|
||||||
|
ARG TAILSCALE_VERSION=now
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get install -y gnupg curl \
|
&& apt-get install -y gnupg curl \
|
||||||
&& curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/focal.gpg | apt-key add - \
|
&& curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/focal.gpg | apt-key add - \
|
||||||
&& curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/focal.list | tee /etc/apt/sources.list.d/tailscale.list \
|
&& curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/focal.list | tee /etc/apt/sources.list.d/tailscale.list \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get install -y tailscale \
|
&& apt-get install -y tailscale=${TAILSCALE_VERSION} \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build integration
|
||||||
// +build integration
|
// +build integration
|
||||||
|
|
||||||
package headscale
|
package headscale
|
||||||
@ -23,14 +24,20 @@ import (
|
|||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
)
|
)
|
||||||
|
|
||||||
var integrationTmpDir string
|
var (
|
||||||
var ih Headscale
|
integrationTmpDir string
|
||||||
|
ih Headscale
|
||||||
|
)
|
||||||
|
|
||||||
var pool dockertest.Pool
|
var (
|
||||||
var network dockertest.Network
|
pool dockertest.Pool
|
||||||
var headscale dockertest.Resource
|
network dockertest.Network
|
||||||
var tailscaleCount int = 25
|
headscale dockertest.Resource
|
||||||
var tailscales map[string]dockertest.Resource
|
tailscaleCount int = 25
|
||||||
|
tailscales map[string]dockertest.Resource
|
||||||
|
)
|
||||||
|
|
||||||
|
var tailscaleVersions = []string{"1.14.3", "1.12.3"}
|
||||||
|
|
||||||
type IntegrationTestSuite struct {
|
type IntegrationTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
@ -119,12 +126,12 @@ func saveLog(resource *dockertest.Resource, basePath string) error {
|
|||||||
|
|
||||||
fmt.Printf("Saving logs for %s to %s\n", resource.Container.Name, basePath)
|
fmt.Printf("Saving logs for %s to %s\n", resource.Container.Name, basePath)
|
||||||
|
|
||||||
err = ioutil.WriteFile(path.Join(basePath, resource.Container.Name+".stdout.log"), []byte(stdout.String()), 0644)
|
err = ioutil.WriteFile(path.Join(basePath, resource.Container.Name+".stdout.log"), []byte(stdout.String()), 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(path.Join(basePath, resource.Container.Name+".stderr.log"), []byte(stdout.String()), 0644)
|
err = ioutil.WriteFile(path.Join(basePath, resource.Container.Name+".stderr.log"), []byte(stdout.String()), 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -140,6 +147,32 @@ func dockerRestartPolicy(config *docker.HostConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tailscaleContainer(identifier string, version string) (string, *dockertest.Resource) {
|
||||||
|
tailscaleBuildOptions := &dockertest.BuildOptions{
|
||||||
|
Dockerfile: "Dockerfile.tailscale",
|
||||||
|
ContextDir: ".",
|
||||||
|
BuildArgs: []docker.BuildArg{
|
||||||
|
{
|
||||||
|
Name: "TAILSCALE_VERSION",
|
||||||
|
Value: version,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
hostname := fmt.Sprintf("tailscale-%s-%s", strings.Replace(version, ".", "-", -1), identifier)
|
||||||
|
tailscaleOptions := &dockertest.RunOptions{
|
||||||
|
Name: hostname,
|
||||||
|
Networks: []*dockertest.Network{&network},
|
||||||
|
Cmd: []string{"tailscaled", "--tun=userspace-networking", "--socks5-server=localhost:1055"},
|
||||||
|
}
|
||||||
|
|
||||||
|
pts, err := pool.BuildAndRunWithBuildOptions(tailscaleBuildOptions, tailscaleOptions, dockerRestartPolicy)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not start resource: %s", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Created %s container\n", hostname)
|
||||||
|
return hostname, pts
|
||||||
|
}
|
||||||
|
|
||||||
func (s *IntegrationTestSuite) SetupSuite() {
|
func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
var err error
|
var err error
|
||||||
h = Headscale{
|
h = Headscale{
|
||||||
@ -164,11 +197,6 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
|||||||
ContextDir: ".",
|
ContextDir: ".",
|
||||||
}
|
}
|
||||||
|
|
||||||
tailscaleBuildOptions := &dockertest.BuildOptions{
|
|
||||||
Dockerfile: "Dockerfile.tailscale",
|
|
||||||
ContextDir: ".",
|
|
||||||
}
|
|
||||||
|
|
||||||
currentPath, err := os.Getwd()
|
currentPath, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not determine current path: %s", err)
|
log.Fatalf("Could not determine current path: %s", err)
|
||||||
@ -183,7 +211,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
|||||||
Networks: []*dockertest.Network{&network},
|
Networks: []*dockertest.Network{&network},
|
||||||
Cmd: []string{"headscale", "serve"},
|
Cmd: []string{"headscale", "serve"},
|
||||||
PortBindings: map[docker.Port][]docker.PortBinding{
|
PortBindings: map[docker.Port][]docker.PortBinding{
|
||||||
"8080/tcp": []docker.PortBinding{{HostPort: "8080"}},
|
"8080/tcp": {{HostPort: "8080"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,19 +226,10 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
|||||||
fmt.Println("Creating tailscale containers")
|
fmt.Println("Creating tailscale containers")
|
||||||
tailscales = make(map[string]dockertest.Resource)
|
tailscales = make(map[string]dockertest.Resource)
|
||||||
for i := 0; i < tailscaleCount; i++ {
|
for i := 0; i < tailscaleCount; i++ {
|
||||||
hostname := fmt.Sprintf("tailscale%d", i)
|
version := tailscaleVersions[i%len(tailscaleVersions)]
|
||||||
tailscaleOptions := &dockertest.RunOptions{
|
|
||||||
Name: hostname,
|
|
||||||
Networks: []*dockertest.Network{&network},
|
|
||||||
Cmd: []string{"tailscaled", "--tun=userspace-networking", "--socks5-server=localhost:1055"},
|
|
||||||
}
|
|
||||||
|
|
||||||
if pts, err := pool.BuildAndRunWithBuildOptions(tailscaleBuildOptions, tailscaleOptions, dockerRestartPolicy); err == nil {
|
hostname, container := tailscaleContainer(fmt.Sprint(i), version)
|
||||||
tailscales[hostname] = *pts
|
tailscales[hostname] = *container
|
||||||
} else {
|
|
||||||
log.Fatalf("Could not start resource: %s", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Created %s container\n", hostname)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Waiting for headscale to be ready")
|
fmt.Println("Waiting for headscale to be ready")
|
||||||
@ -288,7 +307,7 @@ func (s *IntegrationTestSuite) TestListNodes() {
|
|||||||
lines := strings.Split(result, "\n")
|
lines := strings.Split(result, "\n")
|
||||||
assert.Equal(s.T(), len(tailscales), len(lines)-2)
|
assert.Equal(s.T(), len(tailscales), len(lines)-2)
|
||||||
|
|
||||||
for hostname, _ := range tailscales {
|
for hostname := range tailscales {
|
||||||
assert.Contains(s.T(), result, hostname)
|
assert.Contains(s.T(), result, hostname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,7 +317,7 @@ func (s *IntegrationTestSuite) TestGetIpAddresses() {
|
|||||||
ips, err := getIPs()
|
ips, err := getIPs()
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
for hostname, _ := range tailscales {
|
for hostname := range tailscales {
|
||||||
s.T().Run(hostname, func(t *testing.T) {
|
s.T().Run(hostname, func(t *testing.T) {
|
||||||
ip := ips[hostname]
|
ip := ips[hostname]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user