fix(instance): sort public services so the profile order is stable

The cache is a Go map; unsorted output reshuffled on every poll,
which made hub-client lists visibly jump around.
This commit is contained in:
2026-08-23 12:03:55 +01:00
parent 5d11e80837
commit 707fe619f7
2 changed files with 27 additions and 1 deletions
+20
View File
@@ -61,6 +61,26 @@ func serve(t *testing.T, dataRoot string, services []types.Container) map[string
return body
}
func TestPublicServicesSortedCaseInsensitive(t *testing.T) {
// The cache is a Go map, so input order is random per call; the profile
// must still be stable across polls.
all := []types.Container{
{ID: "1", ServiceName: "calendar", Status: "running"},
{ID: "2", ServiceName: "Blog", Status: "running"},
{ID: "3", ServiceName: "auth-proxy", Status: "running"},
}
got := publicServices(all)
want := []string{"auth-proxy", "Blog", "calendar"}
if len(got) != len(want) {
t.Fatalf("len = %d, want %d", len(got), len(want))
}
for i := range want {
if got[i].ServiceName != want[i] {
t.Fatalf("order[%d] = %q, want %q (full: %v)", i, got[i].ServiceName, want[i], got)
}
}
}
func TestPublicProfileFiltersHiddenInfra(t *testing.T) {
dataRoot := t.TempDir()
body := serve(t, dataRoot, testServices())