Skip to content

Commit

Permalink
Changed IsAutomaticNameMode to GivenNameHasBeenChanged. Fixed errors …
Browse files Browse the repository at this point in the history
…in files according to golangci-lint rules
  • Loading branch information
hopleus committed Oct 17, 2024
1 parent f38a567 commit 37b0673
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions hscontrol/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ type (
Nodes []*Node
)

// IsAutomaticNameMode returns whether the `givenName` can be automatically changed based on the `Hostname` of the node.
func (node *Node) IsAutomaticNameMode() bool {
// GivenNameHasBeenChanged returns whether the `givenName` can be automatically changed based on the `Hostname` of the node.
func (node *Node) GivenNameHasBeenChanged() bool {
return node.GivenName == util.ConvertWithFQDNRules(node.Hostname)
}

Expand Down Expand Up @@ -359,7 +359,7 @@ func (node *Node) ApplyHostnameFromHostInfo(hostInfo *tailcfg.Hostinfo) {
}

if node.Hostname != hostInfo.Hostname {
if node.IsAutomaticNameMode() {
if node.GivenNameHasBeenChanged() {
node.GivenName = util.ConvertWithFQDNRules(hostInfo.Hostname)
}

Expand Down
12 changes: 6 additions & 6 deletions integration/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/juanfont/headscale/hscontrol/util"
"net/netip"
"strconv"
"strings"
Expand All @@ -13,6 +12,7 @@ import (

v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/juanfont/headscale/hscontrol/types"
"github.com/juanfont/headscale/hscontrol/util"
"github.com/juanfont/headscale/integration/hsic"
"github.com/juanfont/headscale/integration/tsic"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -723,8 +723,8 @@ func TestUpdateHostnameFromClient(t *testing.T) {

for _, node := range nodes {
hostname := hostnames[strconv.FormatUint(node.GetId(), 10)]
assert.Equal(t, hostname, node.Name)
assert.Equal(t, util.ConvertWithFQDNRules(hostname), node.GivenName)
assert.Equal(t, hostname, node.GetName())
assert.Equal(t, util.ConvertWithFQDNRules(hostname), node.GetGivenName())
}

// Rename givenName in nodes
Expand All @@ -737,7 +737,7 @@ func TestUpdateHostnameFromClient(t *testing.T) {
"rename",
givenName,
"--identifier",
strconv.Itoa(int(node.GetId())),
strconv.FormatUint(node.GetId(), 10),
})
assertNoErr(t, err)
}
Expand Down Expand Up @@ -779,8 +779,8 @@ func TestUpdateHostnameFromClient(t *testing.T) {
for _, node := range nodes {
hostname := hostnames[strconv.FormatUint(node.GetId(), 10)]
givenName := fmt.Sprintf("%d-givenname", node.GetId())
assert.Equal(t, hostname+"NEW", node.Name)
assert.Equal(t, givenName, node.GivenName)
assert.Equal(t, hostname+"NEW", node.GetName())
assert.Equal(t, givenName, node.GetGivenName())
}
}

Expand Down

0 comments on commit 37b0673

Please sign in to comment.