diff --git a/cmd/hi/stats.go b/cmd/hi/stats.go index aec28c50..bd81d6da 100644 --- a/cmd/hi/stats.go +++ b/cmd/hi/stats.go @@ -409,25 +409,25 @@ func calculateStatsSummary(values []float64) StatsSummary { return StatsSummary{} } - min := values[0] - max := values[0] + minVal := values[0] + maxVal := values[0] sum := 0.0 for _, value := range values { - if value < min { - min = value + if value < minVal { + minVal = value } - if value > max { - max = value + if value > maxVal { + maxVal = value } sum += value } return StatsSummary{ - Min: min, - Max: max, + Min: minVal, + Max: maxVal, Average: sum / float64(len(values)), } } diff --git a/hscontrol/auth_test.go b/hscontrol/auth_test.go index 73048d9e..14cfaad5 100644 --- a/hscontrol/auth_test.go +++ b/hscontrol/auth_test.go @@ -3113,7 +3113,7 @@ func TestWebFlowReauthDifferentUser(t *testing.T) { user1Nodes := 0 user2Nodes := 0 - for i := 0; i < allNodesSlice.Len(); i++ { + for i := range allNodesSlice.Len() { n := allNodesSlice.At(i) if n.UserID().Get() == user1.ID { user1Nodes++ diff --git a/hscontrol/db/db.go b/hscontrol/db/db.go index 61f192db..f9fd9a20 100644 --- a/hscontrol/db/db.go +++ b/hscontrol/db/db.go @@ -173,6 +173,9 @@ AND auth_key_id NOT IN ( routes = slices.Compact(routes) data, err := json.Marshal(routes) + if err != nil { + return fmt.Errorf("marshaling routes for node %d: %w", nodeID, err) + } err = tx.Model(&types.Node{}).Where("id = ?", nodeID).Update("approved_routes", data).Error if err != nil { diff --git a/hscontrol/db/node_test.go b/hscontrol/db/node_test.go index 3696aa2e..0f16f8a4 100644 --- a/hscontrol/db/node_test.go +++ b/hscontrol/db/node_test.go @@ -754,6 +754,9 @@ func TestNodeNaming(t *testing.T) { } _, err = RegisterNodeForTest(tx, nodeInvalidHostname, new(mpp("100.64.0.66/32").Addr()), nil) + if err != nil { + return err + } _, err = RegisterNodeForTest(tx, nodeShortHostname, new(mpp("100.64.0.67/32").Addr()), nil) return err diff --git a/hscontrol/policy/v2/types_test.go b/hscontrol/policy/v2/types_test.go index 8164f576..dc95e1f3 100644 --- a/hscontrol/policy/v2/types_test.go +++ b/hscontrol/policy/v2/types_test.go @@ -1860,7 +1860,7 @@ func TestResolvePolicy(t *testing.T) { }, { name: "autogroup-member-comprehensive", - toResolve: new(AutoGroup(AutoGroupMember)), + toResolve: new(AutoGroupMember), nodes: types.Nodes{ // Node with no tags (should be included - is a member) { @@ -1910,7 +1910,7 @@ func TestResolvePolicy(t *testing.T) { }, { name: "autogroup-tagged", - toResolve: new(AutoGroup(AutoGroupTagged)), + toResolve: new(AutoGroupTagged), nodes: types.Nodes{ // Node with no tags (should be excluded - not tagged) { diff --git a/hscontrol/state/state.go b/hscontrol/state/state.go index c720c271..57e0ebde 100644 --- a/hscontrol/state/state.go +++ b/hscontrol/state/state.go @@ -749,7 +749,7 @@ func (s *State) RenameNode(nodeID types.NodeID, newName string) (types.NodeView, // Check name uniqueness against NodeStore allNodes := s.nodeStore.ListNodes() - for i := 0; i < allNodes.Len(); i++ { + for i := range allNodes.Len() { node := allNodes.At(i) if node.ID() != nodeID && node.AsStruct().GivenName == newName { return types.NodeView{}, change.Change{}, fmt.Errorf("%w: %s", ErrNodeNameNotUnique, newName) diff --git a/integration/auth_web_flow_test.go b/integration/auth_web_flow_test.go index 6dbf6dfe..8d596241 100644 --- a/integration/auth_web_flow_test.go +++ b/integration/auth_web_flow_test.go @@ -245,7 +245,7 @@ func TestAuthWebFlowLogoutAndReloginNewUser(t *testing.T) { allClients, err := scenario.ListTailscaleClients() requireNoErrListClients(t, err) - allIps, err := scenario.ListTailscaleClientsIPs() + _, err = scenario.ListTailscaleClientsIPs() requireNoErrListClientIPs(t, err) err = scenario.WaitForTailscaleSync() @@ -367,7 +367,7 @@ func TestAuthWebFlowLogoutAndReloginNewUser(t *testing.T) { } // Test connectivity after user switch - allIps, err = scenario.ListTailscaleClientsIPs() + allIps, err := scenario.ListTailscaleClientsIPs() requireNoErrListClientIPs(t, err) allAddrs := lo.Map(allIps, func(x netip.Addr, index int) string { diff --git a/integration/helpers.go b/integration/helpers.go index b1701f8f..86986bc8 100644 --- a/integration/helpers.go +++ b/integration/helpers.go @@ -23,8 +23,8 @@ import ( "github.com/oauth2-proxy/mockoidc" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" + "maps" + "slices" "tailscale.com/tailcfg" ) @@ -332,7 +332,7 @@ func requireAllClientsOnlineWithSingleTimeout(t *testing.T, headscale ControlSer var failureReport strings.Builder - ids := types.NodeIDs(maps.Keys(nodeStatus)) + ids := slices.Collect(maps.Keys(nodeStatus)) slices.Sort(ids) for _, nodeID := range ids { diff --git a/integration/scenario.go b/integration/scenario.go index 9ae0c4fc..bf3f4096 100644 --- a/integration/scenario.go +++ b/integration/scenario.go @@ -1158,7 +1158,7 @@ var errParseAuthPage = errors.New("failed to parse auth page") func (s *Scenario) runHeadscaleRegister(userStr string, body string) error { // see api.go HTML template - codeSep := strings.Split(string(body), "") + codeSep := strings.Split(body, "") if len(codeSep) != expectedHTMLSplitParts { return errParseAuthPage } diff --git a/integration/tsic/tsic.go b/integration/tsic/tsic.go index b270fab3..d7ff1714 100644 --- a/integration/tsic/tsic.go +++ b/integration/tsic/tsic.go @@ -731,12 +731,12 @@ func (t *TailscaleInContainer) LoginWithURL( // Logout runs the logout routine on the given Tailscale instance. func (t *TailscaleInContainer) Logout() error { - stdout, stderr, err := t.Execute([]string{"tailscale", "logout"}) + _, _, err := t.Execute([]string{"tailscale", "logout"}) if err != nil { return err } - stdout, stderr, _ = t.Execute([]string{"tailscale", "status"}) + stdout, stderr, _ := t.Execute([]string{"tailscale", "status"}) if !strings.Contains(stdout+stderr, "Logged out.") { return fmt.Errorf("%w: stdout: %s, stderr: %s", errLogoutFailed, stdout, stderr) }