package inventory import ( "testing" ) // The node-engine's words for a machine's facts (novox/hq issue 160), as mesh-host's profile.Machine puts // them on the wire. A rename on either side fails here rather than as a blank on a real machine. func TestAMachinesAccountIsReadInTheNodeEnginesWords(t *testing.T) { raw := []byte(`{"architecture":"amd64","kernel":"linux","capabilities":[], "machine":{"observed_at":"2026-10-12T15:00:00Z","kernel_release":"7.2.8-arch1-2", "distribution":"Arch Linux","version":"rolling","processor":"AMD Ryzen 9","cores":8,"threads":16, "memory_bytes":32891494400,"virtual":"physical","booted_at":"2026-10-09T08:50:34Z", "timezone":"Europe/Brussels", "filesystems":[{"mount":"/","device":"/dev/nvme0n1p3","type":"ext4","size_bytes":100,"free_bytes":40}], "unknown":{"public address":"not decided"}}}`) a, had, err := machineFrom(raw) if err != nil || !had { t.Fatalf("had %v, err %v", had, err) } m := a.Machine if a.Architecture != "amd64" || a.Kernel != "linux" || m == nil { t.Fatalf("%+v", a) } if m.KernelRelease != "7.2.8-arch1-2" || m.Distribution != "Arch Linux" || m.Version != "rolling" || m.Processor != "AMD Ryzen 9" || m.Cores != 8 || m.Threads != 16 || m.MemoryBytes != 32891494400 || m.Virtual != "physical" || m.BootedAt == nil || m.Timezone != "Europe/Brussels" || len(m.Filesystems) != 1 || m.Filesystems[0].FreeBytes != 40 || m.Unknown["public address"] == "" || m.ObservedAt.IsZero() { t.Errorf("%+v", m) } } func TestAProfileWithoutTheFactsIsAnOlderNodeEngineNotNothing(t *testing.T) { a, had, err := machineFrom([]byte(`{"architecture":"amd64","kernel":"linux","capabilities":[]}`)) if err != nil || !had || a.Machine != nil || a.Architecture != "amd64" { t.Errorf("%+v had %v err %v", a, had, err) } if _, had, _ := machineFrom(nil); had { t.Error("a node that never reported read as having reported") } }