Port integration tests routes CLI to v2
Fix options signature
This commit is contained in:
parent
946d38e5d7
commit
52862b8a22
4 changed files with 156 additions and 168 deletions
|
@ -7,7 +7,6 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -1244,173 +1243,6 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||
assert.Contains(s.T(), listAllAfterRenameAttempt[4].GetGivenName(), "machine-5")
|
||||
}
|
||||
|
||||
func (s *IntegrationCLITestSuite) TestRouteCommand() {
|
||||
namespace, err := s.createNamespace("routes-namespace")
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
// Randomly generated machine keys
|
||||
machineKey := "nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe"
|
||||
|
||||
_, _, err = ExecuteCommand(
|
||||
&s.headscale,
|
||||
[]string{
|
||||
"headscale",
|
||||
"debug",
|
||||
"create-node",
|
||||
"--name",
|
||||
"route-machine",
|
||||
"--namespace",
|
||||
namespace.Name,
|
||||
"--key",
|
||||
machineKey,
|
||||
"--route",
|
||||
"10.0.0.0/8",
|
||||
"--route",
|
||||
"192.168.1.0/24",
|
||||
"--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)
|
||||
|
||||
assert.Equal(s.T(), uint64(1), machine.Id)
|
||||
assert.Equal(s.T(), "route-machine", machine.Name)
|
||||
|
||||
listAllResult, _, err := ExecuteCommand(
|
||||
&s.headscale,
|
||||
[]string{
|
||||
"headscale",
|
||||
"routes",
|
||||
"list",
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
[]string{},
|
||||
)
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
var routes []v1.Route
|
||||
err = json.Unmarshal([]byte(listAllResult), &routes)
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
assert.Len(s.T(), routes, 2)
|
||||
assert.Equal(s.T(), routes[0].Enabled, false)
|
||||
assert.Equal(s.T(), routes[1].Enabled, false)
|
||||
|
||||
routeIDToEnable := routes[1].Id
|
||||
|
||||
_, _, err = ExecuteCommand(
|
||||
&s.headscale,
|
||||
[]string{
|
||||
"headscale",
|
||||
"routes",
|
||||
"enable",
|
||||
"--output",
|
||||
"json",
|
||||
"--route",
|
||||
strconv.FormatUint(routeIDToEnable, 10),
|
||||
},
|
||||
[]string{},
|
||||
)
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
listAllResult, _, err = ExecuteCommand(
|
||||
&s.headscale,
|
||||
[]string{
|
||||
"headscale",
|
||||
"routes",
|
||||
"list",
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
[]string{},
|
||||
)
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
err = json.Unmarshal([]byte(listAllResult), &routes)
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
assert.Len(s.T(), routes, 2)
|
||||
|
||||
for _, route := range routes {
|
||||
if route.Id == routeIDToEnable {
|
||||
assert.Equal(s.T(), route.Enabled, true)
|
||||
assert.Equal(s.T(), route.IsPrimary, true)
|
||||
} else {
|
||||
assert.Equal(s.T(), route.Enabled, false)
|
||||
}
|
||||
}
|
||||
|
||||
// Enable only one route, effectively disabling one of the routes
|
||||
_, _, err = ExecuteCommand(
|
||||
&s.headscale,
|
||||
[]string{
|
||||
"headscale",
|
||||
"routes",
|
||||
"disable",
|
||||
"--output",
|
||||
"json",
|
||||
"--route",
|
||||
strconv.FormatUint(routeIDToEnable, 10),
|
||||
},
|
||||
[]string{},
|
||||
)
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
listAllResult, _, err = ExecuteCommand(
|
||||
&s.headscale,
|
||||
[]string{
|
||||
"headscale",
|
||||
"routes",
|
||||
"list",
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
[]string{},
|
||||
)
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
err = json.Unmarshal([]byte(listAllResult), &routes)
|
||||
assert.Nil(s.T(), err)
|
||||
|
||||
assert.Len(s.T(), routes, 2)
|
||||
|
||||
for _, route := range routes {
|
||||
if route.Id == routeIDToEnable {
|
||||
assert.Equal(s.T(), route.Enabled, false)
|
||||
assert.Equal(s.T(), route.IsPrimary, false)
|
||||
} else {
|
||||
assert.Equal(s.T(), route.Enabled, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationCLITestSuite) TestApiKeyCommand() {
|
||||
count := 5
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue