Return stderr too in ExecuteCommand

This commit is contained in:
Juan Font 2022-09-21 15:01:26 +00:00
parent 95948e03c9
commit 695359862e
5 changed files with 94 additions and 94 deletions

View file

@ -129,7 +129,7 @@ func (s *IntegrationCLITestSuite) HandleStats(
} }
func (s *IntegrationCLITestSuite) createNamespace(name string) (*v1.Namespace, error) { func (s *IntegrationCLITestSuite) createNamespace(name string) (*v1.Namespace, error) {
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -172,7 +172,7 @@ func (s *IntegrationCLITestSuite) TestNamespaceCommand() {
assert.Equal(s.T(), names[2], namespaces[2].Name) assert.Equal(s.T(), names[2], namespaces[2].Name)
// Test list namespaces // Test list namespaces
listResult, err := ExecuteCommand( listResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -194,7 +194,7 @@ func (s *IntegrationCLITestSuite) TestNamespaceCommand() {
assert.Equal(s.T(), names[2], listedNamespaces[2].Name) assert.Equal(s.T(), names[2], listedNamespaces[2].Name)
// Test rename namespace // Test rename namespace
renameResult, err := ExecuteCommand( renameResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -216,7 +216,7 @@ func (s *IntegrationCLITestSuite) TestNamespaceCommand() {
assert.Equal(s.T(), renamedNamespace.Name, "newname") assert.Equal(s.T(), renamedNamespace.Name, "newname")
// Test list after rename namespaces // Test list after rename namespaces
listAfterRenameResult, err := ExecuteCommand( listAfterRenameResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -247,7 +247,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
preAuthResult, err := ExecuteCommand( preAuthResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -275,7 +275,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommand() {
assert.Len(s.T(), keys, 5) assert.Len(s.T(), keys, 5)
// Test list of keys // Test list of keys
listResult, err := ExecuteCommand( listResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -335,7 +335,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommand() {
// Expire three keys // Expire three keys
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -351,7 +351,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommand() {
} }
// Test list pre auth keys after expire // Test list pre auth keys after expire
listAfterExpireResult, err := ExecuteCommand( listAfterExpireResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -396,7 +396,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandWithoutExpiry() {
namespace, err := s.createNamespace("pre-auth-key-without-exp-namespace") namespace, err := s.createNamespace("pre-auth-key-without-exp-namespace")
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
preAuthResult, err := ExecuteCommand( preAuthResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -417,7 +417,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandWithoutExpiry() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
// Test list of keys // Test list of keys
listResult, err := ExecuteCommand( listResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -449,7 +449,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandReusableEphemeral() {
namespace, err := s.createNamespace("pre-auth-key-reus-ephm-namespace") namespace, err := s.createNamespace("pre-auth-key-reus-ephm-namespace")
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
preAuthReusableResult, err := ExecuteCommand( preAuthReusableResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -472,7 +472,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandReusableEphemeral() {
assert.True(s.T(), preAuthReusableKey.GetReusable()) assert.True(s.T(), preAuthReusableKey.GetReusable())
assert.False(s.T(), preAuthReusableKey.GetEphemeral()) assert.False(s.T(), preAuthReusableKey.GetEphemeral())
preAuthEphemeralResult, err := ExecuteCommand( preAuthEphemeralResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -514,7 +514,7 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandReusableEphemeral() {
// assert.NotNil(s.T(), err) // assert.NotNil(s.T(), err)
// Test list of keys // Test list of keys
listResult, err := ExecuteCommand( listResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -548,7 +548,7 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
for index, machineKey := range machineKeys { for index, machineKey := range machineKeys {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -567,7 +567,7 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
) )
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
machineResult, err := ExecuteCommand( machineResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -592,7 +592,7 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
} }
assert.Len(s.T(), machines, len(machineKeys)) assert.Len(s.T(), machines, len(machineKeys))
addTagResult, err := ExecuteCommand( addTagResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -612,7 +612,7 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
assert.Equal(s.T(), []string{"tag:test"}, machine.ForcedTags) assert.Equal(s.T(), []string{"tag:test"}, machine.ForcedTags)
// try to set a wrong tag and retrieve the error // try to set a wrong tag and retrieve the error
wrongTagResult, err := ExecuteCommand( wrongTagResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -634,7 +634,7 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
assert.Contains(s.T(), errorOutput.Error, "tag must start with the string 'tag:'") assert.Contains(s.T(), errorOutput.Error, "tag must start with the string 'tag:'")
// Test list all nodes after added seconds // Test list all nodes after added seconds
listAllResult, err := ExecuteCommand( listAllResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -684,7 +684,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
for index, machineKey := range machineKeys { for index, machineKey := range machineKeys {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -703,7 +703,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
) )
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
machineResult, err := ExecuteCommand( machineResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -730,7 +730,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
assert.Len(s.T(), machines, len(machineKeys)) assert.Len(s.T(), machines, len(machineKeys))
// Test list all nodes after added seconds // Test list all nodes after added seconds
listAllResult, err := ExecuteCommand( listAllResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -769,7 +769,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
for index, machineKey := range otherNamespaceMachineKeys { for index, machineKey := range otherNamespaceMachineKeys {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -788,7 +788,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
) )
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
machineResult, err := ExecuteCommand( machineResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -815,7 +815,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
assert.Len(s.T(), otherNamespaceMachines, len(otherNamespaceMachineKeys)) assert.Len(s.T(), otherNamespaceMachines, len(otherNamespaceMachineKeys))
// Test list all nodes after added otherNamespace // Test list all nodes after added otherNamespace
listAllWithotherNamespaceResult, err := ExecuteCommand( listAllWithotherNamespaceResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -845,7 +845,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
assert.Equal(s.T(), "otherNamespace-machine-2", listAllWithotherNamespace[6].Name) assert.Equal(s.T(), "otherNamespace-machine-2", listAllWithotherNamespace[6].Name)
// Test list all nodes after added otherNamespace // Test list all nodes after added otherNamespace
listOnlyotherNamespaceMachineNamespaceResult, err := ExecuteCommand( listOnlyotherNamespaceMachineNamespaceResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -884,7 +884,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
) )
// Delete a machines // Delete a machines
_, err = ExecuteCommand( _, _, err = ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -902,7 +902,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
// Test: list main namespace after machine is deleted // Test: list main namespace after machine is deleted
listOnlyMachineNamespaceAfterDeleteResult, err := ExecuteCommand( listOnlyMachineNamespaceAfterDeleteResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -943,7 +943,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
for index, machineKey := range machineKeys { for index, machineKey := range machineKeys {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -962,7 +962,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
) )
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
machineResult, err := ExecuteCommand( machineResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -988,7 +988,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
assert.Len(s.T(), machines, len(machineKeys)) assert.Len(s.T(), machines, len(machineKeys))
listAllResult, err := ExecuteCommand( listAllResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1014,7 +1014,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
assert.True(s.T(), listAll[4].Expiry.AsTime().IsZero()) assert.True(s.T(), listAll[4].Expiry.AsTime().IsZero())
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1028,7 +1028,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
} }
listAllAfterExpiryResult, err := ExecuteCommand( listAllAfterExpiryResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1070,7 +1070,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
for index, machineKey := range machineKeys { for index, machineKey := range machineKeys {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1089,7 +1089,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
) )
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
machineResult, err := ExecuteCommand( machineResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1115,7 +1115,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
assert.Len(s.T(), machines, len(machineKeys)) assert.Len(s.T(), machines, len(machineKeys))
listAllResult, err := ExecuteCommand( listAllResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1141,7 +1141,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
assert.Contains(s.T(), listAll[4].GetGivenName(), "machine-5") assert.Contains(s.T(), listAll[4].GetGivenName(), "machine-5")
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1156,7 +1156,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
} }
listAllAfterRenameResult, err := ExecuteCommand( listAllAfterRenameResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1182,7 +1182,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
assert.Contains(s.T(), listAllAfterRename[4].GetGivenName(), "machine-5") assert.Contains(s.T(), listAllAfterRename[4].GetGivenName(), "machine-5")
// Test failure for too long names // Test failure for too long names
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1197,7 +1197,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
assert.Contains(s.T(), result, "not be over 63 chars") assert.Contains(s.T(), result, "not be over 63 chars")
listAllAfterRenameAttemptResult, err := ExecuteCommand( listAllAfterRenameAttemptResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1233,7 +1233,7 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() {
// Randomly generated machine keys // Randomly generated machine keys
machineKey := "9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe" machineKey := "9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe"
_, err = ExecuteCommand( _, _, err = ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1256,7 +1256,7 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() {
) )
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
machineResult, err := ExecuteCommand( machineResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1280,7 +1280,7 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() {
assert.Equal(s.T(), uint64(1), machine.Id) assert.Equal(s.T(), uint64(1), machine.Id)
assert.Equal(s.T(), "route-machine", machine.Name) assert.Equal(s.T(), "route-machine", machine.Name)
listAllResult, err := ExecuteCommand( listAllResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1305,7 +1305,7 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() {
assert.Empty(s.T(), listAll.EnabledRoutes) assert.Empty(s.T(), listAll.EnabledRoutes)
enableTwoRoutesResult, err := ExecuteCommand( enableTwoRoutesResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1337,7 +1337,7 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() {
assert.Contains(s.T(), enableTwoRoutes.EnabledRoutes, "192.168.1.0/24") assert.Contains(s.T(), enableTwoRoutes.EnabledRoutes, "192.168.1.0/24")
// Enable only one route, effectively disabling one of the routes // Enable only one route, effectively disabling one of the routes
enableOneRouteResult, err := ExecuteCommand( enableOneRouteResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1366,7 +1366,7 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() {
assert.Contains(s.T(), enableOneRoute.EnabledRoutes, "10.0.0.0/8") assert.Contains(s.T(), enableOneRoute.EnabledRoutes, "10.0.0.0/8")
// Enable only one route, effectively disabling one of the routes // Enable only one route, effectively disabling one of the routes
failEnableNonAdvertisedRoute, err := ExecuteCommand( failEnableNonAdvertisedRoute, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1390,7 +1390,7 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() {
) )
// Enable all routes on host // Enable all routes on host
enableAllRouteResult, err := ExecuteCommand( enableAllRouteResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1425,7 +1425,7 @@ func (s *IntegrationCLITestSuite) TestApiKeyCommand() {
keys := make([]string, count) keys := make([]string, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
apiResult, err := ExecuteCommand( apiResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1451,7 +1451,7 @@ func (s *IntegrationCLITestSuite) TestApiKeyCommand() {
assert.Len(s.T(), keys, 5) assert.Len(s.T(), keys, 5)
// Test list of keys // Test list of keys
listResult, err := ExecuteCommand( listResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1513,7 +1513,7 @@ func (s *IntegrationCLITestSuite) TestApiKeyCommand() {
// Expire three keys // Expire three keys
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1530,7 +1530,7 @@ func (s *IntegrationCLITestSuite) TestApiKeyCommand() {
} }
// Test list pre auth keys after expire // Test list pre auth keys after expire
listAfterExpireResult, err := ExecuteCommand( listAfterExpireResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1573,7 +1573,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
// Randomly generated machine key // Randomly generated machine key
machineKey := "688411b767663479632d44140f08a9fde87383adc7cdeb518f62ce28a17ef0aa" machineKey := "688411b767663479632d44140f08a9fde87383adc7cdeb518f62ce28a17ef0aa"
_, err = ExecuteCommand( _, _, err = ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1592,7 +1592,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
) )
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
machineResult, err := ExecuteCommand( machineResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1619,7 +1619,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
machineId := fmt.Sprintf("%d", machine.Id) machineId := fmt.Sprintf("%d", machine.Id)
moveToNewNSResult, err := ExecuteCommand( moveToNewNSResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1641,7 +1641,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
assert.Equal(s.T(), machine.Namespace, newNamespace) assert.Equal(s.T(), machine.Namespace, newNamespace)
listAllNodesResult, err := ExecuteCommand( listAllNodesResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1664,7 +1664,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
assert.Equal(s.T(), allNodes[0].Namespace, machine.Namespace) assert.Equal(s.T(), allNodes[0].Namespace, machine.Namespace)
assert.Equal(s.T(), allNodes[0].Namespace, newNamespace) assert.Equal(s.T(), allNodes[0].Namespace, newNamespace)
moveToNonExistingNSResult, err := ExecuteCommand( moveToNonExistingNSResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1688,7 +1688,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
) )
assert.Equal(s.T(), machine.Namespace, newNamespace) assert.Equal(s.T(), machine.Namespace, newNamespace)
moveToOldNSResult, err := ExecuteCommand( moveToOldNSResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1710,7 +1710,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
assert.Equal(s.T(), machine.Namespace, oldNamespace) assert.Equal(s.T(), machine.Namespace, oldNamespace)
moveToSameNSResult, err := ExecuteCommand( moveToSameNSResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1742,7 +1742,7 @@ func (s *IntegrationCLITestSuite) TestLoadConfigFromCommand() {
altEnvConfig, err := os.ReadFile("integration_test/etc/alt-env-config.dump.gold.yaml") altEnvConfig, err := os.ReadFile("integration_test/etc/alt-env-config.dump.gold.yaml")
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
_, err = ExecuteCommand( _, _, err = ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1757,7 +1757,7 @@ func (s *IntegrationCLITestSuite) TestLoadConfigFromCommand() {
assert.YAMLEq(s.T(), string(defaultConfig), string(defaultDumpConfig)) assert.YAMLEq(s.T(), string(defaultConfig), string(defaultDumpConfig))
_, err = ExecuteCommand( _, _, err = ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1774,7 +1774,7 @@ func (s *IntegrationCLITestSuite) TestLoadConfigFromCommand() {
assert.YAMLEq(s.T(), string(altConfig), string(altDumpConfig)) assert.YAMLEq(s.T(), string(altConfig), string(altDumpConfig))
_, err = ExecuteCommand( _, _, err = ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -1791,7 +1791,7 @@ func (s *IntegrationCLITestSuite) TestLoadConfigFromCommand() {
assert.YAMLEq(s.T(), string(altEnvConfig), string(altEnvDumpConfig)) assert.YAMLEq(s.T(), string(altEnvConfig), string(altEnvDumpConfig))
_, err = ExecuteCommand( _, _, err = ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",

View file

@ -68,7 +68,7 @@ func ExecuteCommand(
cmd []string, cmd []string,
env []string, env []string,
options ...ExecuteCommandOption, options ...ExecuteCommandOption,
) (string, error) { ) (string, string, error) {
var stdout bytes.Buffer var stdout bytes.Buffer
var stderr bytes.Buffer var stderr bytes.Buffer
@ -78,7 +78,7 @@ func ExecuteCommand(
for _, opt := range options { for _, opt := range options {
if err := opt(&execConfig); err != nil { if err := opt(&execConfig); err != nil {
return "", fmt.Errorf("execute-command/options: %w", err) return "", "", fmt.Errorf("execute-command/options: %w", err)
} }
} }
@ -107,7 +107,7 @@ func ExecuteCommand(
select { select {
case res := <-resultChan: case res := <-resultChan:
if res.err != nil { if res.err != nil {
return "", res.err return stdout.String(), stderr.String(), res.err
} }
if res.exitCode != 0 { if res.exitCode != 0 {
@ -115,13 +115,13 @@ func ExecuteCommand(
fmt.Println("stdout: ", stdout.String()) fmt.Println("stdout: ", stdout.String())
fmt.Println("stderr: ", stderr.String()) fmt.Println("stderr: ", stderr.String())
return "", fmt.Errorf("command failed with: %s", stderr.String()) return stdout.String(), stderr.String(), fmt.Errorf("command failed with: %s", stderr.String())
} }
return stdout.String(), nil return stdout.String(), stderr.String(), nil
case <-time.After(execConfig.timeout): case <-time.After(execConfig.timeout):
return stderr.String(), fmt.Errorf("command timed out after %s", execConfig.timeout) return stdout.String(), stderr.String(), fmt.Errorf("command timed out after %s", execConfig.timeout)
} }
} }
@ -200,7 +200,7 @@ func getIPs(
for hostname, tailscale := range tailscales { for hostname, tailscale := range tailscales {
command := []string{"tailscale", "ip"} command := []string{"tailscale", "ip"}
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -228,7 +228,7 @@ func getIPs(
func getDNSNames( func getDNSNames(
headscale *dockertest.Resource, headscale *dockertest.Resource,
) ([]string, error) { ) ([]string, error) {
listAllResult, err := ExecuteCommand( listAllResult, _, err := ExecuteCommand(
headscale, headscale,
[]string{ []string{
"headscale", "headscale",
@ -261,7 +261,7 @@ func getDNSNames(
func getMagicFQDN( func getMagicFQDN(
headscale *dockertest.Resource, headscale *dockertest.Resource,
) ([]string, error) { ) ([]string, error) {
listAllResult, err := ExecuteCommand( listAllResult, _, err := ExecuteCommand(
headscale, headscale,
[]string{ []string{
"headscale", "headscale",

View file

@ -187,7 +187,7 @@ func (s *IntegrationDERPTestSuite) SetupSuite() {
log.Println("headscale container is ready for embedded DERP tests") log.Println("headscale container is ready for embedded DERP tests")
log.Printf("Creating headscale namespace: %s\n", namespaceName) log.Printf("Creating headscale namespace: %s\n", namespaceName)
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{"headscale", "namespaces", "create", namespaceName}, []string{"headscale", "namespaces", "create", namespaceName},
[]string{}, []string{},
@ -196,7 +196,7 @@ func (s *IntegrationDERPTestSuite) SetupSuite() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
log.Printf("Creating pre auth key for %s\n", namespaceName) log.Printf("Creating pre auth key for %s\n", namespaceName)
preAuthResult, err := ExecuteCommand( preAuthResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -259,7 +259,7 @@ func (s *IntegrationDERPTestSuite) Join(
log.Println("Join command:", command) log.Println("Join command:", command)
log.Printf("Running join command for %s\n", hostname) log.Printf("Running join command for %s\n", hostname)
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -414,7 +414,7 @@ func (s *IntegrationDERPTestSuite) TestPingAllPeersByHostname() {
peername, peername,
) )
log.Println(command) log.Println(command)
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},

View file

@ -163,7 +163,7 @@ func (s *IntegrationTestSuite) Join(
log.Println("Join command:", command) log.Println("Join command:", command)
log.Printf("Running join command for %s\n", hostname) log.Printf("Running join command for %s\n", hostname)
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -305,7 +305,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
for namespace, scales := range s.namespaces { for namespace, scales := range s.namespaces {
log.Printf("Creating headscale namespace: %s\n", namespace) log.Printf("Creating headscale namespace: %s\n", namespace)
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{"headscale", "namespaces", "create", namespace}, []string{"headscale", "namespaces", "create", namespace},
[]string{}, []string{},
@ -314,7 +314,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
assert.Nil(s.T(), err) assert.Nil(s.T(), err)
log.Printf("Creating pre auth key for %s\n", namespace) log.Printf("Creating pre auth key for %s\n", namespace)
preAuthResult, err := ExecuteCommand( preAuthResult, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{ []string{
"headscale", "headscale",
@ -386,7 +386,7 @@ func (s *IntegrationTestSuite) HandleStats(
func (s *IntegrationTestSuite) TestListNodes() { func (s *IntegrationTestSuite) TestListNodes() {
for namespace, scales := range s.namespaces { for namespace, scales := range s.namespaces {
log.Println("Listing nodes") log.Println("Listing nodes")
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{"headscale", "--namespace", namespace, "nodes", "list"}, []string{"headscale", "--namespace", namespace, "nodes", "list"},
[]string{}, []string{},
@ -518,7 +518,7 @@ func (s *IntegrationTestSuite) TestPingAllPeersByAddress() {
peername, peername,
ip, ip,
) )
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -552,7 +552,7 @@ func (s *IntegrationTestSuite) TestTailDrop() {
for hostname, tailscale := range scales.tailscales { for hostname, tailscale := range scales.tailscales {
command := []string{"touch", fmt.Sprintf("/tmp/file_from_%s", hostname)} command := []string{"touch", fmt.Sprintf("/tmp/file_from_%s", hostname)}
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -586,7 +586,7 @@ func (s *IntegrationTestSuite) TestTailDrop() {
hostname, hostname,
peername, peername,
) )
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -606,7 +606,7 @@ func (s *IntegrationTestSuite) TestTailDrop() {
"get", "get",
"/tmp/", "/tmp/",
} }
_, err := ExecuteCommand( _, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -628,7 +628,7 @@ func (s *IntegrationTestSuite) TestTailDrop() {
peername, peername,
ip, ip,
) )
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -672,7 +672,7 @@ func (s *IntegrationTestSuite) TestPingAllPeersByHostname() {
hostname, hostname,
peername, peername,
) )
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -724,7 +724,7 @@ func (s *IntegrationTestSuite) TestMagicDNS() {
peername, peername,
hostname, hostname,
) )
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
@ -757,7 +757,7 @@ func getAPIURLs(
"/run/tailscale/tailscaled.sock", "/run/tailscale/tailscaled.sock",
"http://localhost/localapi/v0/file-targets", "http://localhost/localapi/v0/file-targets",
} }
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},

View file

@ -244,7 +244,7 @@ oidc:
s.Suite.T().Log("headscale container is ready for embedded OIDC tests") s.Suite.T().Log("headscale container is ready for embedded OIDC tests")
s.Suite.T().Logf("Creating headscale namespace: %s\n", oidcNamespaceName) s.Suite.T().Logf("Creating headscale namespace: %s\n", oidcNamespaceName)
result, err := ExecuteCommand( result, _, err := ExecuteCommand(
&s.headscale, &s.headscale,
[]string{"headscale", "namespaces", "create", oidcNamespaceName}, []string{"headscale", "namespaces", "create", oidcNamespaceName},
[]string{}, []string{},
@ -320,22 +320,22 @@ func (s *IntegrationOIDCTestSuite) joinOIDC(
log.Println("Join command:", command) log.Println("Join command:", command)
log.Printf("Running join command for %s\n", hostname) log.Printf("Running join command for %s\n", hostname)
result, _ := ExecuteCommand( _, stderr, _ := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
) )
// This piece of code just gets the login URL out of the output of the tailscale client. // This piece of code just gets the login URL out of the stderr of the tailscale client.
// See https://github.com/tailscale/tailscale/blob/main/cmd/tailscale/cli/up.go#L584. // See https://github.com/tailscale/tailscale/blob/main/cmd/tailscale/cli/up.go#L584.
urlStr := strings.ReplaceAll(result, "\nTo authenticate, visit:\n\n\t", "") urlStr := strings.ReplaceAll(stderr, "\nTo authenticate, visit:\n\n\t", "")
urlStr = strings.TrimSpace(urlStr) urlStr = strings.TrimSpace(urlStr)
// parse URL // parse URL
loginUrl, err := url.Parse(urlStr) loginUrl, err := url.Parse(urlStr)
if err != nil { if err != nil {
log.Printf("Could not parse login URL: %s", err) log.Printf("Could not parse login URL: %s", err)
log.Printf("Original join command result: %s", result) log.Printf("Original join command result: %s", stderr)
return nil, err return nil, err
} }
@ -491,14 +491,14 @@ func (s *IntegrationOIDCTestSuite) TestPingAllPeersByAddress() {
peername, peername,
ip, ip,
) )
result, err := ExecuteCommand( stdout, stderr, err := ExecuteCommand(
&tailscale, &tailscale,
command, command,
[]string{}, []string{},
) )
assert.Nil(t, err) assert.Nil(t, err)
log.Printf("Result for %s: %s\n", hostname, result) log.Printf("result for %s: stdout: %s, stderr: %s\n", hostname, stdout, stderr)
assert.Contains(t, result, "pong") assert.Contains(t, stdout, "pong")
}) })
} }
} }