mirror of
https://github.com/juanfont/headscale.git
synced 2026-08-15 20:00:43 +09:00
integration: port the new CLI command tests to the HTTP client
#3326 added per-resource CLI coverage decoding into the proto types; convert the transport to the apiv1/ogen types, keeping every command and assertion. Drop the now-duplicate health and node-routes tests #3326 covers more fully.
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
apiv1 "github.com/juanfont/headscale/gen/api/v1"
|
||||
"github.com/juanfont/headscale/integration/hsic"
|
||||
"github.com/juanfont/headscale/integration/integrationutil"
|
||||
"github.com/juanfont/headscale/integration/tsic"
|
||||
@@ -34,12 +34,12 @@ func TestPreAuthKeyCommand(t *testing.T) {
|
||||
headscale, err := scenario.Headscale()
|
||||
require.NoError(t, err)
|
||||
|
||||
keys := make([]*v1.PreAuthKey, count)
|
||||
keys := make([]*apiv1.PreAuthKey, count)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
for index := range count {
|
||||
var preAuthKey v1.PreAuthKey
|
||||
var preAuthKey apiv1.PreAuthKey
|
||||
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
err := executeAndUnmarshal(
|
||||
@@ -68,7 +68,7 @@ func TestPreAuthKeyCommand(t *testing.T) {
|
||||
|
||||
assert.Len(t, keys, 3)
|
||||
|
||||
var listedPreAuthKeys []v1.PreAuthKey
|
||||
var listedPreAuthKeys []apiv1.PreAuthKey
|
||||
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
err = executeAndUnmarshal(
|
||||
@@ -90,34 +90,34 @@ func TestPreAuthKeyCommand(t *testing.T) {
|
||||
|
||||
assert.Equal(
|
||||
t,
|
||||
[]uint64{keys[0].GetId(), keys[1].GetId(), keys[2].GetId()},
|
||||
[]uint64{keys[0].GetID().Or(0), keys[1].GetID().Or(0), keys[2].GetID().Or(0)},
|
||||
[]uint64{
|
||||
listedPreAuthKeys[1].GetId(),
|
||||
listedPreAuthKeys[2].GetId(),
|
||||
listedPreAuthKeys[3].GetId(),
|
||||
listedPreAuthKeys[1].GetID().Or(0),
|
||||
listedPreAuthKeys[2].GetID().Or(0),
|
||||
listedPreAuthKeys[3].GetID().Or(0),
|
||||
},
|
||||
)
|
||||
|
||||
// New keys show prefix after listing, so check the created keys instead
|
||||
assert.NotEmpty(t, keys[0].GetKey())
|
||||
assert.NotEmpty(t, keys[1].GetKey())
|
||||
assert.NotEmpty(t, keys[2].GetKey())
|
||||
assert.NotEmpty(t, keys[0].GetKey().Or(""))
|
||||
assert.NotEmpty(t, keys[1].GetKey().Or(""))
|
||||
assert.NotEmpty(t, keys[2].GetKey().Or(""))
|
||||
|
||||
assert.True(t, listedPreAuthKeys[1].GetExpiration().AsTime().After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeys[2].GetExpiration().AsTime().After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeys[3].GetExpiration().AsTime().After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeys[1].GetExpiration().Value.After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeys[2].GetExpiration().Value.After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeys[3].GetExpiration().Value.After(time.Now()))
|
||||
|
||||
assert.True(
|
||||
t,
|
||||
listedPreAuthKeys[1].GetExpiration().AsTime().Before(time.Now().Add(time.Hour*26)),
|
||||
listedPreAuthKeys[1].GetExpiration().Value.Before(time.Now().Add(time.Hour*26)),
|
||||
)
|
||||
assert.True(
|
||||
t,
|
||||
listedPreAuthKeys[2].GetExpiration().AsTime().Before(time.Now().Add(time.Hour*26)),
|
||||
listedPreAuthKeys[2].GetExpiration().Value.Before(time.Now().Add(time.Hour*26)),
|
||||
)
|
||||
assert.True(
|
||||
t,
|
||||
listedPreAuthKeys[3].GetExpiration().AsTime().Before(time.Now().Add(time.Hour*26)),
|
||||
listedPreAuthKeys[3].GetExpiration().Value.Before(time.Now().Add(time.Hour*26)),
|
||||
)
|
||||
|
||||
for index := range listedPreAuthKeys {
|
||||
@@ -139,12 +139,12 @@ func TestPreAuthKeyCommand(t *testing.T) {
|
||||
"preauthkeys",
|
||||
"expire",
|
||||
"--id",
|
||||
strconv.FormatUint(keys[0].GetId(), 10),
|
||||
strconv.FormatUint(keys[0].GetID().Or(0), 10),
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
var listedPreAuthKeysAfterExpire []v1.PreAuthKey
|
||||
var listedPreAuthKeysAfterExpire []apiv1.PreAuthKey
|
||||
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
err = executeAndUnmarshal(
|
||||
@@ -161,9 +161,9 @@ func TestPreAuthKeyCommand(t *testing.T) {
|
||||
assert.NoError(c, err)
|
||||
}, integrationutil.ScaledTimeout(10*time.Second), integrationutil.FastPoll, "Waiting for preauth keys list after expire")
|
||||
|
||||
assert.True(t, listedPreAuthKeysAfterExpire[1].GetExpiration().AsTime().Before(time.Now()))
|
||||
assert.True(t, listedPreAuthKeysAfterExpire[2].GetExpiration().AsTime().After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeysAfterExpire[3].GetExpiration().AsTime().After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeysAfterExpire[1].GetExpiration().Value.Before(time.Now()))
|
||||
assert.True(t, listedPreAuthKeysAfterExpire[2].GetExpiration().Value.After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeysAfterExpire[3].GetExpiration().Value.After(time.Now()))
|
||||
}
|
||||
|
||||
func TestPreAuthKeyCommandWithoutExpiry(t *testing.T) {
|
||||
@@ -185,7 +185,7 @@ func TestPreAuthKeyCommandWithoutExpiry(t *testing.T) {
|
||||
headscale, err := scenario.Headscale()
|
||||
require.NoError(t, err)
|
||||
|
||||
var preAuthKey v1.PreAuthKey
|
||||
var preAuthKey apiv1.PreAuthKey
|
||||
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
err = executeAndUnmarshal(
|
||||
@@ -205,7 +205,7 @@ func TestPreAuthKeyCommandWithoutExpiry(t *testing.T) {
|
||||
assert.NoError(c, err)
|
||||
}, integrationutil.ScaledTimeout(10*time.Second), integrationutil.FastPoll, "Waiting for preauth key creation without expiry")
|
||||
|
||||
var listedPreAuthKeys []v1.PreAuthKey
|
||||
var listedPreAuthKeys []apiv1.PreAuthKey
|
||||
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
err = executeAndUnmarshal(
|
||||
@@ -225,10 +225,10 @@ func TestPreAuthKeyCommandWithoutExpiry(t *testing.T) {
|
||||
// There is one key created by [Scenario.CreateHeadscaleEnv]
|
||||
assert.Len(t, listedPreAuthKeys, 2)
|
||||
|
||||
assert.True(t, listedPreAuthKeys[1].GetExpiration().AsTime().After(time.Now()))
|
||||
assert.True(t, listedPreAuthKeys[1].GetExpiration().Value.After(time.Now()))
|
||||
assert.True(
|
||||
t,
|
||||
listedPreAuthKeys[1].GetExpiration().AsTime().Before(time.Now().Add(time.Minute*70)),
|
||||
listedPreAuthKeys[1].GetExpiration().Value.Before(time.Now().Add(time.Minute*70)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func TestPreAuthKeyCommandReusableEphemeral(t *testing.T) {
|
||||
headscale, err := scenario.Headscale()
|
||||
require.NoError(t, err)
|
||||
|
||||
var preAuthReusableKey v1.PreAuthKey
|
||||
var preAuthReusableKey apiv1.PreAuthKey
|
||||
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
err = executeAndUnmarshal(
|
||||
@@ -271,7 +271,7 @@ func TestPreAuthKeyCommandReusableEphemeral(t *testing.T) {
|
||||
assert.NoError(c, err)
|
||||
}, integrationutil.ScaledTimeout(10*time.Second), integrationutil.FastPoll, "Waiting for reusable preauth key creation")
|
||||
|
||||
var preAuthEphemeralKey v1.PreAuthKey
|
||||
var preAuthEphemeralKey apiv1.PreAuthKey
|
||||
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
err = executeAndUnmarshal(
|
||||
@@ -291,10 +291,10 @@ func TestPreAuthKeyCommandReusableEphemeral(t *testing.T) {
|
||||
assert.NoError(c, err)
|
||||
}, integrationutil.ScaledTimeout(10*time.Second), integrationutil.FastPoll, "Waiting for ephemeral preauth key creation")
|
||||
|
||||
assert.True(t, preAuthEphemeralKey.GetEphemeral())
|
||||
assert.False(t, preAuthEphemeralKey.GetReusable())
|
||||
assert.True(t, preAuthEphemeralKey.GetEphemeral().Or(false))
|
||||
assert.False(t, preAuthEphemeralKey.GetReusable().Or(false))
|
||||
|
||||
var listedPreAuthKeys []v1.PreAuthKey
|
||||
var listedPreAuthKeys []apiv1.PreAuthKey
|
||||
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
err = executeAndUnmarshal(
|
||||
@@ -325,7 +325,7 @@ func TestPreAuthKeyDeleteCommand(t *testing.T) {
|
||||
defer scenario.ShutdownAssertNoPanics(t)
|
||||
|
||||
// Create a key to delete.
|
||||
created := assertJSONRoundtrip[*v1.PreAuthKey](t, headscale, []string{
|
||||
created := assertJSONRoundtrip[*apiv1.PreAuthKey](t, headscale, []string{
|
||||
"headscale",
|
||||
"preauthkeys",
|
||||
"--user", "1",
|
||||
@@ -333,7 +333,7 @@ func TestPreAuthKeyDeleteCommand(t *testing.T) {
|
||||
"--reusable",
|
||||
"--output", "json",
|
||||
})
|
||||
require.NotZero(t, created.GetId())
|
||||
require.NotZero(t, created.GetID().Or(0))
|
||||
|
||||
// delete with no --id must be rejected.
|
||||
_, err := headscale.Execute([]string{"headscale", "preauthkeys", "delete"})
|
||||
@@ -342,13 +342,13 @@ func TestPreAuthKeyDeleteCommand(t *testing.T) {
|
||||
// delete the created key by id.
|
||||
_, err = headscale.Execute([]string{
|
||||
"headscale", "preauthkeys", "delete",
|
||||
"--id", strconv.FormatUint(created.GetId(), 10),
|
||||
"--id", strconv.FormatUint(created.GetID().Or(0), 10),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// The deleted key must be gone from the list.
|
||||
assert.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||
var listed []v1.PreAuthKey
|
||||
var listed []apiv1.PreAuthKey
|
||||
|
||||
err := executeAndUnmarshal(headscale,
|
||||
[]string{"headscale", "preauthkeys", "list", "--output", "json"},
|
||||
@@ -357,7 +357,7 @@ func TestPreAuthKeyDeleteCommand(t *testing.T) {
|
||||
assert.NoError(c, err)
|
||||
|
||||
for i := range listed {
|
||||
assert.NotEqual(c, created.GetId(), listed[i].GetId(), "deleted key should not be listed")
|
||||
assert.NotEqual(c, created.GetID().Or(0), listed[i].GetID().Or(0), "deleted key should not be listed")
|
||||
}
|
||||
}, integrationutil.ScaledTimeout(10*time.Second), integrationutil.FastPoll, "Waiting for preauth key list after delete")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user