tailcfg: update node display name fields and methods (#1207)

Signed-off-by: Sonia Appasamy <sonia@tailscale.com>

Consolidates the node display name logic from each of the clients into
tailcfg.Node. UI clients can use these names directly, rather than computing
them independently.
This commit is contained in:
Sonia Appasamy
2021-01-27 11:50:31 -05:00
committed by GitHub
parent 35e10c78fc
commit 4dab0c1702
7 changed files with 121 additions and 75 deletions

View File

@@ -17,11 +17,3 @@ func HasSuffix(name, suffix string) bool {
nameBase := strings.TrimSuffix(name, suffix)
return len(nameBase) < len(name) && strings.HasSuffix(nameBase, ".")
}
// ToBaseName removes the domain ending from a DNS name of a node.
func ToBaseName(name string) string {
if i := strings.Index(name, "."); i != -1 {
return name[:i]
}
return name
}

View File

@@ -26,21 +26,3 @@ func TestHasSuffix(t *testing.T) {
}
}
}
func TestToBaseName(t *testing.T) {
tests := []struct {
name string
want string
}{
{"foo", "foo"},
{"foo.com", "foo"},
{"foo.example.com.beta.tailscale.net", "foo"},
{"computer-a.test.gmail.com.beta.tailscale.net", "computer-a"},
}
for _, tt := range tests {
got := ToBaseName(tt.name)
if got != tt.want {
t.Errorf("ToBaseName(%q) = %q; want %q", tt.name, got, tt.want)
}
}
}