modified code to satisfy golangci-lint and added integration test

This commit is contained in:
Samuel Lock 2022-05-11 09:31:24 +10:00
parent b028a7dfc9
commit c26280c331
2 changed files with 34 additions and 4 deletions

View file

@ -131,12 +131,10 @@ omit the route you do not want to enable.
defer cancel() defer cancel()
defer conn.Close() defer conn.Close()
routes := []string{} var routes []string
isAll, _ := cmd.Flags().GetBool("all") isAll, _ := cmd.Flags().GetBool("all")
if isAll == true { if isAll {
// x := v1.NewHeadscaleServiceClient(conn)
// machine, err := x.GetMachineByID(machineID)
response, err := client.GetMachineRoute(ctx, &v1.GetMachineRouteRequest{ response, err := client.GetMachineRoute(ctx, &v1.GetMachineRouteRequest{
MachineId: machineID, MachineId: machineID,
}) })
@ -149,6 +147,8 @@ omit the route you do not want to enable.
), ),
output, output,
) )
return
} }
routes = response.GetRoutes().GetAdvertisedRoutes() routes = response.GetRoutes().GetAdvertisedRoutes()
} else { } else {
@ -159,6 +159,7 @@ omit the route you do not want to enable.
fmt.Sprintf("Error getting routes from flag: %s", err), fmt.Sprintf("Error getting routes from flag: %s", err),
output, output,
) )
return return
} }
} }

View file

@ -1076,6 +1076,35 @@ func (s *IntegrationCLITestSuite) TestRouteCommand() {
string(failEnableNonAdvertisedRoute), string(failEnableNonAdvertisedRoute),
"route (route-machine) is not available on node", "route (route-machine) is not available on node",
) )
// Enable all routes on host
enableAllRouteResult, err := ExecuteCommand(
&s.headscale,
[]string{
"headscale",
"routes",
"enable",
"--output",
"json",
"--identifier",
"0",
"--all",
},
[]string{},
)
assert.Nil(s.T(), err)
var enableAllRoute v1.Routes
err = json.Unmarshal([]byte(enableAllRouteResult), &enableAllRoute)
assert.Nil(s.T(), err)
assert.Len(s.T(), enableAllRoute.AdvertisedRoutes, 2)
assert.Contains(s.T(), enableAllRoute.AdvertisedRoutes, "10.0.0.0/8")
assert.Contains(s.T(), enableAllRoute.AdvertisedRoutes, "192.168.1.0/24")
assert.Len(s.T(), enableAllRoute.EnabledRoutes, 2)
assert.Contains(s.T(), enableAllRoute.EnabledRoutes, "10.0.0.0/8")
assert.Contains(s.T(), enableAllRoute.EnabledRoutes, "192.168.1.0/24")
} }
func (s *IntegrationCLITestSuite) TestApiKeyCommand() { func (s *IntegrationCLITestSuite) TestApiKeyCommand() {