mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-29 18:33:05 +00:00
feat: add integration tests for tag support
This commit is contained in:
parent
63d920510d
commit
31c0062d5e
1 changed files with 122 additions and 0 deletions
|
@ -525,6 +525,128 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandReusableEphemeral() {
|
||||||
assert.Len(s.T(), listedPreAuthKeys, 2)
|
assert.Len(s.T(), listedPreAuthKeys, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
||||||
|
namespace, err := s.createNamespace("machine-namespace")
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
machineKeys := []string{
|
||||||
|
"9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||||
|
"6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||||
|
}
|
||||||
|
machines := make([]*v1.Machine, len(machineKeys))
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
for index, machineKey := range machineKeys {
|
||||||
|
_, err := ExecuteCommand(
|
||||||
|
&s.headscale,
|
||||||
|
[]string{
|
||||||
|
"headscale",
|
||||||
|
"debug",
|
||||||
|
"create-node",
|
||||||
|
"--name",
|
||||||
|
fmt.Sprintf("machine-%d", index+1),
|
||||||
|
"--namespace",
|
||||||
|
namespace.Name,
|
||||||
|
"--key",
|
||||||
|
machineKey,
|
||||||
|
"--output",
|
||||||
|
"json",
|
||||||
|
},
|
||||||
|
[]string{},
|
||||||
|
)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
machineResult, err := ExecuteCommand(
|
||||||
|
&s.headscale,
|
||||||
|
[]string{
|
||||||
|
"headscale",
|
||||||
|
"nodes",
|
||||||
|
"--namespace",
|
||||||
|
namespace.Name,
|
||||||
|
"register",
|
||||||
|
"--key",
|
||||||
|
machineKey,
|
||||||
|
"--output",
|
||||||
|
"json",
|
||||||
|
},
|
||||||
|
[]string{},
|
||||||
|
)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
var machine v1.Machine
|
||||||
|
err = json.Unmarshal([]byte(machineResult), &machine)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
machines[index] = &machine
|
||||||
|
}
|
||||||
|
assert.Len(s.T(), machines, len(machineKeys))
|
||||||
|
|
||||||
|
addTagResult, err := ExecuteCommand(
|
||||||
|
&s.headscale,
|
||||||
|
[]string{
|
||||||
|
"headscale",
|
||||||
|
"nodes",
|
||||||
|
"tag",
|
||||||
|
"-i", "1",
|
||||||
|
"-t", "tag:test",
|
||||||
|
"--output", "json",
|
||||||
|
},
|
||||||
|
[]string{},
|
||||||
|
)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
var machine v1.Machine
|
||||||
|
err = json.Unmarshal([]byte(addTagResult), &machine)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
assert.Equal(s.T(), []string{"tag:test"}, machine.ForcedTags)
|
||||||
|
|
||||||
|
// try to set a wrong tag and retrieve the error
|
||||||
|
_, err = ExecuteCommand(
|
||||||
|
&s.headscale,
|
||||||
|
[]string{
|
||||||
|
"headscale",
|
||||||
|
"nodes",
|
||||||
|
"tag",
|
||||||
|
"-i", "2",
|
||||||
|
"-t", "wrong-tag",
|
||||||
|
"--output", "json",
|
||||||
|
},
|
||||||
|
[]string{},
|
||||||
|
)
|
||||||
|
assert.ErrorContains(s.T(), err, "Invalid tag detected")
|
||||||
|
|
||||||
|
// Test list all nodes after added seconds
|
||||||
|
listAllResult, err := ExecuteCommand(
|
||||||
|
&s.headscale,
|
||||||
|
[]string{
|
||||||
|
"headscale",
|
||||||
|
"nodes",
|
||||||
|
"list",
|
||||||
|
"--output", "json",
|
||||||
|
},
|
||||||
|
[]string{},
|
||||||
|
)
|
||||||
|
resultMachines := make([]*v1.Machine, len(machineKeys))
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
json.Unmarshal([]byte(listAllResult), &resultMachines)
|
||||||
|
found := false
|
||||||
|
for _, machine := range machines {
|
||||||
|
if machine.ForcedTags != nil {
|
||||||
|
for _, tag := range machine.ForcedTags {
|
||||||
|
if tag == "tag:test" {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.Equal(
|
||||||
|
s.T(),
|
||||||
|
true,
|
||||||
|
found,
|
||||||
|
"should find a machine with the tag 'tag:test' in the list of machines",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
||||||
namespace, err := s.createNamespace("machine-namespace")
|
namespace, err := s.createNamespace("machine-namespace")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
Loading…
Reference in a new issue