Add testname identifier to hs container
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
835288d864
commit
46df219ed3
4 changed files with 32 additions and 14 deletions
|
@ -10,6 +10,8 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/juanfont/headscale/integration/hsic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errParseAuthPage = errors.New("failed to parse auth page")
|
var errParseAuthPage = errors.New("failed to parse auth page")
|
||||||
|
@ -35,7 +37,7 @@ func TestAuthWebFlowAuthenticationPingAll(t *testing.T) {
|
||||||
"namespace2": len(TailscaleVersions),
|
"namespace2": len(TailscaleVersions),
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("webauthping"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to create headscale environment: %s", err)
|
t.Errorf("failed to create headscale environment: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -76,8 +78,11 @@ func TestAuthWebFlowAuthenticationPingAll(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthWebFlowScenario) CreateHeadscaleEnv(namespaces map[string]int) error {
|
func (s *AuthWebFlowScenario) CreateHeadscaleEnv(
|
||||||
headscale, err := s.Headscale()
|
namespaces map[string]int,
|
||||||
|
opts ...hsic.Option,
|
||||||
|
) error {
|
||||||
|
headscale, err := s.Headscale(opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||||
|
"github.com/juanfont/headscale/integration/hsic"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ func TestNamespaceCommand(t *testing.T) {
|
||||||
"namespace2": 0,
|
"namespace2": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("clins"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headscale, err := scenario.Headscale()
|
headscale, err := scenario.Headscale()
|
||||||
|
@ -117,7 +118,7 @@ func TestPreAuthKeyCommand(t *testing.T) {
|
||||||
namespace: 0,
|
namespace: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("clipak"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headscale, err := scenario.Headscale()
|
headscale, err := scenario.Headscale()
|
||||||
|
@ -257,7 +258,7 @@ func TestPreAuthKeyCommandWithoutExpiry(t *testing.T) {
|
||||||
namespace: 0,
|
namespace: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("clipaknaexp"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headscale, err := scenario.Headscale()
|
headscale, err := scenario.Headscale()
|
||||||
|
@ -322,7 +323,7 @@ func TestPreAuthKeyCommandReusableEphemeral(t *testing.T) {
|
||||||
namespace: 0,
|
namespace: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("clipakresueeph"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headscale, err := scenario.Headscale()
|
headscale, err := scenario.Headscale()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/juanfont/headscale/integration/hsic"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ func TestPingAllByIP(t *testing.T) {
|
||||||
"namespace2": len(TailscaleVersions),
|
"namespace2": len(TailscaleVersions),
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("pingallbyip"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to create headscale environment: %s", err)
|
t.Errorf("failed to create headscale environment: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -77,7 +78,7 @@ func TestPingAllByHostname(t *testing.T) {
|
||||||
"namespace4": len(TailscaleVersions) - 1,
|
"namespace4": len(TailscaleVersions) - 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("pingallbyname"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to create headscale environment: %s", err)
|
t.Errorf("failed to create headscale environment: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -144,7 +145,7 @@ func TestTaildrop(t *testing.T) {
|
||||||
"taildrop": len(TailscaleVersions) - 1,
|
"taildrop": len(TailscaleVersions) - 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("taildrop"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to create headscale environment: %s", err)
|
t.Errorf("failed to create headscale environment: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -271,7 +272,7 @@ func TestResolveMagicDNS(t *testing.T) {
|
||||||
"magicdns2": len(TailscaleVersions) - 1,
|
"magicdns2": len(TailscaleVersions) - 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(spec)
|
err = scenario.CreateHeadscaleEnv(spec, hsic.WithTestName("magicdns"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to create headscale environment: %s", err)
|
t.Errorf("failed to create headscale environment: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,15 @@ func WithPort(port int) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithTestName(testName string) Option {
|
||||||
|
return func(hsic *HeadscaleInContainer) {
|
||||||
|
hash, _ := headscale.GenerateRandomStringDNSSafe(hsicHashLength)
|
||||||
|
|
||||||
|
hostname := fmt.Sprintf("hs-%s-%s", testName, hash)
|
||||||
|
hsic.hostname = hostname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
pool *dockertest.Pool,
|
pool *dockertest.Pool,
|
||||||
network *dockertest.Network,
|
network *dockertest.Network,
|
||||||
|
@ -120,6 +129,8 @@ func New(
|
||||||
opt(hsic)
|
opt(hsic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("NAME: ", hsic.hostname)
|
||||||
|
|
||||||
portProto := fmt.Sprintf("%d/tcp", hsic.port)
|
portProto := fmt.Sprintf("%d/tcp", hsic.port)
|
||||||
|
|
||||||
headscaleBuildOptions := &dockertest.BuildOptions{
|
headscaleBuildOptions := &dockertest.BuildOptions{
|
||||||
|
@ -128,7 +139,7 @@ func New(
|
||||||
}
|
}
|
||||||
|
|
||||||
runOptions := &dockertest.RunOptions{
|
runOptions := &dockertest.RunOptions{
|
||||||
Name: hostname,
|
Name: hsic.hostname,
|
||||||
ExposedPorts: []string{portProto},
|
ExposedPorts: []string{portProto},
|
||||||
Networks: []*dockertest.Network{network},
|
Networks: []*dockertest.Network{network},
|
||||||
// Cmd: []string{"headscale", "serve"},
|
// Cmd: []string{"headscale", "serve"},
|
||||||
|
@ -141,7 +152,7 @@ func New(
|
||||||
// dockertest isnt very good at handling containers that has already
|
// dockertest isnt very good at handling containers that has already
|
||||||
// been created, this is an attempt to make sure this container isnt
|
// been created, this is an attempt to make sure this container isnt
|
||||||
// present.
|
// present.
|
||||||
err = pool.RemoveContainerByName(hostname)
|
err = pool.RemoveContainerByName(hsic.hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -156,7 +167,7 @@ func New(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not start headscale container: %w", err)
|
return nil, fmt.Errorf("could not start headscale container: %w", err)
|
||||||
}
|
}
|
||||||
log.Printf("Created %s container\n", hostname)
|
log.Printf("Created %s container\n", hsic.hostname)
|
||||||
|
|
||||||
hsic.container = container
|
hsic.container = container
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue