package link_test import ( "testing" "github.com/novox/mesh-controller/internal/link" ) // A report may carry the machine's profile, detected again by the apply that reports, and the latest // replaces what enrolment recorded (novox/hq ADR 0161): a machine that switched its network manager // is a machine whose uplink holder lacks a capability at its next push, not at its next enrolment. func TestAReportsProfileReplacesTheEnrolledOne(t *testing.T) { e, _, _ := anEnrolledHub(t) ctx := t.Context() first := map[string]any{"capabilities": []any{map[string]any{"name": "uplink-networkmanager", "present": true}}} if _, err := e.Heard(ctx, link.Report{Node: "anchor", Profile: first}); err != nil { t.Fatal(err) } got, err := e.Inventory.Profile(ctx, "anchor") if err != nil { t.Fatal(err) } if len(got) != 1 || got[0].Name != "uplink-networkmanager" || !got[0].Present { t.Fatalf("the report's profile was not kept: %+v", got) } // The machine switched managers; the next report says so and the old fact is gone. second := map[string]any{"capabilities": []any{map[string]any{"name": "uplink-systemd-networkd", "present": true}}} if _, err := e.Heard(ctx, link.Report{Node: "anchor", Profile: second}); err != nil { t.Fatal(err) } got, err = e.Inventory.Profile(ctx, "anchor") if err != nil { t.Fatal(err) } if len(got) != 1 || got[0].Name != "uplink-systemd-networkd" { t.Fatalf("the latest profile did not replace the earlier one: %+v", got) } // A report with no profile leaves the last one standing. if _, err := e.Heard(ctx, link.Report{Node: "anchor", Host: "1"}); err != nil { t.Fatal(err) } if got, _ = e.Inventory.Profile(ctx, "anchor"); len(got) != 1 { t.Fatalf("a report without a profile erased it: %+v", got) } }