Rename and move wait for headscale

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2022-11-10 17:06:10 +01:00 committed by Juan Font
parent cb87852825
commit 456479eaa1
3 changed files with 26 additions and 24 deletions

View File

@ -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",

View File

@ -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
}

View File

@ -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)
}