Files
mesh-host/internal/compose/resolution/resolver_file_is_the_uplinks_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

64 lines
2.4 KiB
Go

package resolution
import (
"reflect"
"testing"
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
)
func testTheResolverConfigSeatIsGone(t *testing.T) {
if _, known := mcat.SeatNamed("node-resolver-config"); known {
t.Error("node-resolver-config is still in the mesh's set; the uplink's holder writes the resolver file")
}
// An uplink's holder needs no seat beside it for the file: it is its own.
if got := DependsOn(nil, mod("networkmanager", nil, nil, nil, mcat.Claim{Name: "node-uplink"})); len(got) != 0 {
t.Errorf("an uplink holder with nothing declared depends on %v", got)
}
}
// The catalogue as it is: nothing claims the retired seat, and every manager the mesh knows holds the
// uplink and writes the resolver file; beside them only a holder of node-resolver does (ADR 0247).
func testTheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes(t *testing.T) {
cat := map[string]mcat.Manifest{}
for _, m := range theCatalogue(t) {
cat[m.Module] = m
}
if got := PossibleHolders(cat, "node-uplink"); !reflect.DeepEqual(got, uplinks) {
t.Errorf("node-uplink can be held by %v, not %v", got, uplinks)
}
for name, m := range cat {
for _, c := range m.Claims {
if c.Name == "node-resolver-config" {
t.Errorf("%s still claims node-resolver-config", name)
}
}
_, writes := m.Facts["resolvers"]
isUplink := false
for _, u := range uplinks {
isUplink = isUplink || u == name
}
for _, f := range m.Facts {
// Or the machine's own resolver's, where it is held (novox/hq ADR 0247): the uplink's holder
// steps back from the file there, and nowhere else.
if f.Path == "/etc/resolv.conf" && !isUplink && !holdsSeat(m, mcat.ResolverSeat) {
t.Errorf("%s writes /etc/resolv.conf and holds neither the uplink nor the machine's resolver", name)
}
}
for _, r := range m.Resources {
if r["path"] == "/etc/resolv.conf" {
t.Errorf("%s declares /etc/resolv.conf as a file of its own", name)
}
}
if isUplink && !writes {
t.Errorf("%s holds the uplink and does not write the resolver file", name)
}
}
}
// TestResolverFileIsTheUplinks runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestResolverFileIsTheUplinks(t *testing.T) {
t.Run("TheResolverConfigSeatIsGone", testTheResolverConfigSeatIsGone)
t.Run("TheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes", testTheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes)
}