Files
mesh-host/internal/compose/resolution/zones_test.go
T
jschoubben 0c01c81c3f E8: run each file's unit tests as subtests of one test
The node-engine held 1,707 top-level unit tests against the budget of 500
a module. Each unit test file with two or more tests now runs them as
subtests of one test named for the file, each named as its function was,
in the same order: every check is kept, and the check counts 383. Files
with a TestMain, a re-run of a test by its name, or the integration tag
are left. Four files of this branch's earlier commits are formatted.

Builds: design 47 H2 §819; H-A-349 DQ-14
2026-11-22 00:30:05 +01:00

54 lines
2.2 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)
}
}
}
// TestZones runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestZones(t *testing.T) {
t.Run("AZoneIsPlacedFromTheNodesSettingAndPublishedPort", testAZoneIsPlacedFromTheNodesSettingAndPublishedPort)
t.Run("TheMeshRefusesAZoneTwiceOrOneThatShadows", testTheMeshRefusesAZoneTwiceOrOneThatShadows)
}