From 67d54d9d09b2a4f36598aa191dd521c469f412e9 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 12 Oct 2026 17:43:38 +0200 Subject: [PATCH] Say an account without its time as age unknown, not as two thousand years (issue 160) --- cmd/mesh-controller/machine_lines.go | 7 ++++++- cmd/mesh-controller/machine_lines_test.go | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/mesh-controller/machine_lines.go b/cmd/mesh-controller/machine_lines.go index 20d79a37..03f6e4b3 100644 --- a/cmd/mesh-controller/machine_lines.go +++ b/cmd/mesh-controller/machine_lines.go @@ -24,7 +24,12 @@ func machineLines(a inventory.MachineAccount, had bool, now time.Time) []string " " + factLine("kernel", orUnsaid(a.Kernel)), } } - out := []string{fmt.Sprintf(" what it is made of, as it said %s ago:", roughly(now.Sub(m.ObservedAt)))} + age := roughly(now.Sub(m.ObservedAt)) + " ago" + if m.ObservedAt.IsZero() { + // Said with no time: its age is not known, and is never read as two thousand years. + age = "at a time it did not say (age unknown)" + } + out := []string{fmt.Sprintf(" what it is made of, as it said %s:", age)} add := func(name, value string) { out = append(out, " "+factLine(name, value)) } unknown := map[string]string{} for k, v := range m.Unknown { diff --git a/cmd/mesh-controller/machine_lines_test.go b/cmd/mesh-controller/machine_lines_test.go index 7318136f..9f7e2e55 100644 --- a/cmd/mesh-controller/machine_lines_test.go +++ b/cmd/mesh-controller/machine_lines_test.go @@ -78,3 +78,11 @@ func TestAnOlderNodeEngineStillShowsArchitectureAndKernel(t *testing.T) { t.Errorf("%s", got) } } + +func TestAnAccountWithoutItsTimeSaysAgeUnknown(t *testing.T) { + got := machineLines(inventory.MachineAccount{Architecture: "amd64", Kernel: "linux", + Machine: &inventory.MadeOf{KernelRelease: "7.2"}}, true, time.Now())[0] + if !strings.Contains(got, "age unknown") || strings.Contains(got, "d ago") { + t.Errorf("%s", got) + } +}