ADR 0593 §7: the composer with its refusals leaves mesh-sdk, so mesh-sdk carries no composition rule. The catalogue functions only the node-engine's composition reaches (Resolve, Resolution's Compose, Declaration, DataItems, LeftOut, Rules and the rest, the settings, placeholder and template refusals, the rendering helpers) are copied with their tests into internal/compose/resolution; a method of a mesh-sdk shape becomes a function taking it first. The composition calls its own copies, and the captured catalogue its tests read lives here now, shared by mesh-compose's tests. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
48 lines
1.8 KiB
Go
48 lines
1.8 KiB
Go
package resolution
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// The zone is the operator's (a setting) and the port is where this machine publishes the listen —
|
|
// neither is the definition's to state.
|
|
func TestAZoneIsPlacedFromTheNodesSettingAndPublishedPort(t *testing.T) {
|
|
m := mcat.Manifest{Module: "lab", Zone: &mcat.Zone{Name: "${setting:zone}", Listen: "dns"},
|
|
Listens: []mcat.Listening{{Name: "dns", Port: 5353, From: mcat.FromMesh}}}
|
|
z, err := ZoneOn(m, []mcat.Layer{{From: "node", Values: map[string]any{"zone": "Incus."}}},
|
|
map[int]int{5353: 15353}, "workstation", "10.77.0.3")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if z.Zone != "incus" || z.Address != "10.77.0.3" || z.Port != 15353 || z.Node != "workstation" {
|
|
t.Fatalf("the zone was placed as %+v", *z)
|
|
}
|
|
if _, err := ZoneOn(m, nil, nil, "workstation", "10.77.0.3"); err == nil {
|
|
t.Fatal("a zone nobody named was placed")
|
|
}
|
|
}
|
|
|
|
// One module answers a zone, and none may shadow the mesh's names or a public domain.
|
|
func TestTheMeshRefusesAZoneTwiceOrOneThatShadows(t *testing.T) {
|
|
one := mcat.ZoneAt{Zone: "incus", Node: "workstation", Module: "lab", Address: "10.77.0.3", Port: 53}
|
|
if p := ZonesProblems([]mcat.ZoneAt{one}, "internal", []string{"example.tld"}); len(p) != 0 {
|
|
t.Fatalf("one ordinary zone was refused: %v", p)
|
|
}
|
|
twice := one
|
|
twice.Node, twice.Module = "laptop", "other"
|
|
cases := map[string][]mcat.ZoneAt{
|
|
"declared by": {one, twice},
|
|
"mesh's own suffix": {{Zone: "lab.internal", Node: "a", Module: "m"}},
|
|
"public domain": {{Zone: "dev.example.tld", Node: "a", Module: "m"}},
|
|
}
|
|
for want, zones := range cases {
|
|
p := strings.Join(ZonesProblems(zones, "internal", []string{"example.tld"}), "\n")
|
|
if !strings.Contains(p, want) {
|
|
t.Errorf("not refused for %q: %q", want, p)
|
|
}
|
|
}
|
|
}
|