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
This commit is contained in:
2026-11-22 00:30:05 +01:00
parent a882051de6
commit 0c01c81c3f
257 changed files with 4189 additions and 1589 deletions
+24 -10
View File
@@ -26,7 +26,7 @@ table inet mesh_guard {
}
`
func TestTheGuardIsExactlyThisTable(t *testing.T) {
func testTheGuardIsExactlyThisTable(t *testing.T) {
if got := AsGuard([]int{15672, 5432}); got != goldenGuard {
t.Fatalf("the guard changed:\n%s", got)
}
@@ -52,13 +52,13 @@ ExecStop=nft delete table inet mesh_guard
WantedBy=multi-user.target
`
func TestTheGuardUnitIsExactlyThisUnit(t *testing.T) {
func testTheGuardUnitIsExactlyThisUnit(t *testing.T) {
if got := guardUnitText(); got != goldenGuardUnit {
t.Fatalf("the guard's unit changed:\n%s", got)
}
}
func TestTheGuardRefusesOnlyWhatIsAddressedToThisMachine(t *testing.T) {
func testTheGuardRefusesOnlyWhatIsAddressedToThisMachine(t *testing.T) {
// A machine that routes for others — a predecessor's private-network hub — must not have a
// packet for another machine's database port refused (novox/hq ADR 0103).
for _, line := range strings.Split(AsGuard([]int{5432}), "\n") {
@@ -68,7 +68,7 @@ func TestTheGuardRefusesOnlyWhatIsAddressedToThisMachine(t *testing.T) {
}
}
func TestAnAdoptedBundleLoadsNoDroppingTableAndExactlyTheGuard(t *testing.T) {
func testAnAdoptedBundleLoadsNoDroppingTableAndExactlyTheGuard(t *testing.T) {
r := producedBundle(t)
p := FoundationPorts{Store: 5433}
if _, err := RewritePorts(&r, p, ""); err != nil {
@@ -133,7 +133,7 @@ func TestAnAdoptedBundleLoadsNoDroppingTableAndExactlyTheGuard(t *testing.T) {
}
}
func TestAConvergedBundleIsNotMadeAnAdoptedOne(t *testing.T) {
func testAConvergedBundleIsNotMadeAnAdoptedOne(t *testing.T) {
// The converged genesis keeps the foundation's filter, byte for byte (novox/hq ADR 0088).
r := producedBundle(t)
for _, res := range r.Declaration.Resources {
@@ -146,7 +146,7 @@ func TestAConvergedBundleIsNotMadeAnAdoptedOne(t *testing.T) {
}
}
func TestAnAdoptedGenesisTakesTheMeshsOwnModulesBeforePushingThem(t *testing.T) {
func testAnAdoptedGenesisTakesTheMeshsOwnModulesBeforePushingThem(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
for _, c := range []struct {
module string
@@ -171,7 +171,7 @@ func TestAnAdoptedGenesisTakesTheMeshsOwnModulesBeforePushingThem(t *testing.T)
}
}
func TestAConvergedGenesisTakesNothing(t *testing.T) {
func testAConvergedGenesisTakesNothing(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
rec := &controlRecorder{settings: map[string]string{}}
control := controlPlane{container: "temp-mesh-controller", run: rec.run, timeout: time.Second}
@@ -184,7 +184,7 @@ func TestAConvergedGenesisTakesNothing(t *testing.T) {
}
}
func TestAnAdoptedGenesisOpensTheRegistryFromAnywhere(t *testing.T) {
func testAnAdoptedGenesisOpensTheRegistryFromAnywhere(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
rec := &controlRecorder{settings: map[string]string{}}
control := controlPlane{container: "temp-mesh-controller", run: rec.run, timeout: time.Second}
@@ -197,7 +197,7 @@ func TestAnAdoptedGenesisOpensTheRegistryFromAnywhere(t *testing.T) {
}
}
func TestAnAdoptedGenesisChoosesTheFilterAndLoadsNone(t *testing.T) {
func testAnAdoptedGenesisChoosesTheFilterAndLoadsNone(t *testing.T) {
rec := &controlRecorder{settings: map[string]string{}}
control := controlPlane{container: "mesh-controller", run: rec.run, timeout: time.Second}
o := Options{Node: "anchor", Adopted: true, Answers: map[string]string{"packet-filter": "nftables"}}
@@ -210,7 +210,7 @@ func TestAnAdoptedGenesisChoosesTheFilterAndLoadsNone(t *testing.T) {
}
}
func TestAnAdoptedNodeIsRecordedAdopted(t *testing.T) {
func testAnAdoptedNodeIsRecordedAdopted(t *testing.T) {
stop := errors.New("stop here")
runtime := &asked{answer: func(name string, args []string) (string, error) {
joined := strings.Join(args, " ")
@@ -231,3 +231,17 @@ func TestAnAdoptedNodeIsRecordedAdopted(t *testing.T) {
t.Errorf("the node was not added adopted: %v", runtime.commands)
}
}
// TestAdopted runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestAdopted(t *testing.T) {
t.Run("TheGuardIsExactlyThisTable", testTheGuardIsExactlyThisTable)
t.Run("TheGuardUnitIsExactlyThisUnit", testTheGuardUnitIsExactlyThisUnit)
t.Run("TheGuardRefusesOnlyWhatIsAddressedToThisMachine", testTheGuardRefusesOnlyWhatIsAddressedToThisMachine)
t.Run("AnAdoptedBundleLoadsNoDroppingTableAndExactlyTheGuard", testAnAdoptedBundleLoadsNoDroppingTableAndExactlyTheGuard)
t.Run("AConvergedBundleIsNotMadeAnAdoptedOne", testAConvergedBundleIsNotMadeAnAdoptedOne)
t.Run("AnAdoptedGenesisTakesTheMeshsOwnModulesBeforePushingThem", testAnAdoptedGenesisTakesTheMeshsOwnModulesBeforePushingThem)
t.Run("AConvergedGenesisTakesNothing", testAConvergedGenesisTakesNothing)
t.Run("AnAdoptedGenesisOpensTheRegistryFromAnywhere", testAnAdoptedGenesisOpensTheRegistryFromAnywhere)
t.Run("AnAdoptedGenesisChoosesTheFilterAndLoadsNone", testAnAdoptedGenesisChoosesTheFilterAndLoadsNone)
t.Run("AnAdoptedNodeIsRecordedAdopted", testAnAdoptedNodeIsRecordedAdopted)
}
+18 -7
View File
@@ -20,7 +20,7 @@ import (
// is the one it claims to be, by asking its package database about a package that is certainly
// there. Getting this wrong installs with the wrong package manager and the wrong unit names.
func TestTheMachineIsAskedWhichSystemItIs(t *testing.T) {
func testTheMachineIsAskedWhichSystemItIs(t *testing.T) {
// Only pacman answers, so this is the arch host and nothing had to be told so.
onlyPacman := func(_ context.Context, name string, _ ...string) (string, error) {
if name == "pacman" {
@@ -40,7 +40,7 @@ func TestTheMachineIsAskedWhichSystemItIs(t *testing.T) {
// A machine that is none of them is refused with what each of them said. "Unsupported system" is
// a sentence nobody can act on; "pacman does not answer here" is.
func TestAMachineThatIsNoneOfThemIsRefusedWithWhatEachSaid(t *testing.T) {
func testAMachineThatIsNoneOfThemIsRefusedWithWhatEachSaid(t *testing.T) {
nothing := func(context.Context, string, ...string) (string, error) {
return "", errors.New("command not found")
}
@@ -58,7 +58,7 @@ func TestAMachineThatIsNoneOfThemIsRefusedWithWhatEachSaid(t *testing.T) {
// And a machine that was TOLD what it is still has to prove it. Installing the arch half of the
// host on Alpine must say so once, at the start, rather than failing later inside pacman.
func TestASystemThatWasNamedIsStillProved(t *testing.T) {
func testASystemThatWasNamedIsStillProved(t *testing.T) {
onlyApk := func(_ context.Context, name string, _ ...string) (string, error) {
if name == "apk" {
return "apk-tools-2.14.0\n", nil
@@ -75,7 +75,7 @@ func TestASystemThatWasNamedIsStillProved(t *testing.T) {
}
}
func TestASystemNobodyHasBuiltIsRefusedByName(t *testing.T) {
func testASystemNobodyHasBuiltIsRefusedByName(t *testing.T) {
anything := func(context.Context, string, ...string) (string, error) { return "", nil }
_, err := WorkOutSystem(context.Background(), anything, "debian")
if err == nil {
@@ -88,7 +88,7 @@ func TestASystemNobodyHasBuiltIsRefusedByName(t *testing.T) {
// A foundation is applied before any mesh exists, so it can carry no secret the mesh sealed — there
// is no key to open one with. Refused with a sentence rather than a nil dereference.
func TestASealedFileInAFoundationIsRefusedWithAReason(t *testing.T) {
func testASealedFileInAFoundationIsRefusedWithAReason(t *testing.T) {
_, err := refuseSealed("anything")
if err == nil {
t.Fatal("a sealed file in a foundation bundle was accepted")
@@ -100,7 +100,7 @@ func TestASealedFileInAFoundationIsRefusedWithAReason(t *testing.T) {
// Defends novox/hq ADR 0100: the carried bundle keeps the original of a file it writes over that
// the host has no record of — the distribution's own ruleset, say.
func TestTheBundleKeepsTheOriginalOfWhatItWritesOver(t *testing.T) {
func testTheBundleKeepsTheOriginalOfWhatItWritesOver(t *testing.T) {
dir := t.TempDir()
conf := filepath.Join(dir, "nftables.conf")
if err := os.WriteFile(conf, []byte("# the distribution's own\n"), 0o644); err != nil {
@@ -134,7 +134,7 @@ func TestTheBundleKeepsTheOriginalOfWhatItWritesOver(t *testing.T) {
// Defends novox/hq issue 104: genesis consumes the bundle, recording the digest of what it applied
// and the mode the operator raised the machine in, so the host's own `reconcile` never applies the
// carried bytes over it.
func TestGenesisConsumesTheBundleAndRecordsTheMode(t *testing.T) {
func testGenesisConsumesTheBundleAndRecordsTheMode(t *testing.T) {
dir := t.TempDir()
raw := []byte(`{"declaration":1,"resources":[
{"id":"a","type":"file","path":"` + filepath.Join(dir, "a.conf") + `","content":"x\n"}]}`)
@@ -180,3 +180,14 @@ func TestGenesisConsumesTheBundleAndRecordsTheMode(t *testing.T) {
t.Errorf("a genesis re-run set the mode back to %q over the mesh's converged", known.Mode)
}
}
// TestApply runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestApply(t *testing.T) {
t.Run("TheMachineIsAskedWhichSystemItIs", testTheMachineIsAskedWhichSystemItIs)
t.Run("AMachineThatIsNoneOfThemIsRefusedWithWhatEachSaid", testAMachineThatIsNoneOfThemIsRefusedWithWhatEachSaid)
t.Run("ASystemThatWasNamedIsStillProved", testASystemThatWasNamedIsStillProved)
t.Run("ASystemNobodyHasBuiltIsRefusedByName", testASystemNobodyHasBuiltIsRefusedByName)
t.Run("ASealedFileInAFoundationIsRefusedWithAReason", testASealedFileInAFoundationIsRefusedWithAReason)
t.Run("TheBundleKeepsTheOriginalOfWhatItWritesOver", testTheBundleKeepsTheOriginalOfWhatItWritesOver)
t.Run("GenesisConsumesTheBundleAndRecordsTheMode", testGenesisConsumesTheBundleAndRecordsTheMode)
}
+16 -6
View File
@@ -11,7 +11,7 @@ import (
// **Exercised rather than assumed.** This is the refusal that stands between a person and a
// machine left holding a store, a broker and no control plane — the failure the whole preflight
// exists to prevent — and a refusal nothing tests is a refusal nobody has read.
func TestAnInstallerWithNothingToBuildRefuses(t *testing.T) {
func testAnInstallerWithNothingToBuildRefuses(t *testing.T) {
err := Source{}.Check()
if err == nil {
t.Fatal("a source naming no repository was accepted; nothing would have been built")
@@ -24,7 +24,7 @@ func TestAnInstallerWithNothingToBuildRefuses(t *testing.T) {
}
// A repository without a commit refuses too, because a branch is somebody else's moving target.
func TestABranchIsNotACommit(t *testing.T) {
func testABranchIsNotACommit(t *testing.T) {
err := Source{Repository: "https://example.invalid/mesh-controller.git"}.Check()
if err == nil {
t.Fatal("a source with no ref was accepted; genesis would have built whatever a branch pointed at")
@@ -35,7 +35,7 @@ func TestABranchIsNotACommit(t *testing.T) {
}
// And a repository with a commit is enough.
func TestARepositoryAndACommitIsEnough(t *testing.T) {
func testARepositoryAndACommitIsEnough(t *testing.T) {
if err := (Source{Repository: "https://example.invalid/mesh-controller.git", Ref: "a1b2c3d4"}).Check(); err != nil {
t.Fatalf("a repository and a commit were refused: %v", err)
}
@@ -46,7 +46,7 @@ func TestARepositoryAndACommitIsEnough(t *testing.T) {
// it rebuilds the control plane from source, and a copy in the catalogue, which genesis read — and
// nothing kept them equal (novox/hq 04-ISSUES/072). The builder already reports the manifest it
// built, artifact resolved to the image; genesis takes it from there and reads no second copy.
func TestTheBuildHandsOverTheManifestTheMeshWillHold(t *testing.T) {
func testTheBuildHandsOverTheManifestTheMeshWillHold(t *testing.T) {
manifest := `{"module":"mesh-controller","version":"1","resources":[` +
`{"id":"server","type":"container","name":"mesh-controller","image":"` + builtImage + `"}]}`
runtime := &asked{answer: aRepository(t, imageFormManifest, func(string, []string) (string, error) {
@@ -68,7 +68,7 @@ func TestTheBuildHandsOverTheManifestTheMeshWillHold(t *testing.T) {
// A result without a manifest is a build the installer cannot finish, and it is refused beside the
// builder that said it rather than at step 9 with a message about a missing file.
func TestABuildReportingNoManifestIsRefused(t *testing.T) {
func testABuildReportingNoManifestIsRefused(t *testing.T) {
runtime := &asked{answer: aRepository(t, imageFormManifest, func(string, []string) (string, error) {
return `{"module":"mesh-controller","commit":"a1b2c3d4",` +
`"made":[{"name":"server","kind":"image","reference":"` + builtImage + `"}]}`, nil
@@ -81,7 +81,7 @@ func TestABuildReportingNoManifestIsRefused(t *testing.T) {
}
// And a manifest that does not name the image the build produced describes some other build.
func TestABuildWhoseManifestNamesAnotherImageIsRefused(t *testing.T) {
func testABuildWhoseManifestNamesAnotherImageIsRefused(t *testing.T) {
runtime := &asked{answer: aRepository(t, imageFormManifest, func(string, []string) (string, error) {
return `{"module":"mesh-controller","commit":"a1b2c3d4","manifest":{"module":"mesh-controller",` +
`"resources":[{"id":"server","type":"container","image":"sha256:` + strings.Repeat("9", 64) + `"}]},` +
@@ -93,3 +93,13 @@ func TestABuildWhoseManifestNamesAnotherImageIsRefused(t *testing.T) {
t.Fatalf("a manifest naming another image was accepted, or refused for another reason: %v", err)
}
}
// TestBuild runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestBuild(t *testing.T) {
t.Run("AnInstallerWithNothingToBuildRefuses", testAnInstallerWithNothingToBuildRefuses)
t.Run("ABranchIsNotACommit", testABranchIsNotACommit)
t.Run("ARepositoryAndACommitIsEnough", testARepositoryAndACommitIsEnough)
t.Run("TheBuildHandsOverTheManifestTheMeshWillHold", testTheBuildHandsOverTheManifestTheMeshWillHold)
t.Run("ABuildReportingNoManifestIsRefused", testABuildReportingNoManifestIsRefused)
t.Run("ABuildWhoseManifestNamesAnotherImageIsRefused", testABuildWhoseManifestNamesAnotherImageIsRefused)
}
+20 -8
View File
@@ -38,7 +38,7 @@ func recording(t *testing.T) (*controlRecorder, controlPlane) {
return c, controlPlane{container: "temp-mesh-controller", run: c.run, timeout: time.Second}
}
func TestTheBuilderOnTheDefaultPackagesPortIsToldNothing(t *testing.T) {
func testTheBuilderOnTheDefaultPackagesPortIsToldNothing(t *testing.T) {
c, control := recording(t)
o := Options{Node: "anchor", Wait: time.Second}
if _, err := installModule(context.Background(), o, control, BuilderModule,
@@ -67,7 +67,7 @@ func aCatalogueWith(t *testing.T, module, manifest string) string {
const theForgesManifest = `{"module": "gitea", "version": "1"}`
func TestThePackagesPortIsTheForgeModulesSettingOnThisNode(t *testing.T) {
func testThePackagesPortIsTheForgeModulesSettingOnThisNode(t *testing.T) {
c, control := recording(t)
o := Options{Node: "anchor", Catalogue: aCatalogueWith(t, ForgeModule, theForgesManifest),
Ports: FoundationPorts{Packages: 3100}, Wait: time.Second}
@@ -104,7 +104,7 @@ func (k *knowingControl) run(ctx context.Context, name string, args ...string) (
return out, err
}
func TestARerunDoesNotReplaceAForgeTheMeshAlreadyHas(t *testing.T) {
func testARerunDoesNotReplaceAForgeTheMeshAlreadyHas(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
k := &knowingControl{controlRecorder{settings: map[string]string{}}}
control := controlPlane{container: "mesh-controller", run: k.run, timeout: time.Second}
@@ -125,7 +125,7 @@ func TestARerunDoesNotReplaceAForgeTheMeshAlreadyHas(t *testing.T) {
}
}
func TestAGenesisOnTheCataloguesPackagesPortRegistersNoForge(t *testing.T) {
func testAGenesisOnTheCataloguesPackagesPortRegistersNoForge(t *testing.T) {
c, control := recording(t)
o := Options{Node: "anchor", Catalogue: aCatalogueWith(t, ForgeModule, theForgesManifest),
Wait: time.Second}
@@ -137,7 +137,7 @@ func TestAGenesisOnTheCataloguesPackagesPortRegistersNoForge(t *testing.T) {
}
}
func TestAForgeManifestTheCatalogueDoesNotHaveIsNamed(t *testing.T) {
func testAForgeManifestTheCatalogueDoesNotHaveIsNamed(t *testing.T) {
_, control := recording(t)
o := Options{Node: "anchor", Catalogue: t.TempDir(),
Ports: FoundationPorts{Packages: 3100}, Wait: time.Second}
@@ -182,7 +182,7 @@ func theCataloguesModule(t *testing.T, module string) []byte {
// one-holder `builder` left the catalogue on 2026-10-03, and genesis stopped at step 13 asking for it.
// The catalogue's own manifest is read, and the image the installer carried is put where the manifest
// names the image it builds.
func TestGenesisInstallsTheCataloguesBuildAgent(t *testing.T) {
func testGenesisInstallsTheCataloguesBuildAgent(t *testing.T) {
manifest := theCataloguesModule(t, BuilderModule)
const reference = "127.0.0.1:5000/mesh-builder@sha256:" + "4444444444444444444444444444444444444444444444444444444444444444"
pinned, places, err := pinTheCarriedBuilder(manifest, reference)
@@ -221,7 +221,7 @@ func TestGenesisInstallsTheCataloguesBuildAgent(t *testing.T) {
// A manifest that runs nothing from an image it builds has nowhere to put the carried builder, and is
// refused rather than registered running nothing.
func TestABuildAgentManifestWithNowhereForTheCarriedBuilderIsRefused(t *testing.T) {
func testABuildAgentManifestWithNowhereForTheCarriedBuilderIsRefused(t *testing.T) {
_, _, err := pinTheCarriedBuilder([]byte(`{"module":"build-agent","resources":[{"id":"server","type":"container","name":"x","artifact":"server"}],"build":{"artifacts":[{"name":"server","kind":"bundle"}]}}`),
"127.0.0.1:5000/mesh-builder@sha256:"+strings.Repeat("4", 64))
if err == nil || !strings.Contains(err.Error(), "nowhere to put") {
@@ -232,7 +232,7 @@ func TestABuildAgentManifestWithNowhereForTheCarriedBuilderIsRefused(t *testing.
// 1151: the build agent's manifest lives in the controller's repository now (ADR 0420, issue 1019), and a merge check of
// this repository has the controller cloned beside it, so a tree shaped like that check's, whose catalogue no longer holds
// the build agent, is read from the controller.
func TestTheBuildAgentsManifestIsReadFromTheControllerBesideTheCheck(t *testing.T) {
func testTheBuildAgentsManifestIsReadFromTheControllerBesideTheCheck(t *testing.T) {
beside := t.TempDir()
for path, body := range map[string]string{
"mesh-catalog/modules/nats/module.json": `{"module":"nats"}`,
@@ -254,3 +254,15 @@ func TestTheBuildAgentsManifestIsReadFromTheControllerBesideTheCheck(t *testing.
t.Errorf("a module the catalogue holds was read as %s", got)
}
}
// TestBuilder runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestBuilder(t *testing.T) {
t.Run("TheBuilderOnTheDefaultPackagesPortIsToldNothing", testTheBuilderOnTheDefaultPackagesPortIsToldNothing)
t.Run("ThePackagesPortIsTheForgeModulesSettingOnThisNode", testThePackagesPortIsTheForgeModulesSettingOnThisNode)
t.Run("ARerunDoesNotReplaceAForgeTheMeshAlreadyHas", testARerunDoesNotReplaceAForgeTheMeshAlreadyHas)
t.Run("AGenesisOnTheCataloguesPackagesPortRegistersNoForge", testAGenesisOnTheCataloguesPackagesPortRegistersNoForge)
t.Run("AForgeManifestTheCatalogueDoesNotHaveIsNamed", testAForgeManifestTheCatalogueDoesNotHaveIsNamed)
t.Run("GenesisInstallsTheCataloguesBuildAgent", testGenesisInstallsTheCataloguesBuildAgent)
t.Run("ABuildAgentManifestWithNowhereForTheCarriedBuilderIsRefused", testABuildAgentManifestWithNowhereForTheCarriedBuilderIsRefused)
t.Run("TheBuildAgentsManifestIsReadFromTheControllerBesideTheCheck", testTheBuildAgentsManifestIsReadFromTheControllerBesideTheCheck)
}
+10 -3
View File
@@ -13,7 +13,7 @@ import (
// image, and the mesh replaces its bus only as a planned step. A plain push was refused — "sending anchor
// would replace the bus … a planned step: `bus upgrade --why …`" — and genesis stopped at step 18.
func TestTheBrokerStepAdoptsTheBusThroughItsPlannedStep(t *testing.T) {
func testTheBrokerStepAdoptsTheBusThroughItsPlannedStep(t *testing.T) {
catalogue := aCatalogue(t, map[string]string{BusModule: aBusModule(theModulesLayout)})
rewritten, err := Rewrite(theRealBundle(t), held)
if err != nil {
@@ -95,7 +95,7 @@ func TestTheBrokerStepAdoptsTheBusThroughItsPlannedStep(t *testing.T) {
}
// A planned step the controller ends failed is the broker step failing, with the controller's words.
func TestABusStepThatEndsFailedIsRefused(t *testing.T) {
func testABusStepThatEndsFailedIsRefused(t *testing.T) {
aGenesisBusOnDisk(t)
runtime := &asked{answer: func(name string, args []string) (string, error) {
return "last step 1: not known → 53e51864 on anchor by installer (x): failed at 2026-10-13 11:59; snapshot s\n" +
@@ -112,7 +112,7 @@ func TestABusStepThatEndsFailedIsRefused(t *testing.T) {
// server release and is reversible as the step says (ADR 0333 §3). The module takes the server as an upstream
// artifact, its image reference pinned by digest (issue 1641); it no longer builds an image on a NATS_BASE argument,
// which this test read until issue 1875.
func TestTheBundlesBusRunsTheReleaseTheModulesImageIsBuiltOn(t *testing.T) {
func testTheBundlesBusRunsTheReleaseTheModulesImageIsBuiltOn(t *testing.T) {
var m struct {
Build struct {
Artifacts []struct{ Name, Kind, From string } `json:"artifacts"`
@@ -148,3 +148,10 @@ func TestTheBundlesBusRunsTheReleaseTheModulesImageIsBuiltOn(t *testing.T) {
}
}
}
// TestBusAdoption runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestBusAdoption(t *testing.T) {
t.Run("TheBrokerStepAdoptsTheBusThroughItsPlannedStep", testTheBrokerStepAdoptsTheBusThroughItsPlannedStep)
t.Run("ABusStepThatEndsFailedIsRefused", testABusStepThatEndsFailedIsRefused)
t.Run("TheBundlesBusRunsTheReleaseTheModulesImageIsBuiltOn", testTheBundlesBusRunsTheReleaseTheModulesImageIsBuiltOn)
}
+12 -4
View File
@@ -8,7 +8,7 @@ import (
func quietly(string) {}
// A flag answers, and answers wrongly is refused naming what would have worked.
func TestAFlagAnswersAndAWrongOneIsRefused(t *testing.T) {
func testAFlagAnswersAndAWrongOneIsRefused(t *testing.T) {
filter := Choice{Name: "packet-filter", Options: []string{"nftables", "ufw"}}
got, err := decide(filter, "ufw", nil, quietly)
@@ -27,7 +27,7 @@ func TestAFlagAnswersAndAWrongOneIsRefused(t *testing.T) {
// A lone option answers itself — and says so, because "it chose for me" and "there was nothing to
// choose" read identically afterwards unless one of them speaks.
func TestALoneOptionAnswersItselfAloud(t *testing.T) {
func testALoneOptionAnswersItselfAloud(t *testing.T) {
var said []string
got, err := decide(Choice{Name: "private-network", Options: []string{"wireguard"}},
"", nil, func(line string) { said = append(said, line) })
@@ -40,7 +40,7 @@ func TestALoneOptionAnswersItselfAloud(t *testing.T) {
}
// A terminal is asked; an empty answer takes the default when there is one.
func TestATerminalIsAskedAndEmptyTakesTheDefault(t *testing.T) {
func testATerminalIsAskedAndEmptyTakesTheDefault(t *testing.T) {
asked := 0
prompt := func(c Choice) (string, error) { asked++; return "", nil }
got, err := decide(Choice{Name: "extras", Default: "none"}, "", prompt, quietly)
@@ -52,7 +52,7 @@ func TestATerminalIsAskedAndEmptyTakesTheDefault(t *testing.T) {
// **Unattended and required is a refusal, not a guess.** The lab and any machine without a
// terminal must be answerable by flags — and a required choice with no flag has to stop the run
// naming the flag, because a guessed packet filter is a machine somebody else configured.
func TestUnattendedAndRequiredRefusesNamingTheFlag(t *testing.T) {
func testUnattendedAndRequiredRefusesNamingTheFlag(t *testing.T) {
_, err := decide(Choice{Name: "packet-filter", Options: []string{"nftables", "ufw"}},
"", nil, quietly)
if err == nil {
@@ -62,3 +62,11 @@ func TestUnattendedAndRequiredRefusesNamingTheFlag(t *testing.T) {
t.Fatalf("the refusal does not name the flag that answers it: %v", err)
}
}
// TestChoices runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestChoices(t *testing.T) {
t.Run("AFlagAnswersAndAWrongOneIsRefused", testAFlagAnswersAndAWrongOneIsRefused)
t.Run("ALoneOptionAnswersItselfAloud", testALoneOptionAnswersItselfAloud)
t.Run("ATerminalIsAskedAndEmptyTakesTheDefault", testATerminalIsAskedAndEmptyTakesTheDefault)
t.Run("UnattendedAndRequiredRefusesNamingTheFlag", testUnattendedAndRequiredRefusesNamingTheFlag)
}
+24 -10
View File
@@ -71,7 +71,7 @@ func theBuild(manifest string) Built {
// which only the machine that built it can resolve; the mesh's record must name what the registry
// assigned, `<registry>/<repository>@sha256:…`, or every other machine the module is pushed to
// would go looking for an image nothing serves.
func TestTheControlPlaneIsPinnedToWhatThisMeshsRegistryAssigned(t *testing.T) {
func testTheControlPlaneIsPinnedToWhatThisMeshsRegistryAssigned(t *testing.T) {
pinned, places, err := pinImage([]byte(theControlPlaneModule), builtImage, pushedReference, "mesh-controller")
if err != nil {
t.Fatal(err)
@@ -90,7 +90,7 @@ func TestTheControlPlaneIsPinnedToWhatThisMeshsRegistryAssigned(t *testing.T) {
// A manifest naming some other image describes some other build. Registering it would install a
// control plane that is not the image this machine just published, which is the one thing this
// step exists to guarantee.
func TestAManifestNamingAnotherBuildIsRefused(t *testing.T) {
func testAManifestNamingAnotherBuildIsRefused(t *testing.T) {
other := strings.Replace(theControlPlaneModule, builtImage, "sha256:"+strings.Repeat("9", 64), 1)
if _, _, err := pinImage([]byte(other), builtImage, pushedReference, "mesh-controller"); err == nil {
t.Fatal("a manifest naming some other image was accepted")
@@ -99,7 +99,7 @@ func TestAManifestNamingAnotherBuildIsRefused(t *testing.T) {
// Every place moves. A manifest naming its image in a second resource — a migrate step beside the
// server — would otherwise be left half pinned, and fail inside an apply rather than here.
func TestEveryPlaceTheManifestNamesTheImageIsPinned(t *testing.T) {
func testEveryPlaceTheManifestNamesTheImageIsPinned(t *testing.T) {
twice := strings.Replace(theControlPlaneModule,
`{"id": "mesh-state", "type": "directory", "path": "/var/lib/mesh/mesh-controller", "mode": "0700"},`,
`{"id": "mesh-state", "type": "directory", "path": "/var/lib/mesh/mesh-controller", "mode": "0700"},
@@ -123,7 +123,7 @@ func TestEveryPlaceTheManifestNamesTheImageIsPinned(t *testing.T) {
// and thirty-two random bytes in their place would leave the control plane unable to open a single
// context. The pairing is read from the manifest so that whatever the catalogue calls these
// secrets is what is delivered.
func TestTheStoreConnectionsComeFromTheBundleThatMadeThem(t *testing.T) {
func testTheStoreConnectionsComeFromTheBundleThatMadeThem(t *testing.T) {
wanted, err := secretsByVariableIn([]byte(theControlPlaneModule))
if err != nil {
t.Fatal(err)
@@ -174,7 +174,7 @@ func TestTheStoreConnectionsComeFromTheBundleThatMadeThem(t *testing.T) {
// A secret the foundation did not make is left for the mesh to make, and said so. Every other
// secret in a mesh is one the mesh made; `secret accept` is only for what predates the mesh.
func TestASecretTheFoundationNeverMadeIsLeftToTheMesh(t *testing.T) {
func testASecretTheFoundationNeverMadeIsLeftToTheMesh(t *testing.T) {
extra := strings.Replace(theControlPlaneModule,
`"bus": "/var/lib/mesh/mesh-controller/bus"`,
`"bus": "/var/lib/mesh/mesh-controller/bus",
@@ -212,7 +212,7 @@ func TestASecretTheFoundationNeverMadeIsLeftToTheMesh(t *testing.T) {
// A manifest whose container reads a file no own-secret writes is refused. The mesh would seal
// nothing there and the control plane would find an empty file where a connection string has to
// be — which presents as a control plane that will not start, three steps from the cause.
func TestAConnectionFileNothingWritesIsRefused(t *testing.T) {
func testAConnectionFileNothingWritesIsRefused(t *testing.T) {
mismatched := strings.Replace(theControlPlaneModule,
`"inventory": "/var/lib/mesh/mesh-controller/inventory",`,
`"inventory": "/var/lib/mesh/mesh-controller/somewhere-else",`, 1)
@@ -229,7 +229,7 @@ func TestAConnectionFileNothingWritesIsRefused(t *testing.T) {
// A manifest asking for no store connections at all describes a control plane that can open
// nothing, and the refusal says what shape the installer delivers into — because the manifest is
// written in another repository and this is where the two have to agree.
func TestAManifestWantingNoStoresIsRefusedWithTheShapeItShouldHave(t *testing.T) {
func testAManifestWantingNoStoresIsRefusedWithTheShapeItShouldHave(t *testing.T) {
rewritten, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -254,7 +254,7 @@ func TestAManifestWantingNoStoresIsRefusedWithTheShapeItShouldHave(t *testing.T)
// The permanent control plane is asked a question, not merely looked at — the same question the
// temporary one was asked at step 5, and for the same reason: `status` opens all three stores, so
// a reply proves the sealed connections it was given are the ones the foundation made.
func TestThePermanentControlPlaneIsAskedTheSameQuestion(t *testing.T) {
func testThePermanentControlPlaneIsAskedTheSameQuestion(t *testing.T) {
runtime := &asked{answer: aMeshThatAgrees(map[string]string{
"module list": "",
"exec mesh-controller /mesh-controller": "1 node, 0 waiting\n",
@@ -287,7 +287,7 @@ func TestThePermanentControlPlaneIsAskedTheSameQuestion(t *testing.T) {
// The broker settings take the file shape too (novox/hq ADR 0086): a `MESH_BROKER_…_FILE` pointing
// at a mounted own-secret is delivered as that secret, exactly as a store connection is.
func TestABrokerSettingReadFromAFileIsDeliveredToo(t *testing.T) {
func testABrokerSettingReadFromAFileIsDeliveredToo(t *testing.T) {
manifest := `{
"module": "mesh-controller", "version": "1",
"own-secrets": {"broker": "/var/lib/mesh/mesh-controller/broker", "inventory": "/var/lib/mesh/mesh-controller/inventory"},
@@ -311,7 +311,7 @@ func TestABrokerSettingReadFromAFileIsDeliveredToo(t *testing.T) {
}
// Step 9 with nothing built is a caller's fault, and it stops rather than pretending to pivot.
func TestTheControlPlaneCannotBeInstalledWithoutABuild(t *testing.T) {
func testTheControlPlaneCannotBeInstalledWithoutABuild(t *testing.T) {
runtime := &asked{answer: aMeshThatAgrees(map[string]string{})}
control := controlPlane{container: "temp-mesh-controller", run: runtime.run, timeout: time.Second}
rewritten, err := Rewrite(theRealBundle(t), held)
@@ -327,3 +327,17 @@ func TestTheControlPlaneCannotBeInstalledWithoutABuild(t *testing.T) {
t.Error("something was registered without a manifest")
}
}
// TestControl runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestControl(t *testing.T) {
t.Run("TheControlPlaneIsPinnedToWhatThisMeshsRegistryAssigned", testTheControlPlaneIsPinnedToWhatThisMeshsRegistryAssigned)
t.Run("AManifestNamingAnotherBuildIsRefused", testAManifestNamingAnotherBuildIsRefused)
t.Run("EveryPlaceTheManifestNamesTheImageIsPinned", testEveryPlaceTheManifestNamesTheImageIsPinned)
t.Run("TheStoreConnectionsComeFromTheBundleThatMadeThem", testTheStoreConnectionsComeFromTheBundleThatMadeThem)
t.Run("ASecretTheFoundationNeverMadeIsLeftToTheMesh", testASecretTheFoundationNeverMadeIsLeftToTheMesh)
t.Run("AConnectionFileNothingWritesIsRefused", testAConnectionFileNothingWritesIsRefused)
t.Run("AManifestWantingNoStoresIsRefusedWithTheShapeItShouldHave", testAManifestWantingNoStoresIsRefusedWithTheShapeItShouldHave)
t.Run("ThePermanentControlPlaneIsAskedTheSameQuestion", testThePermanentControlPlaneIsAskedTheSameQuestion)
t.Run("ABrokerSettingReadFromAFileIsDeliveredToo", testABrokerSettingReadFromAFileIsDeliveredToo)
t.Run("TheControlPlaneCannotBeInstalledWithoutABuild", testTheControlPlaneCannotBeInstalledWithoutABuild)
}
+24 -10
View File
@@ -53,7 +53,7 @@ func arch(t *testing.T) system.System {
// A machine that has already enrolled is not enrolled again, and no token is spent on it. The
// installer is run over and over; a second identity is one the mesh does not know, and the mesh
// believes the first.
func TestAMachineThatHasAlreadyEnrolledIsNotEnrolledAgain(t *testing.T) {
func testAMachineThatHasAlreadyEnrolledIsNotEnrolledAgain(t *testing.T) {
runtime := &asked{answer: func(name string, args []string) (string, error) {
joined := strings.Join(args, " ")
switch {
@@ -99,7 +99,7 @@ func TestAMachineThatHasAlreadyEnrolledIsNotEnrolledAgain(t *testing.T) {
// itself the thing that makes the mesh hear. Taken as proof of life it ends the step believing an
// agent it never started, and everything after is the control plane being told things that never
// reach the machine: the next push is accepted, recorded, and applied by nobody.
func TestAMeshThatHasHeardFromAMachineWithNoAgentStartsOne(t *testing.T) {
func testAMeshThatHasHeardFromAMachineWithNoAgentStartsOne(t *testing.T) {
runtime := &asked{answer: func(name string, args []string) (string, error) {
joined := strings.Join(args, " ")
switch {
@@ -135,7 +135,7 @@ func TestAMeshThatHasHeardFromAMachineWithNoAgentStartsOne(t *testing.T) {
// A machine already enrolled under ANOTHER name is refused, with what to do about it. Re-enrolling
// replaces the identity the mesh recorded, which is a deliberate act and not something an
// installer does on its own.
func TestAMachineEnrolledUnderAnotherNameIsRefused(t *testing.T) {
func testAMachineEnrolledUnderAnotherNameIsRefused(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
if strings.Contains(strings.Join(args, " "), "node list") {
return "somewhere-else here 01J0\n", nil
@@ -161,7 +161,7 @@ func TestAMachineEnrolledUnderAnotherNameIsRefused(t *testing.T) {
// running and cannot reach the broker looks exactly like a successful install until the first push
// silently applies nothing — which is the class of fault this whole program exists to stop being
// found late.
func TestAHostThatIsRunningAndUnheardOfIsNotAnInstall(t *testing.T) {
func testAHostThatIsRunningAndUnheardOfIsNotAnInstall(t *testing.T) {
previous := answerEvery
answerEvery = time.Millisecond
defer func() { answerEvery = previous }()
@@ -198,7 +198,7 @@ func TestAHostThatIsRunningAndUnheardOfIsNotAnInstall(t *testing.T) {
// A machine with no service to start is refused, and the refusal says what is missing rather than
// inventing a unit file. What a unit says is a packaging decision, and an installer writing one
// would put a file on the machine that whatever installed the host will disagree with.
func TestAMachineWithNoHostServiceIsRefusedRatherThanGivenOne(t *testing.T) {
func testAMachineWithNoHostServiceIsRefusedRatherThanGivenOne(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
joined := strings.Join(args, " ")
switch {
@@ -231,7 +231,7 @@ func TestAMachineWithNoHostServiceIsRefusedRatherThanGivenOne(t *testing.T) {
// A machine with no name is refused before anything is said to the mesh. The name is what the
// record, the token, the assignment and the push all name, and one the installer invented would
// match nothing anybody types anywhere else.
func TestAMachineWithNoNameIsRefusedBeforeAnythingIsAsked(t *testing.T) {
func testAMachineWithNoNameIsRefusedBeforeAnythingIsAsked(t *testing.T) {
runtime := &asked{answer: func(string, []string) (string, error) {
return "", fmt.Errorf("nothing should have been asked")
}}
@@ -247,7 +247,7 @@ func TestAMachineWithNoNameIsRefusedBeforeAnythingIsAsked(t *testing.T) {
// The token is found in what the mesh said, by the rule the lab uses: the one long unbroken line.
// The installer does not parse a format the control plane owns.
func TestTheTokenIsFoundInWhatTheMeshSaid(t *testing.T) {
func testTheTokenIsFoundInWhatTheMeshSaid(t *testing.T) {
said := "a token for anchor, good once:\n\n " + strings.Repeat("t", 240) + "\n\n" +
"carry it to the machine and run: mesh-host enrol --token <token>\n"
token, err := tokenIn(said)
@@ -266,7 +266,7 @@ func TestTheTokenIsFoundInWhatTheMeshSaid(t *testing.T) {
// A listing's name is matched as a whole word at the start of a line, so `registry` is not found
// inside `registry-mirror`. A substring match would report a module installed that is not, and the
// installer would skip creating it.
func TestAListingIsMatchedByNameAndNotBySubstring(t *testing.T) {
func testAListingIsMatchedByNameAndNotBySubstring(t *testing.T) {
listing := "registry-mirror 1 built abc\nother 1 built def\n"
if mentions(listing, "registry") {
t.Error("registry-mirror was read as registry")
@@ -280,7 +280,7 @@ func TestAListingIsMatchedByNameAndNotBySubstring(t *testing.T) {
// 04-ISSUES/146). The enrolment account exists only in the mesh's records until somebody writes it
// beside the bus; so does the node's own, minted as it enrols. Without the first, the machine is
// refused by the bus it just raised; without the second, its agent is.
func TestAFirstNodeIsLetOntoTheBusItRaised(t *testing.T) {
func testAFirstNodeIsLetOntoTheBusItRaised(t *testing.T) {
enrolled := false
runtime := &asked{answer: func(name string, args []string) (string, error) {
joined := strings.Join(args, " ")
@@ -333,7 +333,7 @@ func TestAFirstNodeIsLetOntoTheBusItRaised(t *testing.T) {
// controller's list again (novox/hq ADR 0331 §5, review of mesh-host #96). The apply just wrote the
// bundle's list — the controller alone — over the one placed at enrolment; left so, the next time the
// bus re-reads it every node and the enrolment account are refused.
func TestARerunOnAnEnrolledMachineWhoseBusIsNotAdoptedPlacesTheUsersAgain(t *testing.T) {
func testARerunOnAnEnrolledMachineWhoseBusIsNotAdoptedPlacesTheUsersAgain(t *testing.T) {
runtime := &asked{answer: func(name string, args []string) (string, error) {
joined := strings.Join(args, " ")
switch {
@@ -374,3 +374,17 @@ func TestARerunOnAnEnrolledMachineWhoseBusIsNotAdoptedPlacesTheUsersAgain(t *tes
strings.Join(runtime.commands, "\n"))
}
}
// TestEnrol runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestEnrol(t *testing.T) {
t.Run("AMachineThatHasAlreadyEnrolledIsNotEnrolledAgain", testAMachineThatHasAlreadyEnrolledIsNotEnrolledAgain)
t.Run("AMeshThatHasHeardFromAMachineWithNoAgentStartsOne", testAMeshThatHasHeardFromAMachineWithNoAgentStartsOne)
t.Run("AMachineEnrolledUnderAnotherNameIsRefused", testAMachineEnrolledUnderAnotherNameIsRefused)
t.Run("AHostThatIsRunningAndUnheardOfIsNotAnInstall", testAHostThatIsRunningAndUnheardOfIsNotAnInstall)
t.Run("AMachineWithNoHostServiceIsRefusedRatherThanGivenOne", testAMachineWithNoHostServiceIsRefusedRatherThanGivenOne)
t.Run("AMachineWithNoNameIsRefusedBeforeAnythingIsAsked", testAMachineWithNoNameIsRefusedBeforeAnythingIsAsked)
t.Run("TheTokenIsFoundInWhatTheMeshSaid", testTheTokenIsFoundInWhatTheMeshSaid)
t.Run("AListingIsMatchedByNameAndNotBySubstring", testAListingIsMatchedByNameAndNotBySubstring)
t.Run("AFirstNodeIsLetOntoTheBusItRaised", testAFirstNodeIsLetOntoTheBusItRaised)
t.Run("ARerunOnAnEnrolledMachineWhoseBusIsNotAdoptedPlacesTheUsersAgain", testARerunOnAnEnrolledMachineWhoseBusIsNotAdoptedPlacesTheUsersAgain)
}
+14 -5
View File
@@ -67,7 +67,7 @@ func aRepository(t *testing.T, manifest string, then func(string, []string) (str
// novox/hq issue 223: a controller declared as a process is raised at genesis as a container built
// from its own Dockerfile, not by the builder — which has no Go toolchain at genesis and would refuse.
func TestAProcessFormControllerIsBuiltFromItsDockerfileAndRaisedAsAContainer(t *testing.T) {
func testAProcessFormControllerIsBuiltFromItsDockerfileAndRaisedAsAContainer(t *testing.T) {
runtime := &asked{answer: aRepository(t, processFormManifest, func(name string, args []string) (string, error) {
if name == "docker" && args[0] == "build" {
return builtImage + "\n", nil
@@ -152,7 +152,7 @@ func TestAProcessFormControllerIsBuiltFromItsDockerfileAndRaisedAsAContainer(t *
}
// An older controller — an image and a container — is still built by the builder, as before.
func TestAnImageFormControllerIsStillBuiltByTheBuilder(t *testing.T) {
func testAnImageFormControllerIsStillBuiltByTheBuilder(t *testing.T) {
manifest := `{"module":"mesh-controller","version":"1","resources":[` +
`{"id":"server","type":"container","name":"mesh-controller","image":"` + builtImage + `"}]}`
runtime := &asked{answer: aRepository(t, imageFormManifest, func(name string, args []string) (string, error) {
@@ -172,7 +172,7 @@ func TestAnImageFormControllerIsStillBuiltByTheBuilder(t *testing.T) {
}
}
func TestAProcessFormNamingNoOneReplacementIsRefused(t *testing.T) {
func testAProcessFormNamingNoOneReplacementIsRefused(t *testing.T) {
for _, bad := range []string{`"replaces": []`, `"replaces": ["a", "b"]`} {
raw := strings.Replace(processFormManifest, `"replaces": ["server"]`, bad, 1)
if _, err := processFormOf([]byte(raw)); err == nil {
@@ -204,7 +204,7 @@ func theStepNineSecretsOf(t *testing.T, manifest []byte) (map[string]string, err
// window's settings reach the controller in a file its manifest declares from its settings
// (MESH_MERGE_WINDOW_FILE, ADR 0276); genesis refused it as a secret nobody writes, and stopped at
// step 11 of 24.
func TestAFileTheControllersManifestWritesIsNotASecret(t *testing.T) {
func testAFileTheControllersManifestWritesIsNotASecret(t *testing.T) {
manifest := strings.Replace(processFormManifest,
`{"id": "controller", "type": "process",`,
`{"id": "merge-window", "type": "file", "path": "${dir:mesh-state}/merge-window.json", "mode": "0600",
@@ -229,7 +229,7 @@ func TestAFileTheControllersManifestWritesIsNotASecret(t *testing.T) {
}
// And a `…_FILE` that neither an own-secret nor a file of the module writes is still refused.
func TestAFileNothingOfTheControllerWritesIsStillRefused(t *testing.T) {
func testAFileNothingOfTheControllerWritesIsStillRefused(t *testing.T) {
manifest := strings.Replace(processFormManifest, `"MESH_BUS_NATS_FILE": "${dir:mesh-state}/bus"}`,
`"MESH_BUS_NATS_FILE": "${dir:mesh-state}/bus",
"MESH_MERGE_WINDOW_FILE": "${dir:mesh-state}/merge-window.json"}`, 1)
@@ -237,3 +237,12 @@ func TestAFileNothingOfTheControllerWritesIsStillRefused(t *testing.T) {
t.Fatalf("a file nothing writes was accepted, or refused without its name: %v", err)
}
}
// TestGenesisForm runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestGenesisForm(t *testing.T) {
t.Run("AProcessFormControllerIsBuiltFromItsDockerfileAndRaisedAsAContainer", testAProcessFormControllerIsBuiltFromItsDockerfileAndRaisedAsAContainer)
t.Run("AnImageFormControllerIsStillBuiltByTheBuilder", testAnImageFormControllerIsStillBuiltByTheBuilder)
t.Run("AProcessFormNamingNoOneReplacementIsRefused", testAProcessFormNamingNoOneReplacementIsRefused)
t.Run("AFileTheControllersManifestWritesIsNotASecret", testAFileTheControllersManifestWritesIsNotASecret)
t.Run("AFileNothingOfTheControllerWritesIsStillRefused", testAFileNothingOfTheControllerWritesIsStillRefused)
}
+8 -2
View File
@@ -13,7 +13,7 @@ import (
// the base, so until then the packages step's genesis document is how the sdk and base steps reach the
// forge.
func TestThePackagesStepSealsTheGenesisDocumentToTheBuildAgent(t *testing.T) {
func testThePackagesStepSealsTheGenesisDocumentToTheBuildAgent(t *testing.T) {
if BuilderModule != "build-agent" {
t.Fatalf("genesis installs %q; the document is the build agent's", BuilderModule)
}
@@ -42,7 +42,7 @@ func TestThePackagesStepSealsTheGenesisDocumentToTheBuildAgent(t *testing.T) {
// What the retired builder was given and the build agent declares neither of: an `npm-password`
// own-secret and a `serves` setting for its carried binding (ADR 0336 §3).
func TestNoStepGivesTheBuildAgentAServesSettingOrAnNpmPassword(t *testing.T) {
func testNoStepGivesTheBuildAgentAServesSettingOrAnNpmPassword(t *testing.T) {
for _, module := range []string{BuilderModule} {
c, control := recording(t)
o := Options{Node: "anchor", Ports: FoundationPorts{Packages: 3100}, Wait: time.Second}
@@ -63,3 +63,9 @@ func TestNoStepGivesTheBuildAgentAServesSettingOrAnNpmPassword(t *testing.T) {
}
}
}
// TestGenesisRegistry runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestGenesisRegistry(t *testing.T) {
t.Run("ThePackagesStepSealsTheGenesisDocumentToTheBuildAgent", testThePackagesStepSealsTheGenesisDocumentToTheBuildAgent)
t.Run("NoStepGivesTheBuildAgentAServesSettingOrAnNpmPassword", testNoStepGivesTheBuildAgentAServesSettingOrAnNpmPassword)
}
+10 -3
View File
@@ -20,7 +20,7 @@ var genesisModules = []string{RegistryModule, BuilderModule, "postgres", BusModu
// Every genesis module's bundles are compiled in a toolchain the base step builds, read from the real
// catalogue's manifests: a module that gains a language genesis does not build fails here, not at a
// genesis.
func TestTheBaseStepBuildsEveryToolchainAGenesisModuleIsCompiledIn(t *testing.T) {
func testTheBaseStepBuildsEveryToolchainAGenesisModuleIsCompiledIn(t *testing.T) {
// ADR 0604 section 7: the catalog is the indexer's seat now, so genesis has no catalogue step and installs or takes no
// mesh-catalog module.
for _, step := range Steps {
@@ -64,7 +64,7 @@ func TestTheBaseStepBuildsEveryToolchainAGenesisModuleIsCompiledIn(t *testing.T)
}
// And the base step asks for each toolchain's build: the base, then the Go toolchain beside it.
func TestTheBaseStepBuildsTheGoToolchainBesideTheBase(t *testing.T) {
func testTheBaseStepBuildsTheGoToolchainBesideTheBase(t *testing.T) {
runtime := &asked{answer: aMeshThatAgrees(nil)}
control := controlPlane{container: "mesh-controller", run: runtime.run, timeout: time.Second}
o := Options{ToolsSource: Source{Repository: "git://192.0.2.30/mesh-tools.git"}}
@@ -86,7 +86,7 @@ func TestTheBaseStepBuildsTheGoToolchainBesideTheBase(t *testing.T) {
}
}
func TestTheGoToolchainIsAsGivenOrBesideTheBase(t *testing.T) {
func testTheGoToolchainIsAsGivenOrBesideTheBase(t *testing.T) {
for _, c := range []struct{ tools, given, want string }{
{"http://forge/novox/mesh-tools.git", "", "http://forge/novox/mesh-tools-go.git"},
{"http://forge/novox/mesh-tools", "", "http://forge/novox/mesh-tools-go"},
@@ -102,3 +102,10 @@ func TestTheGoToolchainIsAsGivenOrBesideTheBase(t *testing.T) {
t.Errorf("a base not named mesh-tools, and no Go toolchain given, was not refused naming the flag: %v", err)
}
}
// TestGenesisToolchains runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestGenesisToolchains(t *testing.T) {
t.Run("TheBaseStepBuildsEveryToolchainAGenesisModuleIsCompiledIn", testTheBaseStepBuildsEveryToolchainAGenesisModuleIsCompiledIn)
t.Run("TheBaseStepBuildsTheGoToolchainBesideTheBase", testTheBaseStepBuildsTheGoToolchainBesideTheBase)
t.Run("TheGoToolchainIsAsGivenOrBesideTheBase", testTheGoToolchainIsAsGivenOrBesideTheBase)
}
+20 -8
View File
@@ -38,7 +38,7 @@ func (m inUseRunner) run(_ context.Context, name string, args ...string) (string
return m.ss, nil
}
func TestAFreshMachineIsNotInUse(t *testing.T) {
func testAFreshMachineIsNotInUse(t *testing.T) {
containers, listeners, err := InUse(context.Background(), inUseRunner{ss: inUseSockets}.run,
func(string) bool { return false })
if err != nil {
@@ -49,7 +49,7 @@ func TestAFreshMachineIsNotInUse(t *testing.T) {
}
}
func TestAMachineServingIsInUse(t *testing.T) {
func testAMachineServingIsInUse(t *testing.T) {
m := inUseRunner{ps: "hello-web\t\nmesh-store\tabc123\n", ss: inUseSockets + servingSockets}
containers, listeners, err := InUse(context.Background(), m.run, func(string) bool { return false })
if err != nil {
@@ -67,7 +67,7 @@ func TestAMachineServingIsInUse(t *testing.T) {
}
}
func TestAConvergedGenesisRefusesAMachineInUseNamingEverything(t *testing.T) {
func testAConvergedGenesisRefusesAMachineInUseNamingEverything(t *testing.T) {
o := Options{State: filepath.Join(t.TempDir(), "state.json")}
m := inUseRunner{ps: "hello-web\t\n", ss: inUseSockets + servingSockets}
err := RefuseAMachineInUse(context.Background(), o, m.run, quietly)
@@ -86,7 +86,7 @@ func TestAConvergedGenesisRefusesAMachineInUseNamingEverything(t *testing.T) {
}
}
func TestARerunOfGenesisIsNotAMachineInUse(t *testing.T) {
func testARerunOfGenesisIsNotAMachineInUse(t *testing.T) {
o := Options{State: filepath.Join(t.TempDir(), "state.json")}
if err := store.Save(o.State, store.State{Resources: []store.Applied{{ID: "store", Type: "container", Target: "mesh-store"}}}); err != nil {
t.Fatal(err)
@@ -97,7 +97,7 @@ func TestARerunOfGenesisIsNotAMachineInUse(t *testing.T) {
}
}
func TestAFreshlyInstalledMachineAsMeasuredIsNotInUse(t *testing.T) {
func testAFreshlyInstalledMachineAsMeasuredIsNotInUse(t *testing.T) {
// Captured with `ss -Hltunp` on a freshly installed lab machine: its resolver listens on TCP on
// every address, which the record's words alone would count.
raw, err := os.ReadFile("testdata/fresh-machine-listeners.txt")
@@ -121,7 +121,7 @@ func TestAFreshlyInstalledMachineAsMeasuredIsNotInUse(t *testing.T) {
// Defends novox/hq ADR 0103: a machine raised adopted stays adopted if genesis is run again. The
// installer reads the mode from what the machine records, and refuses a flag that disagrees.
func TestARerunWithoutTheFlagOnAnAdoptedMachineIsRefused(t *testing.T) {
func testARerunWithoutTheFlagOnAnAdoptedMachineIsRefused(t *testing.T) {
o := Options{State: filepath.Join(t.TempDir(), "state.json")}
adoptedState := store.State{Resources: []store.Applied{
{ID: "store", Type: "container", Target: "mesh-store", Origin: store.OriginCarried},
@@ -141,7 +141,7 @@ func TestARerunWithoutTheFlagOnAnAdoptedMachineIsRefused(t *testing.T) {
}
}
func TestARerunWithTheFlagOnAConvergedMachineIsRefused(t *testing.T) {
func testARerunWithTheFlagOnAConvergedMachineIsRefused(t *testing.T) {
o := Options{State: filepath.Join(t.TempDir(), "state.json"), Adopted: true}
converged := store.State{Resources: []store.Applied{
{ID: "store", Type: "container", Target: "mesh-store", Origin: store.OriginCarried},
@@ -162,7 +162,7 @@ func TestARerunWithTheFlagOnAConvergedMachineIsRefused(t *testing.T) {
}
}
func TestOnlyTheDaemonsTheMeasurementFoundAreQuiet(t *testing.T) {
func testOnlyTheDaemonsTheMeasurementFoundAreQuiet(t *testing.T) {
// novox/hq ADR 0101: the exempt daemons are the ones a fresh machine was measured to run —
// the resolver and the network manager. A time client or a DHCP client listening beyond
// loopback is something somebody put there, and that is a machine in use.
@@ -177,3 +177,15 @@ udp UNCONN 0 0 0.0.0.0:68 0.0.0
t.Errorf("counted %d listener(s), want the time client and the DHCP client: %+v", len(listeners), listeners)
}
}
// TestInuse runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestInuse(t *testing.T) {
t.Run("AFreshMachineIsNotInUse", testAFreshMachineIsNotInUse)
t.Run("AMachineServingIsInUse", testAMachineServingIsInUse)
t.Run("AConvergedGenesisRefusesAMachineInUseNamingEverything", testAConvergedGenesisRefusesAMachineInUseNamingEverything)
t.Run("ARerunOfGenesisIsNotAMachineInUse", testARerunOfGenesisIsNotAMachineInUse)
t.Run("AFreshlyInstalledMachineAsMeasuredIsNotInUse", testAFreshlyInstalledMachineAsMeasuredIsNotInUse)
t.Run("ARerunWithoutTheFlagOnAnAdoptedMachineIsRefused", testARerunWithoutTheFlagOnAnAdoptedMachineIsRefused)
t.Run("ARerunWithTheFlagOnAConvergedMachineIsRefused", testARerunWithTheFlagOnAConvergedMachineIsRefused)
t.Run("OnlyTheDaemonsTheMeasurementFoundAreQuiet", testOnlyTheDaemonsTheMeasurementFoundAreQuiet)
}
+20 -8
View File
@@ -93,7 +93,7 @@ const (
//
// So the image is identified by its TAG, which survives save and load unchanged, and the runtime
// is asked what that tag resolves to.
func TestTheIdComesFromTheRuntimeAndNotFromTheArchive(t *testing.T) {
func testTheIdComesFromTheRuntimeAndNotFromTheArchive(t *testing.T) {
runtime := &asked{}
inspected := 0
runtime.answer = func(_ string, args []string) (string, error) {
@@ -145,7 +145,7 @@ func TestTheIdComesFromTheRuntimeAndNotFromTheArchive(t *testing.T) {
// indistinguishable from one that had never run. **Decided from what the runtime holds under the
// tag, not from what the archive predicts** — a predicted id cannot answer this question at all on
// a machine whose runtime rewrites configurations.
func TestAnImageThisMachineAlreadyHoldsIsNotLoadedAgain(t *testing.T) {
func testAnImageThisMachineAlreadyHoldsIsNotLoadedAgain(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
if len(args) > 1 && args[0] == "image" && args[1] == "inspect" {
return "sha256:" + runtimeDigest + "\n", nil
@@ -178,7 +178,7 @@ func TestAnImageThisMachineAlreadyHoldsIsNotLoadedAgain(t *testing.T) {
// A load that reported success and left nothing there is a failure, not a convergence
// (novox/hq ADR 0018). Without the read-back it would surface later as the host refusing a bundle
// naming an image nothing serves — a true message about the wrong thing.
func TestALoadThatLeftNothingBehindIsAFailure(t *testing.T) {
func testALoadThatLeftNothingBehindIsAFailure(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
if len(args) > 1 && args[0] == "image" && args[1] == "inspect" {
return "", errors.New("Error: No such image")
@@ -201,7 +201,7 @@ func TestALoadThatLeftNothingBehindIsAFailure(t *testing.T) {
// runtime has decided anything, and the id in the archive is a fact about a file rather than a
// prediction about this machine. `--dry-run` still produces and checks the bundle's shape; what it
// cannot promise is the one value that only a load can settle.
func TestADryRunLoadsNothingAndSaysTheIdIsUnconfirmed(t *testing.T) {
func testADryRunLoadsNothingAndSaysTheIdIsUnconfirmed(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
if len(args) > 1 && args[0] == "image" && args[1] == "inspect" {
return "", errors.New("Error: No such image")
@@ -231,7 +231,7 @@ func TestADryRunLoadsNothingAndSaysTheIdIsUnconfirmed(t *testing.T) {
// A dry run on a machine that already holds the image DOES know the id, because the runtime was
// asked and answered. Reading is not changing, so a dry run is entitled to that.
func TestADryRunOnAMachineThatHoldsItKnowsTheRealId(t *testing.T) {
func testADryRunOnAMachineThatHoldsItKnowsTheRealId(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
if len(args) > 1 && args[0] == "image" && args[1] == "inspect" {
return "sha256:" + runtimeDigest + "\n", nil
@@ -256,7 +256,7 @@ func TestADryRunOnAMachineThatHoldsItKnowsTheRealId(t *testing.T) {
// there is no portable name to ask the runtime about, and the only thing left is scraping the
// sentence `docker load` prints for a person — which differs between runtime versions and is
// exactly the kind of guess this whole step exists to stop making.
func TestAnUntaggedArchiveIsRefused(t *testing.T) {
func testAnUntaggedArchiveIsRefused(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
return "", fmt.Errorf("nothing should have been run: %v", args)
}}
@@ -276,7 +276,7 @@ func TestAnUntaggedArchiveIsRefused(t *testing.T) {
// An installer built from a plain checkout carries no image, and says which build step is missing.
// Discovered here, before a machine is touched, rather than after a bundle has been written.
func TestAnInstallerCarryingNoImageSaysSoRatherThanRaisingHalfAMesh(t *testing.T) {
func testAnInstallerCarryingNoImageSaysSoRatherThanRaisingHalfAMesh(t *testing.T) {
if !image.IsEmpty() {
t.Skip("this checkout has a saved image embedded")
}
@@ -296,7 +296,7 @@ func TestAnInstallerCarryingNoImageSaysSoRatherThanRaisingHalfAMesh(t *testing.T
// rewrites an image's configuration as it loads. What is still worth refusing is an answer that is
// not an id at all — that value becomes the name a bundle applies on a machine with no mesh to
// check anything against, so it is checked where the refusal can say whose mistake it is.
func TestARuntimeAnsweringSomethingThatIsNotAnImageIdIsRefused(t *testing.T) {
func testARuntimeAnsweringSomethingThatIsNotAnImageIdIsRefused(t *testing.T) {
for _, nonsense := range []string{
"mesh-controller:test",
"sha256:" + strings.Repeat("9", 63),
@@ -311,3 +311,15 @@ func TestARuntimeAnsweringSomethingThatIsNotAnImageIdIsRefused(t *testing.T) {
}
}
}
// TestLoad runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestLoad(t *testing.T) {
t.Run("TheIdComesFromTheRuntimeAndNotFromTheArchive", testTheIdComesFromTheRuntimeAndNotFromTheArchive)
t.Run("AnImageThisMachineAlreadyHoldsIsNotLoadedAgain", testAnImageThisMachineAlreadyHoldsIsNotLoadedAgain)
t.Run("ALoadThatLeftNothingBehindIsAFailure", testALoadThatLeftNothingBehindIsAFailure)
t.Run("ADryRunLoadsNothingAndSaysTheIdIsUnconfirmed", testADryRunLoadsNothingAndSaysTheIdIsUnconfirmed)
t.Run("ADryRunOnAMachineThatHoldsItKnowsTheRealId", testADryRunOnAMachineThatHoldsItKnowsTheRealId)
t.Run("AnUntaggedArchiveIsRefused", testAnUntaggedArchiveIsRefused)
t.Run("AnInstallerCarryingNoImageSaysSoRatherThanRaisingHalfAMesh", testAnInstallerCarryingNoImageSaysSoRatherThanRaisingHalfAMesh)
t.Run("ARuntimeAnsweringSomethingThatIsNotAnImageIdIsRefused", testARuntimeAnsweringSomethingThatIsNotAnImageIdIsRefused)
}
+10 -3
View File
@@ -7,7 +7,7 @@ import (
// The endpoint other machines dial defaults to the host they already dial — the broker's — on
// WireGuard's port. One fact, not two that drift.
func TestTheEndpointDerivesFromTheBrokerAddress(t *testing.T) {
func testTheEndpointDerivesFromTheBrokerAddress(t *testing.T) {
if got := derivedEndpoint("192.0.2.10:5671", 51820); got != "192.0.2.10:51820" {
t.Fatalf("derived %q", got)
}
@@ -18,7 +18,7 @@ func TestTheEndpointDerivesFromTheBrokerAddress(t *testing.T) {
// A manifest with artifacts builds; one without does not — which is what separates postgres (a
// bundle to compile) from nftables (a package and a service).
func TestOnlyAManifestWithArtifactsBuilds(t *testing.T) {
func testOnlyAManifestWithArtifactsBuilds(t *testing.T) {
if !builds([]byte(`{"build":{"artifacts":[{"name":"x"}]}}`)) {
t.Fatal("a manifest with artifacts was not built")
}
@@ -29,7 +29,7 @@ func TestOnlyAManifestWithArtifactsBuilds(t *testing.T) {
// Defends novox/hq ADR 0100: the hub's port is the node's, and the endpoint other machines dial
// must name it — an endpoint on another port is an address nothing answers on.
func TestTheEndpointAgreesWithTheHubsPort(t *testing.T) {
func testTheEndpointAgreesWithTheHubsPort(t *testing.T) {
if got, err := endpointAgrees("192.0.2.10:51820", 51820); err != nil || got != "192.0.2.10:51820" {
t.Errorf("an endpoint on the hub's port: %q %v", got, err)
}
@@ -44,3 +44,10 @@ func TestTheEndpointAgreesWithTheHubsPort(t *testing.T) {
t.Error("an endpoint whose port is not a number was accepted")
}
}
// TestPhase2 runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestPhase2(t *testing.T) {
t.Run("TheEndpointDerivesFromTheBrokerAddress", testTheEndpointDerivesFromTheBrokerAddress)
t.Run("OnlyAManifestWithArtifactsBuilds", testOnlyAManifestWithArtifactsBuilds)
t.Run("TheEndpointAgreesWithTheHubsPort", testTheEndpointAgreesWithTheHubsPort)
}
+26 -11
View File
@@ -92,7 +92,7 @@ func busStep(t *testing.T, catalogue string) (*asked, error) {
// The broker step adopts the foundation's bus as the nats module (novox/hq ADR 0331 §1): the module
// the mesh goes on managing, registered from the catalogue — never lavinmq, which left it.
func TestTheBrokerStepAdoptsTheBusAsTheNatsModule(t *testing.T) {
func testTheBrokerStepAdoptsTheBusAsTheNatsModule(t *testing.T) {
catalogue := aCatalogue(t, map[string]string{BusModule: aBusModule(theModulesLayout)})
runtime, err := busStep(t, catalogue)
if err != nil {
@@ -108,7 +108,7 @@ func TestTheBrokerStepAdoptsTheBusAsTheNatsModule(t *testing.T) {
// A catalogue that holds no nats module fails the step by name, before anything is registered —
// which is what today's step did for lavinmq, silently adopting a module that no longer exists.
func TestTheBrokerStepFailsForAModuleTheCatalogueDoesNotHold(t *testing.T) {
func testTheBrokerStepFailsForAModuleTheCatalogueDoesNotHold(t *testing.T) {
catalogue := aCatalogue(t, map[string]string{"lavinmq": `{"module": "lavinmq", "version": "1"}`})
runtime, err := busStep(t, catalogue)
if err == nil {
@@ -126,7 +126,7 @@ func TestTheBrokerStepFailsForAModuleTheCatalogueDoesNotHold(t *testing.T) {
// beside the first, or an empty one on other paths (novox/hq ADR 0333 §1). It is refused naming every
// difference with both sides, before anything is registered. The layout is the one the bundle had
// before ADR 0333, kept as a module's here: the refusal genesis stopped at, at step 18 (issue 590).
func TestABusModuleWhoseLayoutIsNotTheFoundationsIsRefused(t *testing.T) {
func testABusModuleWhoseLayoutIsNotTheFoundationsIsRefused(t *testing.T) {
before := busLayout{Container: "mesh-broker", Streams: "mesh-broker-data", Conf: "/var/lib/mesh-bus-conf",
Certificate: "mesh-broker-tls", Users: "/var/lib/mesh-bus-conf/accounts.conf"}
catalogue := aCatalogue(t, map[string]string{BusModule: aBusModule(before)})
@@ -150,7 +150,7 @@ func TestABusModuleWhoseLayoutIsNotTheFoundationsIsRefused(t *testing.T) {
// One field moved is refused as surely as all of them: a module whose streams are elsewhere would be
// raised empty on the bus's own name.
func TestABusModuleWithItsStreamsElsewhereIsRefused(t *testing.T) {
func testABusModuleWithItsStreamsElsewhereIsRefused(t *testing.T) {
moved := theModulesLayout
moved.Streams = "/srv/nats"
catalogue := aCatalogue(t, map[string]string{BusModule: aBusModule(moved)})
@@ -169,7 +169,7 @@ func TestABusModuleWithItsStreamsElsewhereIsRefused(t *testing.T) {
// The node's bus port is kept (novox/hq ADR 0333 §2): the module declares 4222, and the broker step
// gives it the setting that maps that to the port the bundle published, 5671 unless given — before the
// push, so the first declaration already names it.
func TestTheBrokerStepGivesTheModuleTheNodesBusPort(t *testing.T) {
func testTheBrokerStepGivesTheModuleTheNodesBusPort(t *testing.T) {
for _, c := range []struct {
given int
want string
@@ -203,7 +203,7 @@ func TestTheBrokerStepGivesTheModuleTheNodesBusPort(t *testing.T) {
// The one restart is said before it happens, and the step goes on only once the bus runs the module's
// image and answers (novox/hq ADR 0333 §3).
func TestTheBrokerStepSaysTheRestartAndWaitsForTheBusToAnswer(t *testing.T) {
func testTheBrokerStepSaysTheRestartAndWaitsForTheBusToAnswer(t *testing.T) {
previous := answerEvery
answerEvery = time.Millisecond
defer func() { answerEvery = previous }()
@@ -266,7 +266,7 @@ func TestTheBrokerStepSaysTheRestartAndWaitsForTheBusToAnswer(t *testing.T) {
// A bus still on the bundle's image when the wait runs out is refused, naming the image: every step after
// this one reaches the mesh through that bus, and the push was not applied.
func TestABusTheNodeDidNotRecreateIsRefused(t *testing.T) {
func testABusTheNodeDidNotRecreateIsRefused(t *testing.T) {
previous := answerEvery
answerEvery = time.Millisecond
defer func() { answerEvery = previous }()
@@ -295,7 +295,7 @@ func TestABusTheNodeDidNotRecreateIsRefused(t *testing.T) {
// A re-run after the adoption finds the bus on the module's image already, and says so rather than
// announcing a restart that does not happen.
func TestARerunAfterTheAdoptionSaysTheBusIsTheModulesAlready(t *testing.T) {
func testARerunAfterTheAdoptionSaysTheBusIsTheModulesAlready(t *testing.T) {
catalogue := aCatalogue(t, map[string]string{BusModule: aBusModule(theModulesLayout)})
runtime, fetch := aBusThatAdopts()
o := installing(t, catalogue)
@@ -341,7 +341,7 @@ func theCataloguesBusModule(t *testing.T) []byte {
// manifest: the bus's container, its streams, its configuration, its certificate and its user list are
// where the module keeps them, so adopting the bus keeps it. Before ADR 0333 the bundle raised
// `mesh-broker` on volumes the module never mounts, and genesis stopped at step 18 (issue 590).
func TestTheBundleRaisesTheBusWhereTheCataloguesModuleKeepsIt(t *testing.T) {
func testTheBundleRaisesTheBusWhereTheCataloguesModuleKeepsIt(t *testing.T) {
manifest := theCataloguesBusModule(t)
rewritten, err := Rewrite(theRealBundle(t), held)
if err != nil {
@@ -377,7 +377,7 @@ func TestTheBundleRaisesTheBusWhereTheCataloguesModuleKeepsIt(t *testing.T) {
// The bundle as the installer reads it agrees with the module's layout as this repository states it,
// and with where the installer's bridge writes (ADR 0333 §4): the bridge places the users in the file the
// bus reads, and makes the container that reads it re-read it.
func TestTheBridgeWritesWhereTheBundleRaisesTheBus(t *testing.T) {
func testTheBridgeWritesWhereTheBundleRaisesTheBus(t *testing.T) {
rewritten, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -401,7 +401,7 @@ func TestTheBridgeWritesWhereTheBundleRaisesTheBus(t *testing.T) {
// The bundle's bus configuration and user list are seeds (create-once): an installer run again after
// the adoption applies the bundle again, and must not put the bundle's one user back over the users the
// module writes there (ADR 0333 §4).
func TestTheBundlesBusFilesAreSeeds(t *testing.T) {
func testTheBundlesBusFilesAreSeeds(t *testing.T) {
rewritten, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -445,3 +445,18 @@ func aGenesisBusOnDisk(t *testing.T) {
// aCertificatePEM is a PEM block standing for the bus's certificate; its pin is the sha256 of these bytes.
const aCertificatePEM = "-----BEGIN CERTIFICATE-----\nAAECAwQFBgcICQ==\n-----END CERTIFICATE-----\n"
// TestPhase3 runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestPhase3(t *testing.T) {
t.Run("TheBrokerStepAdoptsTheBusAsTheNatsModule", testTheBrokerStepAdoptsTheBusAsTheNatsModule)
t.Run("TheBrokerStepFailsForAModuleTheCatalogueDoesNotHold", testTheBrokerStepFailsForAModuleTheCatalogueDoesNotHold)
t.Run("ABusModuleWhoseLayoutIsNotTheFoundationsIsRefused", testABusModuleWhoseLayoutIsNotTheFoundationsIsRefused)
t.Run("ABusModuleWithItsStreamsElsewhereIsRefused", testABusModuleWithItsStreamsElsewhereIsRefused)
t.Run("TheBrokerStepGivesTheModuleTheNodesBusPort", testTheBrokerStepGivesTheModuleTheNodesBusPort)
t.Run("TheBrokerStepSaysTheRestartAndWaitsForTheBusToAnswer", testTheBrokerStepSaysTheRestartAndWaitsForTheBusToAnswer)
t.Run("ABusTheNodeDidNotRecreateIsRefused", testABusTheNodeDidNotRecreateIsRefused)
t.Run("ARerunAfterTheAdoptionSaysTheBusIsTheModulesAlready", testARerunAfterTheAdoptionSaysTheBusIsTheModulesAlready)
t.Run("TheBundleRaisesTheBusWhereTheCataloguesModuleKeepsIt", testTheBundleRaisesTheBusWhereTheCataloguesModuleKeepsIt)
t.Run("TheBridgeWritesWhereTheBundleRaisesTheBus", testTheBridgeWritesWhereTheBundleRaisesTheBus)
t.Run("TheBundlesBusFilesAreSeeds", testTheBundlesBusFilesAreSeeds)
}
+28 -12
View File
@@ -46,7 +46,7 @@ func containerNamed(d *declaration.Declaration, name string) *declaration.Contai
return nil
}
func TestTheDefaultPortsLeaveTheBundleAsItWas(t *testing.T) {
func testTheDefaultPortsLeaveTheBundleAsItWas(t *testing.T) {
r := producedBundle(t)
before := string(r.Bundle)
got, err := RewritePorts(&r, DefaultPorts(), DefaultOverlayRange)
@@ -58,7 +58,7 @@ func TestTheDefaultPortsLeaveTheBundleAsItWas(t *testing.T) {
}
}
func TestGivenPortsMoveOnlyTheMachinesSide(t *testing.T) {
func testGivenPortsMoveOnlyTheMachinesSide(t *testing.T) {
r := producedBundle(t)
p := FoundationPorts{Store: 5433, Bus: 5771, Registry: 5100}
got, err := RewritePorts(&r, p, "10.77.0.0/16")
@@ -110,7 +110,7 @@ func TestGivenPortsMoveOnlyTheMachinesSide(t *testing.T) {
}
}
func TestATemplateThatDoesNotSayItsPortsAsExpectedIsRefused(t *testing.T) {
func testATemplateThatDoesNotSayItsPortsAsExpectedIsRefused(t *testing.T) {
r := producedBundle(t)
r.Bundle = []byte(strings.Replace(string(r.Bundle), `"ports": ["5432:5432"]`, `"ports": [ "5432:5432" ]`, 1))
if _, err := RewritePorts(&r, FoundationPorts{Store: 5433}, ""); err == nil {
@@ -118,7 +118,7 @@ func TestATemplateThatDoesNotSayItsPortsAsExpectedIsRefused(t *testing.T) {
}
}
func TestTwoThingsOnOnePortAreRefused(t *testing.T) {
func testTwoThingsOnOnePortAreRefused(t *testing.T) {
p := DefaultPorts()
p.Registry = p.Store
if err := p.Check(); err == nil {
@@ -165,7 +165,7 @@ func (m machineRunner) run(_ context.Context, name string, args ...string) (stri
func noneOurs(reachable.Reach) bool { return false }
func TestABusyPortIsRefusedNamingItsHolder(t *testing.T) {
func testABusyPortIsRefusedNamingItsHolder(t *testing.T) {
m := machineRunner{
ss: "tcp LISTEN 0 4096 0.0.0.0:5000 0.0.0.0:* users:((\"docker-proxy\",pid=1,fd=7))\n" +
"tcp LISTEN 0 4096 0.0.0.0:5671 0.0.0.0:* users:((\"beam.smp\",pid=2,fd=7))\n",
@@ -187,7 +187,7 @@ func TestABusyPortIsRefusedNamingItsHolder(t *testing.T) {
}
}
func TestTheFoundationsOwnContainersAreNotCountedOnARerun(t *testing.T) {
func testTheFoundationsOwnContainersAreNotCountedOnARerun(t *testing.T) {
m := machineRunner{
ss: "tcp LISTEN 0 4096 0.0.0.0:5432 0.0.0.0:* users:((\"docker-proxy\",pid=1,fd=7))\n",
ps: "mesh-store\t0.0.0.0:5432->5432/tcp\n",
@@ -198,7 +198,7 @@ func TestTheFoundationsOwnContainersAreNotCountedOnARerun(t *testing.T) {
}
}
func TestAnOverlappingTunnelIsRefusedNamingItsInterface(t *testing.T) {
func testAnOverlappingTunnelIsRefusedNamingItsInterface(t *testing.T) {
m := machineRunner{
addrs: "1: lo inet 127.0.0.1/8 scope host lo\n5: wg0 inet 10.42.3.1/24 scope global wg0\n7: mesh0 inet 10.42.0.1/16 scope global mesh0\n",
routes: "default via 192.0.2.1 dev eth0\n10.42.3.0/24 dev wg0 proto kernel scope link src 10.42.3.1\n",
@@ -212,7 +212,7 @@ func TestAnOverlappingTunnelIsRefusedNamingItsInterface(t *testing.T) {
}
}
func TestAPredecessorsContainerUnderTheMeshsNameIsRefused(t *testing.T) {
func testAPredecessorsContainerUnderTheMeshsNameIsRefused(t *testing.T) {
m := machineRunner{unlabelled: map[string]bool{"mesh-registry": true}, labelled: map[string]bool{"mesh-store": true}}
err := NamesFree(context.Background(), m.run, []string{"mesh-store", "mesh-registry", "mesh-broker"}, store.State{})
if err == nil || !strings.Contains(err.Error(), "mesh-registry") || strings.Contains(err.Error(), "mesh-store") {
@@ -258,7 +258,7 @@ func (c *controlRecorder) index(prefix string) int {
return -1
}
func TestTheNodesPortsAreSetBeforeTheModuleIsPushed(t *testing.T) {
func testTheNodesPortsAreSetBeforeTheModuleIsPushed(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
c := &controlRecorder{settings: map[string]string{}}
control := controlPlane{container: "temp-mesh-controller", run: c.run, timeout: time.Second}
@@ -281,7 +281,7 @@ func TestTheNodesPortsAreSetBeforeTheModuleIsPushed(t *testing.T) {
}
}
func TestAGenesisOnTheDefaultsSetsNoSettings(t *testing.T) {
func testAGenesisOnTheDefaultsSetsNoSettings(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
c := &controlRecorder{settings: map[string]string{}}
control := controlPlane{container: "temp-mesh-controller", run: c.run, timeout: time.Second}
@@ -294,7 +294,7 @@ func TestAGenesisOnTheDefaultsSetsNoSettings(t *testing.T) {
}
}
func TestARerunOfGenesisFindsItsOwnPackageRegistry(t *testing.T) {
func testARerunOfGenesisFindsItsOwnPackageRegistry(t *testing.T) {
// Raised by genesis itself with no label and no record, so a re-run finds it unlabelled.
m := machineRunner{unlabelled: map[string]bool{giteaBootstrap: true}}
rerun := store.State{Resources: []store.Applied{{ID: "store", Type: "container", Target: "mesh-store"}}}
@@ -309,7 +309,7 @@ func TestARerunOfGenesisFindsItsOwnPackageRegistry(t *testing.T) {
// novox/hq ADR 0105: an adopted genesis takes over the tunnel it finds — its port is the hub's,
// its range the mesh's, and neither is refused for being held by it.
func TestAnAdoptedGenesisSettlesOnTheTunnelItFinds(t *testing.T) {
func testAnAdoptedGenesisSettlesOnTheTunnelItFinds(t *testing.T) {
private, err := aFoundKey()
if err != nil {
t.Fatal(err)
@@ -379,3 +379,19 @@ func aFoundKey() (string, error) {
}
return base64.StdEncoding.EncodeToString(k.Bytes()), nil
}
// TestPorts runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestPorts(t *testing.T) {
t.Run("TheDefaultPortsLeaveTheBundleAsItWas", testTheDefaultPortsLeaveTheBundleAsItWas)
t.Run("GivenPortsMoveOnlyTheMachinesSide", testGivenPortsMoveOnlyTheMachinesSide)
t.Run("ATemplateThatDoesNotSayItsPortsAsExpectedIsRefused", testATemplateThatDoesNotSayItsPortsAsExpectedIsRefused)
t.Run("TwoThingsOnOnePortAreRefused", testTwoThingsOnOnePortAreRefused)
t.Run("ABusyPortIsRefusedNamingItsHolder", testABusyPortIsRefusedNamingItsHolder)
t.Run("TheFoundationsOwnContainersAreNotCountedOnARerun", testTheFoundationsOwnContainersAreNotCountedOnARerun)
t.Run("AnOverlappingTunnelIsRefusedNamingItsInterface", testAnOverlappingTunnelIsRefusedNamingItsInterface)
t.Run("APredecessorsContainerUnderTheMeshsNameIsRefused", testAPredecessorsContainerUnderTheMeshsNameIsRefused)
t.Run("TheNodesPortsAreSetBeforeTheModuleIsPushed", testTheNodesPortsAreSetBeforeTheModuleIsPushed)
t.Run("AGenesisOnTheDefaultsSetsNoSettings", testAGenesisOnTheDefaultsSetsNoSettings)
t.Run("ARerunOfGenesisFindsItsOwnPackageRegistry", testARerunOfGenesisFindsItsOwnPackageRegistry)
t.Run("AnAdoptedGenesisSettlesOnTheTunnelItFinds", testAnAdoptedGenesisSettlesOnTheTunnelItFinds)
}
+16 -6
View File
@@ -16,7 +16,7 @@ import (
// The refusal has to be plain, because the person reading it is standing in front of a machine
// that will not work: it says what was asked, what came back, that re-running is safe, and names
// the record that explains why an installed docker is not enough.
func TestPreflightRefusesPlainlyWhenTheRuntimeDoesNotAnswer(t *testing.T) {
func testPreflightRefusesPlainlyWhenTheRuntimeDoesNotAnswer(t *testing.T) {
silent := func(context.Context, string, ...string) (string, error) {
return "", errors.New("Cannot connect to the Docker daemon at unix:///var/run/docker.sock")
}
@@ -44,7 +44,7 @@ func TestPreflightRefusesPlainlyWhenTheRuntimeDoesNotAnswer(t *testing.T) {
// Refusing on the first attempt would make a correct bootstrap fail for being observed too early —
// and `docker load` against such a daemon blocks silently rather than failing, which is how one
// became a 35-minute silence (04-ISSUES/024).
func TestARuntimeThatIsStillStartingIsWaitedFor(t *testing.T) {
func testARuntimeThatIsStillStartingIsWaitedFor(t *testing.T) {
previous := runtimeAskEvery
runtimeAskEvery = time.Millisecond
defer func() { runtimeAskEvery = previous }()
@@ -76,7 +76,7 @@ func TestARuntimeThatIsStillStartingIsWaitedFor(t *testing.T) {
// The mesh's own image is carried and nothing serves it, so asking a registry about it would be
// asking a question with no answer — which is the whole point of naming an image by the digest of
// its own configuration.
func TestOnlyTheRegistriesTheBundleNamesAreAskedAbout(t *testing.T) {
func testOnlyTheRegistriesTheBundleNamesAreAskedAbout(t *testing.T) {
parsed, err := declaration.ParseFileTrusted([]byte(`{"declaration":1,"resources":[
{"id":"store","type":"container","name":"mesh-store","image":"postgres@sha256:` +
strings.Repeat("7", 64) + `"},
@@ -107,7 +107,7 @@ func TestOnlyTheRegistriesTheBundleNamesAreAskedAbout(t *testing.T) {
// but preflight was reading that slot like any other and dialling it. The lab's template still
// carried the address of a registry the lab no longer raises, so a correct install timed out in
// preflight against a machine with a perfectly good network.
func TestTheControlPlanesOwnRegistryIsNeverAskedAbout(t *testing.T) {
func testTheControlPlanesOwnRegistryIsNeverAskedAbout(t *testing.T) {
parsed, err := declaration.ParseFileTrusted([]byte(`{"declaration":1,"resources":[
{"id":"store","type":"container","name":"mesh-store","image":"postgres@sha256:` +
strings.Repeat("7", 64) + `"},
@@ -125,7 +125,7 @@ func TestTheControlPlanesOwnRegistryIsNeverAskedAbout(t *testing.T) {
}
}
func TestWhereAnImageWouldBeFetchedFrom(t *testing.T) {
func testWhereAnImageWouldBeFetchedFrom(t *testing.T) {
// The container runtime's own rule: the part before the first slash is a registry host if it
// has a dot, a port, or is localhost. Getting this wrong means dialling a hostname that is
// really the first half of a repository name, and refusing a machine that is fine.
@@ -153,7 +153,7 @@ func TestWhereAnImageWouldBeFetchedFrom(t *testing.T) {
// A template whose temporary control plane is given no bus is refused at preflight, before anything
// is changed, rather than raised and waited on at the verify step until its timeout (novox/hq issue
// 146, ADR 0331 §4): that control plane says it has no MESH_BUS_NATS every few seconds, for ever.
func TestATemplateWhoseControlPlaneHasNoBusIsRefusedBeforeAnythingIsRaised(t *testing.T) {
func testATemplateWhoseControlPlaneHasNoBusIsRefusedBeforeAnythingIsRaised(t *testing.T) {
template := string(theRealBundle(t))
if _, err := CheckTemplate([]byte(template)); err != nil {
t.Fatalf("the shipped bundle is refused at preflight: %v", err)
@@ -167,3 +167,13 @@ func TestATemplateWhoseControlPlaneHasNoBusIsRefusedBeforeAnythingIsRaised(t *te
t.Fatalf("a control plane with no bus was let through preflight: %v", err)
}
}
// TestPreflight runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestPreflight(t *testing.T) {
t.Run("PreflightRefusesPlainlyWhenTheRuntimeDoesNotAnswer", testPreflightRefusesPlainlyWhenTheRuntimeDoesNotAnswer)
t.Run("ARuntimeThatIsStillStartingIsWaitedFor", testARuntimeThatIsStillStartingIsWaitedFor)
t.Run("OnlyTheRegistriesTheBundleNamesAreAskedAbout", testOnlyTheRegistriesTheBundleNamesAreAskedAbout)
t.Run("TheControlPlanesOwnRegistryIsNeverAskedAbout", testTheControlPlanesOwnRegistryIsNeverAskedAbout)
t.Run("WhereAnImageWouldBeFetchedFrom", testWhereAnImageWouldBeFetchedFrom)
t.Run("ATemplateWhoseControlPlaneHasNoBusIsRefusedBeforeAnythingIsRaised", testATemplateWhoseControlPlaneHasNoBusIsRefusedBeforeAnythingIsRaised)
}
+16 -6
View File
@@ -36,7 +36,7 @@ func publishing(t *testing.T, fetch func(string) (int, string, error),
// Nothing has ever been pushed under this name, so the registry says 404 — and that is an answer,
// not a failure. An installer that treated it as one would refuse on the first run of the step it
// exists to perform.
func TestAnImageNoRegistryHasEverHeldIsPushed(t *testing.T) {
func testAnImageNoRegistryHasEverHeldIsPushed(t *testing.T) {
pushed := false
o, d, runtime := publishing(t,
func(string) (int, string, error) {
@@ -76,7 +76,7 @@ func TestAnImageNoRegistryHasEverHeldIsPushed(t *testing.T) {
// An image the registry already serves is not pushed again, and says so. Blobs are named by their
// content, so re-pushing is asking a registry to store what it already has under the name it
// already has — and the installer is run over and over.
func TestAnImageTheRegistryAlreadyServesIsNotPushedAgain(t *testing.T) {
func testAnImageTheRegistryAlreadyServesIsNotPushedAgain(t *testing.T) {
o, d, runtime := publishing(t,
func(string) (int, string, error) {
return http.StatusOK, `{"name":"mesh-controller","tags":["genesis"]}`, nil
@@ -104,7 +104,7 @@ func TestAnImageTheRegistryAlreadyServesIsNotPushedAgain(t *testing.T) {
// to more than one registry has more than one entry, and element zero is whichever the runtime
// listed first — which would pin this mesh's control plane to somebody else's registry, silently,
// which is the dependency the whole pivot exists to remove.
func TestTheDigestComesFromThisMeshsOwnRegistry(t *testing.T) {
func testTheDigestComesFromThisMeshsOwnRegistry(t *testing.T) {
elsewhere := "some.other.registry/mesh-controller@sha256:" + strings.Repeat("c", 64)
ours := "127.0.0.1:5000/mesh-controller@sha256:" + strings.Repeat("d", 64)
@@ -133,7 +133,7 @@ func TestTheDigestComesFromThisMeshsOwnRegistry(t *testing.T) {
// depends on it. The next step names the control plane's module by that digest, so there would be
// nothing to name — and finding that out one step later would mean registering a module pinned to
// an empty string.
func TestAPushThatProducedNoDigestIsRefused(t *testing.T) {
func testAPushThatProducedNoDigestIsRefused(t *testing.T) {
pushed := false
o, d, _ := publishing(t,
func(string) (int, string, error) {
@@ -162,7 +162,7 @@ func TestAPushThatProducedNoDigestIsRefused(t *testing.T) {
// A tag is not a pin. If the runtime answers with something that is not pinned by digest, it is
// not used — a tag can be made to point at a different image, and this reference is applied on
// machines with no mesh to ask about anything (novox/hq ADR 0006).
func TestATagIsNotAPin(t *testing.T) {
func testATagIsNotAPin(t *testing.T) {
o, d, _ := publishing(t,
func(string) (int, string, error) {
return http.StatusOK, `{"tags":["genesis"]}`, nil
@@ -182,7 +182,7 @@ func TestATagIsNotAPin(t *testing.T) {
// A registry that cannot be reached at all is said so plainly rather than becoming a push that
// fails for a reason nobody can read.
func TestARegistryThatCannotBeAskedIsSaidSo(t *testing.T) {
func testARegistryThatCannotBeAskedIsSaidSo(t *testing.T) {
o, d, _ := publishing(t,
func(string) (int, string, error) {
return 0, "", errors.New("connection refused")
@@ -197,3 +197,13 @@ func TestARegistryThatCannotBeAskedIsSaidSo(t *testing.T) {
t.Errorf("the refusal does not say the registry could not be asked: %v", err)
}
}
// TestPublish runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestPublish(t *testing.T) {
t.Run("AnImageNoRegistryHasEverHeldIsPushed", testAnImageNoRegistryHasEverHeldIsPushed)
t.Run("AnImageTheRegistryAlreadyServesIsNotPushedAgain", testAnImageTheRegistryAlreadyServesIsNotPushedAgain)
t.Run("TheDigestComesFromThisMeshsOwnRegistry", testTheDigestComesFromThisMeshsOwnRegistry)
t.Run("APushThatProducedNoDigestIsRefused", testAPushThatProducedNoDigestIsRefused)
t.Run("ATagIsNotAPin", testATagIsNotAPin)
t.Run("ARegistryThatCannotBeAskedIsSaidSo", testARegistryThatCannotBeAskedIsSaidSo)
}
+14 -5
View File
@@ -59,7 +59,7 @@ func placedAfterThePush(t *testing.T, commands []string) int {
return placed
}
func TestTheBusHearsTheBuildAgentsAccountAfterItsPush(t *testing.T) {
func testTheBusHearsTheBuildAgentsAccountAfterItsPush(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
runtime, control := placing(false)
o := Options{Node: "anchor", Wait: time.Second}
@@ -71,7 +71,7 @@ func TestTheBusHearsTheBuildAgentsAccountAfterItsPush(t *testing.T) {
}
}
func TestTheGenesisDocumentsPushIsHeardByTheBusToo(t *testing.T) {
func testTheGenesisDocumentsPushIsHeardByTheBusToo(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
runtime, control := placing(false)
o := Options{Node: "anchor", Wait: time.Second}
@@ -84,7 +84,7 @@ func TestTheGenesisDocumentsPushIsHeardByTheBusToo(t *testing.T) {
}
// From the adoption on the nats module writes the list, and the installer does not (ADR 0333 §4).
func TestOnceTheBusIsTheNatsModulesThePushPlacesNothing(t *testing.T) {
func testOnceTheBusIsTheNatsModulesThePushPlacesNothing(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
runtime, control := placing(true)
o := Options{Node: "anchor", Wait: time.Second}
@@ -99,7 +99,7 @@ func TestOnceTheBusIsTheNatsModulesThePushPlacesNothing(t *testing.T) {
// Defends novox/hq issue 615: the packages step's push is waited for until the node applied it, because
// the sdk step right after asks the build agent for a build that reads the genesis document from the
// file that apply writes. A push that returned on sending let the ask race the apply.
func TestThePackagesStepWaitsUntilTheNodeAppliedTheGenesisDocument(t *testing.T) {
func testThePackagesStepWaitsUntilTheNodeAppliedTheGenesisDocument(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
runtime, control := placing(false)
o := Options{Node: "anchor", Wait: 3 * time.Minute}
@@ -119,7 +119,7 @@ func TestThePackagesStepWaitsUntilTheNodeAppliedTheGenesisDocument(t *testing.T)
// Every other push of genesis still returns on sending: only a push whose content the next step reads on
// the machine waits.
func TestAnOrdinaryPushDoesNotWait(t *testing.T) {
func testAnOrdinaryPushDoesNotWait(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
runtime, control := placing(false)
o := Options{Node: "anchor", Wait: time.Second}
@@ -132,3 +132,12 @@ func TestAnOrdinaryPushDoesNotWait(t *testing.T) {
}
}
}
// TestPushPlacesUsers runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestPushPlacesUsers(t *testing.T) {
t.Run("TheBusHearsTheBuildAgentsAccountAfterItsPush", testTheBusHearsTheBuildAgentsAccountAfterItsPush)
t.Run("TheGenesisDocumentsPushIsHeardByTheBusToo", testTheGenesisDocumentsPushIsHeardByTheBusToo)
t.Run("OnceTheBusIsTheNatsModulesThePushPlacesNothing", testOnceTheBusIsTheNatsModulesThePushPlacesNothing)
t.Run("ThePackagesStepWaitsUntilTheNodeAppliedTheGenesisDocument", testThePackagesStepWaitsUntilTheNodeAppliedTheGenesisDocument)
t.Run("AnOrdinaryPushDoesNotWait", testAnOrdinaryPushDoesNotWait)
}
+14 -5
View File
@@ -97,7 +97,7 @@ func installing(t *testing.T, catalogue string) Options {
// A container that is up is not a registry that serves. `/v2/` is the registry API's own "yes, I
// am one and I am ready", and the step after this pushes to it — so it is refused here rather than
// discovered inside a `docker push`.
func TestARegistryContainerThatIsUpIsNotARegistryThatServes(t *testing.T) {
func testARegistryContainerThatIsUpIsNotARegistryThatServes(t *testing.T) {
previous := answerEvery
answerEvery = time.Millisecond
defer func() { answerEvery = previous }()
@@ -125,7 +125,7 @@ func TestARegistryContainerThatIsUpIsNotARegistryThatServes(t *testing.T) {
}
// The whole of step 7, against a mesh that agrees: registered, assigned, pushed, up, and answering.
func TestARegistryThatAnswersIsAccepted(t *testing.T) {
func testARegistryThatAnswersIsAccepted(t *testing.T) {
runtime := &asked{answer: aMeshThatAgrees(nil)}
deps := Deps{
Run: runtime.run,
@@ -163,7 +163,7 @@ func TestARegistryThatAnswersIsAccepted(t *testing.T) {
// placeholder digest would mean somebody had made this module buildable — which is the cycle
// novox/hq 04-ISSUES/029 settled: a module that provides the artifact store cannot be delivered
// through the artifact store.
func TestARegistryManifestThatWantsBuildingIsRefused(t *testing.T) {
func testARegistryManifestThatWantsBuildingIsRefused(t *testing.T) {
wants := strings.Replace(upstreamRegistryManifest,
"registry@sha256:a3d8aaa63ed8681a604f1dea0aa03f100d5895b6a58ace528858a7b332415373",
"mesh-runtime-registry@"+placeholderDigest, 1)
@@ -186,7 +186,7 @@ func TestARegistryManifestThatWantsBuildingIsRefused(t *testing.T) {
// A catalogue that is not there is said plainly, with what --catalog is. This is the most likely
// mistake anybody makes at this step and the least interesting to debug.
func TestACatalogueThatIsNotThereIsSaidPlainly(t *testing.T) {
func testACatalogueThatIsNotThereIsSaidPlainly(t *testing.T) {
runtime := &asked{answer: aMeshThatAgrees(nil)}
_, err := InstallRegistry(context.Background(),
installing(t, filepath.Join(t.TempDir(), "nowhere")),
@@ -203,7 +203,7 @@ func TestACatalogueThatIsNotThereIsSaidPlainly(t *testing.T) {
// A refusal from the control plane is repeated verbatim. mesh-controller refuses in paragraphs —
// "nothing provides route, wanted by registry" — and an installer that reported "exit status 1"
// would throw away the only thing a person can act on.
func TestWhatTheMeshRefusedIsRepeated(t *testing.T) {
func testWhatTheMeshRefusedIsRepeated(t *testing.T) {
refusal := "nothing provides \"route\", wanted by registry"
runtime := &asked{answer: func(name string, args []string) (string, error) {
if strings.Contains(strings.Join(args, " "), "push") {
@@ -226,3 +226,12 @@ func TestWhatTheMeshRefusedIsRepeated(t *testing.T) {
t.Errorf("the failure does not say a re-run continues from here:\n%v", err)
}
}
// TestRegistry runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestRegistry(t *testing.T) {
t.Run("ARegistryContainerThatIsUpIsNotARegistryThatServes", testARegistryContainerThatIsUpIsNotARegistryThatServes)
t.Run("ARegistryThatAnswersIsAccepted", testARegistryThatAnswersIsAccepted)
t.Run("ARegistryManifestThatWantsBuildingIsRefused", testARegistryManifestThatWantsBuildingIsRefused)
t.Run("ACatalogueThatIsNotThereIsSaidPlainly", testACatalogueThatIsNotThereIsSaidPlainly)
t.Run("WhatTheMeshRefusedIsRepeated", testWhatTheMeshRefusedIsRepeated)
}
+16 -6
View File
@@ -25,7 +25,7 @@ func produced(t *testing.T) []byte {
}
// The temporary control plane leaves the bundle, everything else stays, and what is left parses.
func TestTheTemporaryControlPlaneLeavesTheBundleAndNothingElseDoes(t *testing.T) {
func testTheTemporaryControlPlaneLeavesTheBundleAndNothingElseDoes(t *testing.T) {
before, err := declaration.ParseFileTrusted(produced(t))
if err != nil {
t.Fatal(err)
@@ -61,7 +61,7 @@ func TestTheTemporaryControlPlaneLeavesTheBundleAndNothingElseDoes(t *testing.T)
// `postgres://…` several times, and a scanner that read the rest of those lines as a comment
// would lose braces and cut the wrong thing out — silently, because what it produced would still
// look like a file.
func TestASchemeInsideAStringIsNotReadAsAComment(t *testing.T) {
func testASchemeInsideAStringIsNotReadAsAComment(t *testing.T) {
shorter, err := removeResource(produced(t), ControlPlaneID)
if err != nil {
t.Fatal(err)
@@ -86,7 +86,7 @@ func TestASchemeInsideAStringIsNotReadAsAComment(t *testing.T) {
// Removing the FIRST element takes the comma after it rather than the comma before it, because
// there is no comma before it. Getting this wrong produces a leading comma, which is JSON nothing
// parses — and the file would already have been written.
func TestRemovingTheFirstResourceLeavesAValidList(t *testing.T) {
func testRemovingTheFirstResourceLeavesAValidList(t *testing.T) {
shorter, err := removeResource(produced(t), "container-runtime")
if err != nil {
t.Fatal(err)
@@ -105,7 +105,7 @@ func TestRemovingTheFirstResourceLeavesAValidList(t *testing.T) {
// A bundle that declares no such resource is refused rather than silently returned unchanged. A
// removal that removed nothing and reported success would leave the apply below with nothing to
// do and the installer claiming a pivot it did not finish.
func TestRemovingSomethingThatIsNotThereIsRefused(t *testing.T) {
func testRemovingSomethingThatIsNotThereIsRefused(t *testing.T) {
if _, err := removeResource(produced(t), "nothing-of-the-sort"); err == nil {
t.Fatal("a bundle was reported to have had a resource removed that it never declared")
}
@@ -114,7 +114,7 @@ func TestRemovingSomethingThatIsNotThereIsRefused(t *testing.T) {
// A re-run after the retirement finds a bundle with no control plane in it and says so, rather
// than failing. This is the idempotence of the last step, and it is the one a person is most
// likely to exercise: the pivot ends here, so a re-run to check ends here too.
func TestRetiringABundleThatAlreadyHasNoControlPlaneIsAlreadyDone(t *testing.T) {
func testRetiringABundleThatAlreadyHasNoControlPlaneIsAlreadyDone(t *testing.T) {
shorter, err := removeResource(produced(t), ControlPlaneID)
if err != nil {
t.Fatal(err)
@@ -136,7 +136,7 @@ func TestRetiringABundleThatAlreadyHasNoControlPlaneIsAlreadyDone(t *testing.T)
// A container the runtime still knows about after the apply is a pivot that did not finish. Two
// control planes on one mesh are both correct and neither is wrong — but the temporary one was
// supposed to go, and saying it went when it did not is the fault this project keeps naming.
func TestAContainerStillThereAfterRemovalIsNotGone(t *testing.T) {
func testAContainerStillThereAfterRemovalIsNotGone(t *testing.T) {
previous := answerEvery
answerEvery = time.Millisecond
defer func() { answerEvery = previous }()
@@ -163,3 +163,13 @@ func TestAContainerStillThereAfterRemovalIsNotGone(t *testing.T) {
t.Error("a container the runtime does not know about was not reported gone")
}
}
// TestRetire runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestRetire(t *testing.T) {
t.Run("TheTemporaryControlPlaneLeavesTheBundleAndNothingElseDoes", testTheTemporaryControlPlaneLeavesTheBundleAndNothingElseDoes)
t.Run("ASchemeInsideAStringIsNotReadAsAComment", testASchemeInsideAStringIsNotReadAsAComment)
t.Run("RemovingTheFirstResourceLeavesAValidList", testRemovingTheFirstResourceLeavesAValidList)
t.Run("RemovingSomethingThatIsNotThereIsRefused", testRemovingSomethingThatIsNotThereIsRefused)
t.Run("RetiringABundleThatAlreadyHasNoControlPlaneIsAlreadyDone", testRetiringABundleThatAlreadyHasNoControlPlaneIsAlreadyDone)
t.Run("AContainerStillThereAfterRemovalIsNotGone", testAContainerStillThereAfterRemovalIsNotGone)
}
+32 -14
View File
@@ -29,7 +29,7 @@ func theRealBundle(t *testing.T) []byte {
return raw
}
func TestTheControlPlaneIsNamedByTheImageThisMachineHolds(t *testing.T) {
func testTheControlPlaneIsNamedByTheImageThisMachineHolds(t *testing.T) {
out, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -52,7 +52,7 @@ func TestTheControlPlaneIsNamedByTheImageThisMachineHolds(t *testing.T) {
// action that runs `migrate` to create the contexts' schemas. Rewriting only the container leaves
// the migration pointing at an image no registry serves, and the apply dies in the middle — after
// the store is up and before the broker. This is the test that would have caught that.
func TestEveryPlaceTheBundleNamesTheControlPlaneIsRewritten(t *testing.T) {
func testEveryPlaceTheBundleNamesTheControlPlaneIsRewritten(t *testing.T) {
template := theRealBundle(t)
out, err := Rewrite(template, held)
@@ -74,7 +74,7 @@ func TestEveryPlaceTheBundleNamesTheControlPlaneIsRewritten(t *testing.T) {
// Third-party images are somebody else's, at somebody else's registry, and the installer has no
// business touching them (novox/hq ADR 0006).
func TestPostgresAndTheBrokerAreLeftExactlyAsTheyWere(t *testing.T) {
func testPostgresAndTheBrokerAreLeftExactlyAsTheyWere(t *testing.T) {
template := theRealBundle(t)
out, err := Rewrite(template, held)
@@ -107,7 +107,7 @@ func TestPostgresAndTheBrokerAreLeftExactlyAsTheyWere(t *testing.T) {
// A bundle with no control plane raises a store and a broker and no mesh. Refused, because
// applying it would succeed and leave a machine that looks bootstrapped.
func TestABundleThatNamesNoControlPlaneIsRefused(t *testing.T) {
func testABundleThatNamesNoControlPlaneIsRefused(t *testing.T) {
template := []byte(`{"declaration":1,"resources":[
{"id":"store","type":"container","name":"mesh-store","image":"postgres@sha256:` +
strings.Repeat("7", 64) + `"}
@@ -124,7 +124,7 @@ func TestABundleThatNamesNoControlPlaneIsRefused(t *testing.T) {
}
}
func TestAControlPlaneThatIsNotAContainerIsRefused(t *testing.T) {
func testAControlPlaneThatIsNotAContainerIsRefused(t *testing.T) {
template := []byte(`{"declaration":1,"resources":[
{"id":"control-plane","type":"package","package":"mesh-controller"}
]}`)
@@ -136,7 +136,7 @@ func TestAControlPlaneThatIsNotAContainerIsRefused(t *testing.T) {
// Idempotence. This program is run over and over while somebody gets a machine working, and the
// second run must be able to say the bundle already names this image rather than reporting a
// rewrite it did not perform.
func TestRewritingABundleThatAlreadyNamesTheImageChangesNothing(t *testing.T) {
func testRewritingABundleThatAlreadyNamesTheImageChangesNothing(t *testing.T) {
first, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -159,7 +159,7 @@ func TestRewritingABundleThatAlreadyNamesTheImageChangesNothing(t *testing.T) {
// A DIFFERENT image, though, must move — the ordinary case of a new control plane being installed
// over an old one. "Already correct" must not be the same code path as "already ran".
func TestANewImageReplacesAnOlderHeldOne(t *testing.T) {
func testANewImageReplacesAnOlderHeldOne(t *testing.T) {
first, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -177,7 +177,7 @@ func TestANewImageReplacesAnOlderHeldOne(t *testing.T) {
// The produced bundle is meant to be READ. Re-serialising a parsed declaration would drop every
// comment in the template, and the foundation example is mostly comments — each one recording why a
// resource is the way it is, several of them paid for in the lab.
func TestTheProducedBundleKeepsTheTemplatesComments(t *testing.T) {
func testTheProducedBundleKeepsTheTemplatesComments(t *testing.T) {
template := theRealBundle(t)
out, err := Rewrite(template, held)
if err != nil {
@@ -191,7 +191,7 @@ func TestTheProducedBundleKeepsTheTemplatesComments(t *testing.T) {
// The installer must refuse its own bad input in its own words, rather than writing a bundle and
// letting the host refuse a declaration somebody did not write.
func TestSomethingThatIsNotAnImageIdIsRefused(t *testing.T) {
func testSomethingThatIsNotAnImageIdIsRefused(t *testing.T) {
for _, bad := range []string{
"",
"mesh-controller:latest",
@@ -209,7 +209,7 @@ func TestSomethingThatIsNotAnImageIdIsRefused(t *testing.T) {
// The address every enrolment token will carry is reported and never invented. It differs per
// machine and it is silently fatal when wrong: a node enrols against a dead address and nothing
// says so until it fails to come back.
func TestTheAddressNodesWillDialIsReportedAndNotRewritten(t *testing.T) {
func testTheAddressNodesWillDialIsReportedAndNotRewritten(t *testing.T) {
template := theRealBundle(t)
out, err := Rewrite(template, held)
if err != nil {
@@ -233,7 +233,7 @@ func TestTheAddressNodesWillDialIsReportedAndNotRewritten(t *testing.T) {
// one container, and the host — which tracks what it owns — has no way to stop owning something
// without destroying it. Nothing here invents such a mechanism. The foundation's container is
// called `temp-mesh-controller` instead, and there are simply two containers.
func TestTheFoundationsControlPlaneMovesOutOfTheModulesWay(t *testing.T) {
func testTheFoundationsControlPlaneMovesOutOfTheModulesWay(t *testing.T) {
out, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -263,7 +263,7 @@ func TestTheFoundationsControlPlaneMovesOutOfTheModulesWay(t *testing.T) {
// The image reference contains the string `mesh-controller` too, and it is not a container name. A
// substitution that caught it would produce `…/temp-mesh-controller@sha256:…`, which no registry
// serves — and it would be found inside a pull rather than here.
func TestTheImageReferenceIsNotMistakenForTheContainerName(t *testing.T) {
func testTheImageReferenceIsNotMistakenForTheContainerName(t *testing.T) {
out, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -276,7 +276,7 @@ func TestTheImageReferenceIsNotMistakenForTheContainerName(t *testing.T) {
// Everything else keeps the name the foundation gave it. The store and the broker are containers
// too, and a rename that moved them would leave a machine whose foundation the host cannot find.
func TestRenamingTheControlPlaneLeavesEveryOtherContainerAlone(t *testing.T) {
func testRenamingTheControlPlaneLeavesEveryOtherContainerAlone(t *testing.T) {
before, err := declaration.ParseFileTrusted(theRealBundle(t))
if err != nil {
t.Fatal(err)
@@ -299,7 +299,7 @@ func TestRenamingTheControlPlaneLeavesEveryOtherContainerAlone(t *testing.T) {
// A re-run against a bundle this installer produced renames nothing and says so. The installer is
// run over and over while somebody gets a machine working, and a step that could not tell "already
// done" from "just done" makes the second run indistinguishable from the first.
func TestRewritingABundleThisAlreadyProducedRenamesNothing(t *testing.T) {
func testRewritingABundleThisAlreadyProducedRenamesNothing(t *testing.T) {
first, err := Rewrite(theRealBundle(t), held)
if err != nil {
t.Fatal(err)
@@ -319,3 +319,21 @@ func TestRewritingABundleThisAlreadyProducedRenamesNothing(t *testing.T) {
t.Error("rewriting a produced bundle changed it")
}
}
// TestRewrite runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestRewrite(t *testing.T) {
t.Run("TheControlPlaneIsNamedByTheImageThisMachineHolds", testTheControlPlaneIsNamedByTheImageThisMachineHolds)
t.Run("EveryPlaceTheBundleNamesTheControlPlaneIsRewritten", testEveryPlaceTheBundleNamesTheControlPlaneIsRewritten)
t.Run("PostgresAndTheBrokerAreLeftExactlyAsTheyWere", testPostgresAndTheBrokerAreLeftExactlyAsTheyWere)
t.Run("ABundleThatNamesNoControlPlaneIsRefused", testABundleThatNamesNoControlPlaneIsRefused)
t.Run("AControlPlaneThatIsNotAContainerIsRefused", testAControlPlaneThatIsNotAContainerIsRefused)
t.Run("RewritingABundleThatAlreadyNamesTheImageChangesNothing", testRewritingABundleThatAlreadyNamesTheImageChangesNothing)
t.Run("ANewImageReplacesAnOlderHeldOne", testANewImageReplacesAnOlderHeldOne)
t.Run("TheProducedBundleKeepsTheTemplatesComments", testTheProducedBundleKeepsTheTemplatesComments)
t.Run("SomethingThatIsNotAnImageIdIsRefused", testSomethingThatIsNotAnImageIdIsRefused)
t.Run("TheAddressNodesWillDialIsReportedAndNotRewritten", testTheAddressNodesWillDialIsReportedAndNotRewritten)
t.Run("TheFoundationsControlPlaneMovesOutOfTheModulesWay", testTheFoundationsControlPlaneMovesOutOfTheModulesWay)
t.Run("TheImageReferenceIsNotMistakenForTheContainerName", testTheImageReferenceIsNotMistakenForTheContainerName)
t.Run("RenamingTheControlPlaneLeavesEveryOtherContainerAlone", testRenamingTheControlPlaneLeavesEveryOtherContainerAlone)
t.Run("RewritingABundleThisAlreadyProducedRenamesNothing", testRewritingABundleThisAlreadyProducedRenamesNothing)
}
+18 -7
View File
@@ -38,7 +38,7 @@ func theExample(t *testing.T) Rewritten {
// file genesis made, and the controller's account on the bus is the made one in both places the
// bundle names it — the address the control plane dials and the user list the bus is raised with
// (novox/hq issue 071, ADR 0331 §3).
func TestTheProducedBundleCarriesNoWellKnownCredential(t *testing.T) {
func testTheProducedBundleCarriesNoWellKnownCredential(t *testing.T) {
r := theExample(t)
creds := testCredentials(t, "STORE-PW-40-characters-of-random-base64u", "BUS-PW-40-characters-of-random-base64uuu")
got, err := RewriteRoot(&r, creds)
@@ -109,7 +109,7 @@ func hashOf(t *testing.T, list, user string) string {
// The bus's placeholders are what the installer looks for, and a template naming no bus connection
// it knows is refused at preflight, naming the placeholder (novox/hq ADR 0331 §3, §4).
func TestABundleNamingNoBusConnectionItKnowsIsRefusedByItsPlaceholder(t *testing.T) {
func testABundleNamingNoBusConnectionItKnowsIsRefusedByItsPlaceholder(t *testing.T) {
template, err := os.ReadFile("../../examples/foundation-first-node.lock")
if err != nil {
t.Skip("no example bundle beside this checkout")
@@ -151,7 +151,7 @@ func TestABundleNamingNoBusConnectionItKnowsIsRefusedByItsPlaceholder(t *testing
// The account is made once, with its hash, and a second run puts the same bytes in the bundle — a
// hash salted afresh every run would rewrite the bus's user list every run.
func TestTheBusAccountIsKeptWithItsHash(t *testing.T) {
func testTheBusAccountIsKeptWithItsHash(t *testing.T) {
dir := t.TempDir()
first, err := rootSecretsAt(dir+"/store", dir+"/bus", dir+"/bus.bcrypt", false)
if err != nil {
@@ -171,7 +171,7 @@ func TestTheBusAccountIsKeptWithItsHash(t *testing.T) {
}
// Made once and kept: a second run reads the same value; a dry run writes nothing.
func TestRootSecretsAreKeptAcrossRuns(t *testing.T) {
func testRootSecretsAreKeptAcrossRuns(t *testing.T) {
dir := t.TempDir()
path := dir + "/superuser.secret"
first, made, err := keptOrMade(path, false)
@@ -195,7 +195,7 @@ func TestRootSecretsAreKeptAcrossRuns(t *testing.T) {
}
// Nothing the installer says after making the credentials contains them.
func TestTheTranscriptNeverSaysTheCredentials(t *testing.T) {
func testTheTranscriptNeverSaysTheCredentials(t *testing.T) {
var said []string
say := Masking(func(l string) { said = append(said, l) }, RootCredentials{Store: "STORE-PW", Bus: "BUS-PW"})
say("created context-schemas (docker run -e MESH_STORE_INVENTORY=postgres://postgres:STORE-PW@127.0.0.1:5432/inventory)")
@@ -213,7 +213,7 @@ func TestTheTranscriptNeverSaysTheCredentials(t *testing.T) {
// The foundation filters before anything listens: nftables is in place before the store, and its
// rules refuse the store's and broker's client ports from outside while keeping ssh, the bus a node
// enrols over and the registry a node pulls from (novox/hq issue 054).
func TestTheFoundationFiltersBeforeAnythingListens(t *testing.T) {
func testTheFoundationFiltersBeforeAnythingListens(t *testing.T) {
r := theExample(t)
if _, err := RewriteRoot(&r, testCredentials(t, "s", "b")); err != nil {
t.Fatal(err)
@@ -254,7 +254,7 @@ func TestTheFoundationFiltersBeforeAnythingListens(t *testing.T) {
// <data root>/mesh (/var/lib/mesh/postgres), no longer in /var/lib/postgres, the postgresql package's own. A
// directory genesis makes on the way keeps the mode the mesh's directories have (0755, so every module's account
// reaches its own below it); only the credential's own directory is closed, 0700.
func TestTheStoreSuperuserFileLiesInTheModulesOwnDirectory(t *testing.T) {
func testTheStoreSuperuserFileLiesInTheModulesOwnDirectory(t *testing.T) {
if StoreSuperuserFile != "/var/lib/mesh/postgres/superuser.secret" {
t.Errorf("the store's superuser file is %s, not the postgres module's /var/lib/mesh/postgres/superuser.secret", StoreSuperuserFile)
}
@@ -273,3 +273,14 @@ func TestTheStoreSuperuserFileLiesInTheModulesOwnDirectory(t *testing.T) {
}
}
}
// TestRootsecrets runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestRootsecrets(t *testing.T) {
t.Run("TheProducedBundleCarriesNoWellKnownCredential", testTheProducedBundleCarriesNoWellKnownCredential)
t.Run("ABundleNamingNoBusConnectionItKnowsIsRefusedByItsPlaceholder", testABundleNamingNoBusConnectionItKnowsIsRefusedByItsPlaceholder)
t.Run("TheBusAccountIsKeptWithItsHash", testTheBusAccountIsKeptWithItsHash)
t.Run("RootSecretsAreKeptAcrossRuns", testRootSecretsAreKeptAcrossRuns)
t.Run("TheTranscriptNeverSaysTheCredentials", testTheTranscriptNeverSaysTheCredentials)
t.Run("TheFoundationFiltersBeforeAnythingListens", testTheFoundationFiltersBeforeAnythingListens)
t.Run("TheStoreSuperuserFileLiesInTheModulesOwnDirectory", testTheStoreSuperuserFileLiesInTheModulesOwnDirectory)
}
+12 -4
View File
@@ -29,7 +29,7 @@ func theStoreGenesisRaises(t *testing.T) *declaration.Container {
// The bundle's store is exactly the catalogue's postgres module's server, read from the module's own
// manifest (ADR 0338 §1): its name, its image (so a drift of either pin fails here), where its data is,
// and the file its superuser password is read from, with the environment that says so.
func TestTheBundleRaisesTheStoreAsTheCataloguesPostgresModuleDeclaresIt(t *testing.T) {
func testTheBundleRaisesTheStoreAsTheCataloguesPostgresModuleDeclaresIt(t *testing.T) {
manifest := theCataloguesModule(t, "postgres")
var m struct {
Resources []struct {
@@ -90,7 +90,7 @@ func TestTheBundleRaisesTheStoreAsTheCataloguesPostgresModuleDeclaresIt(t *testi
// The store's data directory is made by the bundle before the store starts, owned by the image's
// postgres user, as the module declares it (ADR 0338 §1, and the measurement under its §5).
func TestTheBundleMakesTheStoresDataDirectoryAsTheModuleDoes(t *testing.T) {
func testTheBundleMakesTheStoresDataDirectoryAsTheModuleDoes(t *testing.T) {
r := producedBundle(t)
at, store := -1, -1
for i, res := range r.Declaration.Resources {
@@ -111,7 +111,7 @@ func TestTheBundleMakesTheStoresDataDirectoryAsTheModuleDoes(t *testing.T) {
// No step of the bundle and no step of the installer names `mesh-store`, which is the seat's name only
// (ADR 0338 §2): every step that reaches the store reaches the container the bundle raised.
func TestNoStepReachesTheStoreByTheSeatsName(t *testing.T) {
func testNoStepReachesTheStoreByTheSeatsName(t *testing.T) {
text := string(theRealBundle(t))
for _, by := range []string{`"in": "mesh-store"`, `container:mesh-store`, `exec mesh-store`, `"name": "mesh-store"`, `mesh-store-data`} {
if strings.Contains(text, by) {
@@ -132,7 +132,7 @@ func TestNoStepReachesTheStoreByTheSeatsName(t *testing.T) {
// The installer's refusal to raise a store over data it cannot open looks where the store keeps its data
// (ADR 0338 §2): a cluster there and no credential is refused; the old docker volume alone is not.
func TestTheRefusalOverExistingDataLooksInTheStoresDirectory(t *testing.T) {
func testTheRefusalOverExistingDataLooksInTheStoresDirectory(t *testing.T) {
made := RootCredentials{Store: "s", Bus: "b", StoreMade: true}
machine := func(cluster, volume bool) Runner {
return func(_ context.Context, name string, args ...string) (string, error) {
@@ -161,3 +161,11 @@ func TestTheRefusalOverExistingDataLooksInTheStoresDirectory(t *testing.T) {
t.Fatalf("a kept credential was refused: %v", err)
}
}
// TestStoreLayout runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestStoreLayout(t *testing.T) {
t.Run("TheBundleRaisesTheStoreAsTheCataloguesPostgresModuleDeclaresIt", testTheBundleRaisesTheStoreAsTheCataloguesPostgresModuleDeclaresIt)
t.Run("TheBundleMakesTheStoresDataDirectoryAsTheModuleDoes", testTheBundleMakesTheStoresDataDirectoryAsTheModuleDoes)
t.Run("NoStepReachesTheStoreByTheSeatsName", testNoStepReachesTheStoreByTheSeatsName)
t.Run("TheRefusalOverExistingDataLooksInTheStoresDirectory", testTheRefusalOverExistingDataLooksInTheStoresDirectory)
}
+18 -7
View File
@@ -109,7 +109,7 @@ func insecureIn(t *testing.T) (string, map[string]json.RawMessage) {
return fmt.Sprint(list), o
}
func TestGenesisTrustsTheRegistryByEveryNameBeforeItPushes(t *testing.T) {
func testGenesisTrustsTheRegistryByEveryNameBeforeItPushes(t *testing.T) {
o, runtime, sys := trustSetup(t, `{"data-root":"/srv/docker","insecure-registries":["198.51.100.7:5000"]}`)
names, err := TrustTheRegistry(context.Background(), o, sys, runtime.run, func(string) {})
@@ -143,7 +143,7 @@ func TestGenesisTrustsTheRegistryByEveryNameBeforeItPushes(t *testing.T) {
// The port is the node's setting for the registry, not the module's default, whatever the operator
// typed the address with — and loopback, which the runtime trusts already, is not written.
func TestTheRegistrysTrustNamesThePortTheNodeServesItOn(t *testing.T) {
func testTheRegistrysTrustNamesThePortTheNodeServesItOn(t *testing.T) {
o := Options{Node: "anchor", Registry: "127.0.0.1:5100", Ports: FoundationPorts{Registry: 5100}}
t.Setenv(internalSuffixVar, "")
if got := fmt.Sprint(RegistryNames(o)); got != "[anchor.internal:5100]" {
@@ -158,7 +158,7 @@ func TestTheRegistrysTrustNamesThePortTheNodeServesItOn(t *testing.T) {
}
// A runtime that still refuses after the write is refused here, with the names, before any push.
func TestGenesisRefusesARuntimeThatStillDoesNotTrustTheRegistry(t *testing.T) {
func testGenesisRefusesARuntimeThatStillDoesNotTrustTheRegistry(t *testing.T) {
o, runtime, sys := trustSetup(t, "")
runtime.ignoresReload = true
_, err := TrustTheRegistry(context.Background(), o, sys, runtime.run, func(string) {})
@@ -176,7 +176,7 @@ func TestGenesisRefusesARuntimeThatStillDoesNotTrustTheRegistry(t *testing.T) {
// change, the runtime is not reloaded, and the member it declares is recorded as the module's from
// then on (a member found in a file with no record of it is the mesh's, ADR 0102), so the module
// owns the trust it writes and taking the module away takes that member out.
func TestTheDockerModuleTakesTheTrustOverWithoutAChange(t *testing.T) {
func testTheDockerModuleTakesTheTrustOverWithoutAChange(t *testing.T) {
o, runtime, sys := trustSetup(t, `{"live-restore":true}`)
if _, err := TrustTheRegistry(context.Background(), o, sys, runtime.run, func(string) {}); err != nil {
t.Fatal(err)
@@ -209,7 +209,7 @@ func TestTheDockerModuleTakesTheTrustOverWithoutAChange(t *testing.T) {
}
}
func TestARangeTheRuntimeTrustsCoversAnAddressInIt(t *testing.T) {
func testARangeTheRuntimeTrustsCoversAnAddressInIt(t *testing.T) {
missing, err := untrusted(`{"InsecureRegistryCIDRs":["10.42.0.0/16"],"IndexConfigs":{}}`,
[]string{"10.42.0.1:5000", "anchor.internal:5000"})
if err != nil {
@@ -224,7 +224,7 @@ func TestARangeTheRuntimeTrustsCoversAnAddressInIt(t *testing.T) {
// as dockerd does: a push to a registry it has not been told to trust is refused with the error the
// first genesis met. The trust must be written and confirmed before anything is tagged or pushed;
// moving the trust after the push, or dropping it, fails this test.
func TestNothingIsPushedToTheRegistryBeforeTheRuntimeTrustsIt(t *testing.T) {
func testNothingIsPushedToTheRegistryBeforeTheRuntimeTrustsIt(t *testing.T) {
o, runtime, sys := trustSetup(t, `{"data-root":"/srv/docker"}`)
// The store as distribution's manifest declares it: its container on this machine's loopback, its front not yet served,
// and its state directory, where no credential is ever written (design 51 *On a fresh mesh*, a design limit of issue 1966).
@@ -319,7 +319,7 @@ func TestNothingIsPushedToTheRegistryBeforeTheRuntimeTrustsIt(t *testing.T) {
}
// Preflight asks, without writing, what would stop the trust from taking at step 7.
func TestPreflightRefusesARuntimeThatCouldNotTakeTheTrust(t *testing.T) {
func testPreflightRefusesARuntimeThatCouldNotTakeTheTrust(t *testing.T) {
proc := t.TempDir()
was := procRoot
procRoot = proc
@@ -371,3 +371,14 @@ func TestPreflightRefusesARuntimeThatCouldNotTakeTheTrust(t *testing.T) {
})
}
}
// TestTrust runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestTrust(t *testing.T) {
t.Run("GenesisTrustsTheRegistryByEveryNameBeforeItPushes", testGenesisTrustsTheRegistryByEveryNameBeforeItPushes)
t.Run("TheRegistrysTrustNamesThePortTheNodeServesItOn", testTheRegistrysTrustNamesThePortTheNodeServesItOn)
t.Run("GenesisRefusesARuntimeThatStillDoesNotTrustTheRegistry", testGenesisRefusesARuntimeThatStillDoesNotTrustTheRegistry)
t.Run("TheDockerModuleTakesTheTrustOverWithoutAChange", testTheDockerModuleTakesTheTrustOverWithoutAChange)
t.Run("ARangeTheRuntimeTrustsCoversAnAddressInIt", testARangeTheRuntimeTrustsCoversAnAddressInIt)
t.Run("NothingIsPushedToTheRegistryBeforeTheRuntimeTrustsIt", testNothingIsPushedToTheRegistryBeforeTheRuntimeTrustsIt)
t.Run("PreflightRefusesARuntimeThatCouldNotTakeTheTrust", testPreflightRefusesARuntimeThatCouldNotTakeTheTrust)
}
+16 -6
View File
@@ -23,7 +23,7 @@ func foundation(t *testing.T) *declaration.Declaration {
// **A container that is up is not a control plane that replies**, and this project has paid for
// that distinction more than once. A runtime reports a container running from the moment its
// process starts — before it has opened a database, and before it has failed to.
func TestAContainerThatIsUpIsNotAControlPlaneThatReplies(t *testing.T) {
func testAContainerThatIsUpIsNotAControlPlaneThatReplies(t *testing.T) {
previous := answerEvery
answerEvery = time.Millisecond
defer func() { answerEvery = previous }()
@@ -53,7 +53,7 @@ func TestAContainerThatIsUpIsNotAControlPlaneThatReplies(t *testing.T) {
// Exit zero and silence is not an answer either. A program that returns nothing has not been asked
// anything, and treating it as success is the same fault one level down.
func TestAControlPlaneThatSaysNothingHasNotAnswered(t *testing.T) {
func testAControlPlaneThatSaysNothingHasNotAnswered(t *testing.T) {
previous := answerEvery
answerEvery = time.Millisecond
defer func() { answerEvery = previous }()
@@ -72,7 +72,7 @@ func TestAControlPlaneThatSaysNothingHasNotAnswered(t *testing.T) {
}
// The foundation answering is the whole point, and what it said is reported rather than asserted.
func TestAFoundationThatIsUpAndAnsweringIsAccepted(t *testing.T) {
func testAFoundationThatIsUpAndAnsweringIsAccepted(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
if args[0] == "container" {
return "true running\n", nil
@@ -105,7 +105,7 @@ func TestAFoundationThatIsUpAndAnsweringIsAccepted(t *testing.T) {
// A control plane that is still opening its stores is waited for, not refused. Refusing on the
// first attempt would make a correct bootstrap fail for being observed too early.
func TestAControlPlaneThatIsStillStartingIsWaitedFor(t *testing.T) {
func testAControlPlaneThatIsStillStartingIsWaitedFor(t *testing.T) {
previous := answerEvery
answerEvery = time.Millisecond
defer func() { answerEvery = previous }()
@@ -130,7 +130,7 @@ func TestAControlPlaneThatIsStillStartingIsWaitedFor(t *testing.T) {
// A container that exited is named with what it IS, so somebody can go and read its logs rather
// than being told only that something is not what it should be.
func TestAContainerThatExitedIsNamedWithItsState(t *testing.T) {
func testAContainerThatExitedIsNamedWithItsState(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
if args[0] == "container" && args[len(args)-1] == "mesh-broker-nats" {
return "false exited\n", nil
@@ -153,7 +153,7 @@ func TestAContainerThatExitedIsNamedWithItsState(t *testing.T) {
// The control plane is asked by running the binary in its own image directly, because the image is
// `FROM scratch` and has no shell for a command line to be interpreted by.
func TestTheControlPlaneIsAskedByRunningItsOwnBinary(t *testing.T) {
func testTheControlPlaneIsAskedByRunningItsOwnBinary(t *testing.T) {
runtime := &asked{answer: func(_ string, args []string) (string, error) {
if args[0] == "container" {
return "true running\n", nil
@@ -168,3 +168,13 @@ func TestTheControlPlaneIsAskedByRunningItsOwnBinary(t *testing.T) {
t.Errorf("the control plane was never asked anything: %v", runtime.commands)
}
}
// TestVerify runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestVerify(t *testing.T) {
t.Run("AContainerThatIsUpIsNotAControlPlaneThatReplies", testAContainerThatIsUpIsNotAControlPlaneThatReplies)
t.Run("AControlPlaneThatSaysNothingHasNotAnswered", testAControlPlaneThatSaysNothingHasNotAnswered)
t.Run("AFoundationThatIsUpAndAnsweringIsAccepted", testAFoundationThatIsUpAndAnsweringIsAccepted)
t.Run("AControlPlaneThatIsStillStartingIsWaitedFor", testAControlPlaneThatIsStillStartingIsWaitedFor)
t.Run("AContainerThatExitedIsNamedWithItsState", testAContainerThatExitedIsNamedWithItsState)
t.Run("TheControlPlaneIsAskedByRunningItsOwnBinary", testTheControlPlaneIsAskedByRunningItsOwnBinary)
}