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:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user