From 456479eaa16bda0c2867159ba6be098487a01e82 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 10 Nov 2022 17:06:10 +0100 Subject: [PATCH] Rename and move wait for headscale Signed-off-by: Kristoffer Dalby --- integration/cli_test.go | 24 ++++++++++++------------ integration/scenario.go | 20 +++++++++++--------- integration/scenario_test.go | 6 +++--- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/integration/cli_test.go b/integration/cli_test.go index 43e5551d..5045f2d2 100644 --- a/integration/cli_test.go +++ b/integration/cli_test.go @@ -40,7 +40,7 @@ func TestNamespaceCommand(t *testing.T) { assert.NoError(t, err) var listNamespaces []v1.Namespace - err = executeAndUnmarshal(scenario.Headscale(), + err = executeAndUnmarshal(scenario.MustHeadscale(), []string{ "headscale", "namespaces", @@ -61,7 +61,7 @@ func TestNamespaceCommand(t *testing.T) { result, ) - _, err = scenario.Headscale().Execute( + _, err = scenario.MustHeadscale().Execute( []string{ "headscale", "namespaces", @@ -75,7 +75,7 @@ func TestNamespaceCommand(t *testing.T) { assert.NoError(t, err) var listAfterRenameNamespaces []v1.Namespace - err = executeAndUnmarshal(scenario.Headscale(), + err = executeAndUnmarshal(scenario.MustHeadscale(), []string{ "headscale", "namespaces", @@ -123,7 +123,7 @@ func TestPreAuthKeyCommand(t *testing.T) { for index := 0; index < count; index++ { var preAuthKey v1.PreAuthKey err := executeAndUnmarshal( - scenario.Headscale(), + scenario.MustHeadscale(), []string{ "headscale", "preauthkeys", @@ -149,7 +149,7 @@ func TestPreAuthKeyCommand(t *testing.T) { var listedPreAuthKeys []v1.PreAuthKey err = executeAndUnmarshal( - scenario.Headscale(), + scenario.MustHeadscale(), []string{ "headscale", "preauthkeys", @@ -202,7 +202,7 @@ func TestPreAuthKeyCommand(t *testing.T) { } // Test key expiry - _, err = scenario.Headscale().Execute( + _, err = scenario.MustHeadscale().Execute( []string{ "headscale", "preauthkeys", @@ -216,7 +216,7 @@ func TestPreAuthKeyCommand(t *testing.T) { var listedPreAuthKeysAfterExpire []v1.PreAuthKey err = executeAndUnmarshal( - scenario.Headscale(), + scenario.MustHeadscale(), []string{ "headscale", "preauthkeys", @@ -256,7 +256,7 @@ func TestPreAuthKeyCommandWithoutExpiry(t *testing.T) { var preAuthKey v1.PreAuthKey err = executeAndUnmarshal( - scenario.Headscale(), + scenario.MustHeadscale(), []string{ "headscale", "preauthkeys", @@ -273,7 +273,7 @@ func TestPreAuthKeyCommandWithoutExpiry(t *testing.T) { var listedPreAuthKeys []v1.PreAuthKey err = executeAndUnmarshal( - scenario.Headscale(), + scenario.MustHeadscale(), []string{ "headscale", "preauthkeys", @@ -318,7 +318,7 @@ func TestPreAuthKeyCommandReusableEphemeral(t *testing.T) { var preAuthReusableKey v1.PreAuthKey err = executeAndUnmarshal( - scenario.Headscale(), + scenario.MustHeadscale(), []string{ "headscale", "preauthkeys", @@ -335,7 +335,7 @@ func TestPreAuthKeyCommandReusableEphemeral(t *testing.T) { var preAuthEphemeralKey v1.PreAuthKey err = executeAndUnmarshal( - scenario.Headscale(), + scenario.MustHeadscale(), []string{ "headscale", "preauthkeys", @@ -355,7 +355,7 @@ func TestPreAuthKeyCommandReusableEphemeral(t *testing.T) { var listedPreAuthKeys []v1.PreAuthKey err = executeAndUnmarshal( - scenario.Headscale(), + scenario.MustHeadscale(), []string{ "headscale", "preauthkeys", diff --git a/integration/scenario.go b/integration/scenario.go index 714c0584..62ad7223 100644 --- a/integration/scenario.go +++ b/integration/scenario.go @@ -156,12 +156,19 @@ func (s *Scenario) StartHeadscale(opts ...hsic.Option) error { return fmt.Errorf("failed to create headscale container: %w", err) } + err = headscale.WaitForReady() + if err != nil { + return err + } + s.controlServers["headscale"] = headscale return nil } -func (s *Scenario) Headscale() *hsic.HeadscaleInContainer { +// MustHeadscale returns the headscale unit of a scenario, it will crash if it +// is not available. +func (s *Scenario) MustHeadscale() *hsic.HeadscaleInContainer { //nolint return s.controlServers["headscale"].(*hsic.HeadscaleInContainer) } @@ -220,8 +227,8 @@ func (s *Scenario) CreateTailscaleNodesInNamespace( s.pool, version, s.network, - tsic.WithHeadscaleTLS(s.Headscale().GetCert()), - tsic.WithHeadscaleName(s.Headscale().GetHostname()), + tsic.WithHeadscaleTLS(s.MustHeadscale().GetCert()), + tsic.WithHeadscaleName(s.MustHeadscale().GetHostname()), ) if err != nil { // return fmt.Errorf("failed to add tailscale node: %w", err) @@ -312,11 +319,6 @@ func (s *Scenario) CreateHeadscaleEnv(namespaces map[string]int, opts ...hsic.Op return err } - err = s.Headscale().WaitForReady() - if err != nil { - return err - } - for namespaceName, clientCount := range namespaces { err = s.CreateNamespace(namespaceName) if err != nil { @@ -333,7 +335,7 @@ func (s *Scenario) CreateHeadscaleEnv(namespaces map[string]int, opts ...hsic.Op return err } - err = s.RunTailscaleUp(namespaceName, s.Headscale().GetEndpoint(), key.GetKey()) + err = s.RunTailscaleUp(namespaceName, s.MustHeadscale().GetEndpoint(), key.GetKey()) if err != nil { return err } diff --git a/integration/scenario_test.go b/integration/scenario_test.go index 2d8cb1a5..d762d4c8 100644 --- a/integration/scenario_test.go +++ b/integration/scenario_test.go @@ -39,7 +39,7 @@ func TestHeadscale(t *testing.T) { t.Errorf("failed to create start headcale: %s", err) } - err = scenario.Headscale().WaitForReady() + err = scenario.MustHeadscale().WaitForReady() if err != nil { t.Errorf("headscale failed to become ready: %s", err) } @@ -122,7 +122,7 @@ func TestTailscaleNodesJoiningHeadcale(t *testing.T) { t.Errorf("failed to create start headcale: %s", err) } - headscale := scenario.Headscale() + headscale := scenario.MustHeadscale() err = headscale.WaitForReady() if err != nil { t.Errorf("headscale failed to become ready: %s", err) @@ -157,7 +157,7 @@ func TestTailscaleNodesJoiningHeadcale(t *testing.T) { t.Errorf("failed to create preauthkey: %s", err) } - err = scenario.RunTailscaleUp(namespace, scenario.Headscale().GetEndpoint(), key.GetKey()) + err = scenario.RunTailscaleUp(namespace, scenario.MustHeadscale().GetEndpoint(), key.GetKey()) if err != nil { t.Errorf("failed to login: %s", err) }