cmd/tailscale: format empty cities and countries as hyphens (#16495)

When running `tailscale exit-node list`, an empty city or country name
should be displayed as a hyphen "-". However, this only happened when
there was no location at all. If a node provides a Hostinfo.Location,
then the list would display exactly what was provided.

This patch changes the listing so that empty cities and countries will
either render the provided name or "-".

Fixes #16500

Signed-off-by: Simon Law <sfllaw@tailscale.com>
This commit is contained in:
Simon Law
2025-07-08 22:14:18 -07:00
committed by GitHub
parent a60e0caf6a
commit bad17a1bfa
2 changed files with 29 additions and 21 deletions
+20 -8
View File
@@ -74,10 +74,10 @@ func TestFilterFormatAndSortExitNodes(t *testing.T) {
want := filteredExitNodes{
Countries: []*filteredCountry{
{
Name: noLocationData,
Name: "",
Cities: []*filteredCity{
{
Name: noLocationData,
Name: "",
Peers: []*ipnstate.PeerStatus{
ps[5],
},
@@ -273,14 +273,20 @@ func TestSortByCountryName(t *testing.T) {
Name: "Zimbabwe",
},
{
Name: noLocationData,
Name: "",
},
}
sortByCountryName(fc)
if fc[0].Name != noLocationData {
t.Fatalf("sortByCountryName did not order countries by alphabetical order, got %v, want %v", fc[0].Name, noLocationData)
want := []string{"", "Albania", "Sweden", "Zimbabwe"}
var got []string
for _, c := range fc {
got = append(got, c.Name)
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("sortByCountryName did not order countries by alphabetical order (-want +got):\n%s", diff)
}
}
@@ -296,13 +302,19 @@ func TestSortByCityName(t *testing.T) {
Name: "Squamish",
},
{
Name: noLocationData,
Name: "",
},
}
sortByCityName(fc)
if fc[0].Name != noLocationData {
t.Fatalf("sortByCityName did not order cities by alphabetical order, got %v, want %v", fc[0].Name, noLocationData)
want := []string{"", "Goteborg", "Kingston", "Squamish"}
var got []string
for _, c := range fc {
got = append(got, c.Name)
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("sortByCityName did not order countries by alphabetical order (-want +got):\n%s", diff)
}
}