0056 is 'the authority is the control plane, not a database'. A citation pointing at the wrong decision is worse than none: it reads as corroboration. Claude-Session: https://claude.ai/code/session_01LrgweAeERJYBg88c5cKDzF
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
package inventory
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// novox/hq ADR 0066 — a node's public domain is a node-level fact, held here beside its other
|
|
// node-level configuration rather than in a module's settings. These check it round-trips, that a
|
|
// node with none reports empty rather than failing, and that clearing it works — the setting the
|
|
// ADR names as the whole of moving a catalogue between a lab and production.
|
|
|
|
func TestAPublicDomainRoundTrips(t *testing.T) {
|
|
inv := fresh(t)
|
|
if _, err := inv.AddNode(t.Context(), "anchor"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := inv.SetPublicDomain(t.Context(), "anchor", "example.tld"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
domain, err := inv.PublicDomainOf(t.Context(), "anchor")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if domain != "example.tld" {
|
|
t.Fatalf("set example.tld and read %q", domain)
|
|
}
|
|
}
|
|
|
|
func TestANodeWithNoPublicDomainReportsEmpty(t *testing.T) {
|
|
// Empty, not an error: most machines serve nothing to the outside, and a routed module on such
|
|
// a node simply composes no name.
|
|
inv := fresh(t)
|
|
if _, err := inv.AddNode(t.Context(), "workstation"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
domain, err := inv.PublicDomainOf(t.Context(), "workstation")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if domain != "" {
|
|
t.Fatalf("a node that was never given a domain reported %q", domain)
|
|
}
|
|
}
|
|
|
|
func TestAPublicDomainCanBeCleared(t *testing.T) {
|
|
// A node that stops facing the outside composes no names. Clearing with an empty value is how
|
|
// that is said, and it must actually clear rather than store the empty string.
|
|
inv := fresh(t)
|
|
if _, err := inv.AddNode(t.Context(), "anchor"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := inv.SetPublicDomain(t.Context(), "anchor", "example.tld"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := inv.SetPublicDomain(t.Context(), "anchor", ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
domain, err := inv.PublicDomainOf(t.Context(), "anchor")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if domain != "" {
|
|
t.Fatalf("cleared the domain and read %q", domain)
|
|
}
|
|
}
|
|
|
|
func TestPublicDomainOfAnUnknownNodeFails(t *testing.T) {
|
|
inv := fresh(t)
|
|
if _, err := inv.PublicDomainOf(t.Context(), "never-seen"); err == nil {
|
|
t.Fatal("reading the domain of a node that does not exist was not refused")
|
|
}
|
|
}
|