From d1b23f18329418f923be9296e06b959b90be1ad1 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Wed, 25 Nov 2026 11:47:13 +0100 Subject: [PATCH] fix(cli): show the host address and capacity in get hosts The hosts table read an "addresses" field the controller never sends, so the ADDRESSES column was always empty. The table now reads the single "address" field and shows the port range, online state and the number of instances the agent reported. The memory column is dropped: agents that do not report capacity left it empty, and it stays visible in -o json and -o yaml. --- internal/cli/cli_test.go | 17 +++++++++++++---- internal/cli/get.go | 5 +++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index 1cbb5c5..4a8f240 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -160,15 +160,24 @@ func TestGetGroupsOnOldControllerSaysNotSupported(t *testing.T) { } } -func TestGetHostsOnNewerController(t *testing.T) { +func TestGetHostsShowsAddressPortsAndState(t *testing.T) { mux := apiMux(t) mux.HandleFunc("GET /v1/hosts", func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, `[{"name":"mc01","version":"2.0.0","capacity":{"memoryMiB":16384},"addresses":["10.1.1.1"]}]`) + io.WriteString(w, `[{"name":"mc01","version":"58123e1","address":"10.200.2.35","portRange":"30000-30100","capacity":{},"lastSeen":"2026-11-25T10:00:00Z","online":true,"instances":0}]`) }) h := newHarness(t, mux) out := h.ok("", "get", "hosts") - if !strings.Contains(out, "mc01") || !strings.Contains(out, "16384") { - t.Errorf("hosts:\n%s", out) + lines := strings.Split(strings.TrimSpace(out), "\n") + if len(lines) != 2 { + t.Fatalf("hosts want header and one row, got:\n%s", out) + } + wantHead := []string{"NAME", "VERSION", "ADDRESS", "PORTS", "ONLINE", "INSTANCES", "LAST-SEEN"} + if got := strings.Fields(lines[0]); strings.Join(got, " ") != strings.Join(wantHead, " ") { + t.Errorf("header = %v, want %v", got, wantHead) + } + wantRow := []string{"mc01", "58123e1", "10.200.2.35", "30000-30100", "true", "0", "2026-11-25T10:00:00Z"} + if got := strings.Fields(lines[1]); strings.Join(got, " ") != strings.Join(wantRow, " ") { + t.Errorf("row = %v, want %v", got, wantRow) } } diff --git a/internal/cli/get.go b/internal/cli/get.go index a93341c..b7633af 100644 --- a/internal/cli/get.go +++ b/internal/cli/get.go @@ -42,8 +42,9 @@ var kinds = []kind{ {"PORT", field("spec", "port")}, {"READINESS", field("spec", "readiness")}, }}, {name: "hosts", aliases: []string{"host"}, newNames: true, cols: []column{ - {"NAME", field("name")}, {"VERSION", field("version")}, {"MEMORY-MIB", field("capacity", "memoryMiB")}, - {"ADDRESSES", field("addresses")}, {"LAST-SEEN", field("lastSeen")}, + {"NAME", field("name")}, {"VERSION", field("version")}, {"ADDRESS", field("address")}, + {"PORTS", field("portRange")}, {"ONLINE", field("online")}, {"INSTANCES", field("instances")}, + {"LAST-SEEN", field("lastSeen")}, }}, }