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:
@@ -45,7 +45,7 @@ func withAssistant(t *testing.T) Input {
|
||||
|
||||
// Own secrets (plan.go renderingFor, novox/hq issue 275 and 401): one held and sealed to the machine's key is carried; one not held is
|
||||
// foreseen in the Foreseeing mode and left out in the Reading mode, and nothing is made.
|
||||
func TestAnOwnSecretHeldIsCarriedAndOneNotHeldIsForeseenOrLeftOut(t *testing.T) {
|
||||
func testAnOwnSecretHeldIsCarriedAndOneNotHeldIsForeseenOrLeftOut(t *testing.T) {
|
||||
mk := func() Input {
|
||||
in := withAssistant(t)
|
||||
in.OwnSecrets = []OwnSecretRow{{Node: "laptop", Module: "assistant", Name: "password", Origin: "made",
|
||||
@@ -93,7 +93,7 @@ func TestAnOwnSecretHeldIsCarriedAndOneNotHeldIsForeseenOrLeftOut(t *testing.T)
|
||||
|
||||
// An own secret issued outside the mesh that nobody gave is never made (novox/hq issue 401, ADR 0228): nothing is composed or
|
||||
// foreseen for it; a value the mesh made for it is not one a person gave; a value given is placed once it is sealed to the key held now.
|
||||
func TestAnOutsideSecretIsPlacedOnlyOnceAPersonGaveIt(t *testing.T) {
|
||||
func testAnOutsideSecretIsPlacedOnlyOnceAPersonGaveIt(t *testing.T) {
|
||||
in := withAssistant(t)
|
||||
key := nodeOf(t, &in, "laptop").SealingKey
|
||||
for _, mode := range []Mode{Reading, Foreseeing} {
|
||||
@@ -120,7 +120,7 @@ func TestAnOutsideSecretIsPlacedOnlyOnceAPersonGaveIt(t *testing.T) {
|
||||
// controller's words. No secret value is in an error. A bus account not yet issued is foreseen, issued or not (issue 774: the vault
|
||||
// mints it once the assignment is written on the Approve, ADR 0561 §1, ADR 0567 §5; mesh-self-check's proposal on ace was refused
|
||||
// "has no bus credential: nothing was issued for ace.mesh-self-check").
|
||||
func TestTheSendsRefusalsAreRefusedInTheSendsWords(t *testing.T) {
|
||||
func testTheSendsRefusalsAreRefusedInTheSendsWords(t *testing.T) {
|
||||
broker := catalogue.Manifest{Module: "mesh-self-check", Version: "1", RunsAs: "mesh-self-check",
|
||||
OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh/mesh-self-check/broker", Taken: catalogue.TakenAtStart}}}
|
||||
in := withAssistant(t)
|
||||
@@ -168,7 +168,7 @@ func aGrantMesh(t *testing.T) Input {
|
||||
|
||||
// A credential made for a consumer is a grant on its provider's machine, carrying the consumer's values and the sealed copy; without
|
||||
// the sealed copy a stand-in is composed and named (novox/hq plan.go grantsFor).
|
||||
func TestAGrantIsCreatedForEachCredentialMadeForAConsumer(t *testing.T) {
|
||||
func testAGrantIsCreatedForEachCredentialMadeForAConsumer(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
// 1126 (ADR 0550 §5): the credentials each node's composition reads, by their ends: laptop's files consumes anchor's
|
||||
// s3-bucket, and anchor grants it; the node composing its own asks the vault for exactly these.
|
||||
@@ -211,7 +211,7 @@ func TestAGrantIsCreatedForEachCredentialMadeForAConsumer(t *testing.T) {
|
||||
|
||||
// 1364/AC2: a consumer the grants leave out because its identity overflows the provision's bound is returned beside them, naming the
|
||||
// consumer and the provision (novox/hq ADR 0225), and is not granted.
|
||||
func TestAConsumerWhoseIdentityOverflowsIsLeftOutOfTheGrantsAndNamed(t *testing.T) {
|
||||
func testAConsumerWhoseIdentityOverflowsIsLeftOutOfTheGrantsAndNamed(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
in.Nodes[1].Name = "a-machine-with-a-very-long-name"
|
||||
in.Issued[0].Consumer = "a-machine-with-a-very-long-name"
|
||||
@@ -231,7 +231,7 @@ func TestAConsumerWhoseIdentityOverflowsIsLeftOutOfTheGrantsAndNamed(t *testing.
|
||||
|
||||
// 1364/AC3: a credential on record for a consumer that its own resolution binds to another provider is withdrawn, named with where it is
|
||||
// bound (novox/hq issue 274): the grant stays, with no consumer module asking.
|
||||
func TestACredentialBoundToAnotherProviderIsWithdrawnAndSaidWhereItIsBound(t *testing.T) {
|
||||
func testACredentialBoundToAnotherProviderIsWithdrawnAndSaidWhereItIsBound(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
second := objects()
|
||||
second.Module = "objects2"
|
||||
@@ -264,7 +264,7 @@ func aCertificateMesh(t *testing.T) Input {
|
||||
|
||||
// 1364/AC4: with no certificate and authority in the Input a stand-in is composed and named; given them, the composition carries them as
|
||||
// given. A machine that never reported a serving key, and one not on the private network, are refused in the controller's words.
|
||||
func TestACertificateIsCarriedAsGivenOrStoodInForAndNamed(t *testing.T) {
|
||||
func testACertificateIsCarriedAsGivenOrStoodInForAndNamed(t *testing.T) {
|
||||
in := aCertificateMesh(t)
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
if _, err := Render(in, "laptop", Foreseeing); err == nil || err.Error() != "laptop wants a certificate and has never told the mesh what key it serves with; it joins again to report one" {
|
||||
@@ -291,7 +291,7 @@ func aValidKey(t *testing.T, name string) string { return keyOf(t, name) }
|
||||
// 1364/AC5 and AC6: a core credential the node needs and the Input holds no box for is composed with a stand-in and returned as one
|
||||
// to keep; a kept box sealed to the key held now is carried; a node-engine below the vault-box contract is sent none (and nothing is
|
||||
// asked of it); a machine with no sealing key has its core module left out, said.
|
||||
func TestACoreBoxTheInputHoldsNoneOfIsReturnedToKeepAndNothingIsWritten(t *testing.T) {
|
||||
func testACoreBoxTheInputHoldsNoneOfIsReturnedToKeepAndNothingIsWritten(t *testing.T) {
|
||||
mk := func() Input {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["nats"] = catalogue.Manifest{Module: "nats", Version: "1", CoreCredentials: true,
|
||||
@@ -337,7 +337,7 @@ func TestACoreBoxTheInputHoldsNoneOfIsReturnedToKeepAndNothingIsWritten(t *testi
|
||||
// 1364/AC1: the bus's user list is carried for the machine that runs the bus and for no other; without it a stand-in is composed and
|
||||
// named; the users left out for want of a credential are said; each machine's membership is carried. (The list is composed by the
|
||||
// controller from the bus records, which stay the controller's: see the commit message.)
|
||||
func TestTheBusUserListIsCarriedForTheMachineThatRunsTheBus(t *testing.T) {
|
||||
func testTheBusUserListIsCarriedForTheMachineThatRunsTheBus(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["bus"] = catalogue.Manifest{Module: "bus", Version: "1", BusUsers: "/etc/bus/accounts.conf",
|
||||
Claims: []catalogue.Claim{{Name: "mesh-broker", Scope: catalogue.ScopeMesh}}}
|
||||
@@ -364,7 +364,7 @@ func TestTheBusUserListIsCarriedForTheMachineThatRunsTheBus(t *testing.T) {
|
||||
}
|
||||
|
||||
// 1364/AC7: nothing the composition says carries a secret value the Input holds.
|
||||
func TestNoSecretValueOfTheInputIsInWhatTheCompositionSays(t *testing.T) {
|
||||
func testNoSecretValueOfTheInputIsInWhatTheCompositionSays(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
in.Issued[0].ForProvider = secretValue
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
@@ -387,7 +387,7 @@ func TestNoSecretValueOfTheInputIsInWhatTheCompositionSays(t *testing.T) {
|
||||
// the vault mints or takes in; an offer of form none has no credential (issue 1126, 2026-11-02: mesh-cli on ace held for
|
||||
// "the grant of mcp-endpoint", whose provider node-tools offers form none): its grant carries the consumer and no
|
||||
// credential, nothing stands in on either side, and neither end asks the vault for one.
|
||||
func TestAConsumerNoCredentialWasMadeForYetIsGrantedWithAStandInUnlessItsOfferHasNone(t *testing.T) {
|
||||
func testAConsumerNoCredentialWasMadeForYetIsGrantedWithAStandInUnlessItsOfferHasNone(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
form string
|
||||
cred *catalogue.OfferCredential
|
||||
@@ -458,7 +458,7 @@ func TestAConsumerNoCredentialWasMadeForYetIsGrantedWithAStandInUnlessItsOfferHa
|
||||
}
|
||||
|
||||
// And a consumer whose identity overflows the provision's bound is judged before any credential is made for it (issue 263).
|
||||
func TestAnOverflowingConsumerNoCredentialWasMadeForYetIsWithheld(t *testing.T) {
|
||||
func testAnOverflowingConsumerNoCredentialWasMadeForYetIsWithheld(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
in.Issued = nil
|
||||
in.Catalogue["resolver"] = storeManifests()[1]
|
||||
@@ -473,7 +473,7 @@ func TestAnOverflowingConsumerNoCredentialWasMadeForYetIsWithheld(t *testing.T)
|
||||
}
|
||||
|
||||
// The grants come in the order the controller reads them, whatever order the Input gives its rows.
|
||||
func TestGrantsComeInTheOrderOfProvisionConsumerModuleAndLocal(t *testing.T) {
|
||||
func testGrantsComeInTheOrderOfProvisionConsumerModuleAndLocal(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
in.Issued = []Issued{
|
||||
{Provision: "s3-bucket", Consumer: "laptop", ConsumerModule: "files", Local: "b", Provider: "anchor", ForProvider: "x"},
|
||||
@@ -488,7 +488,7 @@ func TestGrantsComeInTheOrderOfProvisionConsumerModuleAndLocal(t *testing.T) {
|
||||
|
||||
// Round 1, finding 4: a member of a secret family a person gave, whose sealed value the Input does not carry, is placed with a
|
||||
// stand-in and named foreseen, not dropped as if nobody gave it.
|
||||
func TestAGivenFamilyMemberWithoutItsValueIsAStandInAndNamedForeseen(t *testing.T) {
|
||||
func testAGivenFamilyMemberWithoutItsValueIsAStandInAndNamedForeseen(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["mailer"] = catalogue.Manifest{Module: "mailer", Version: "1",
|
||||
OwnSecrets: catalogue.OwnSecrets{"credential-*": {Path: "/var/lib/mailer/credential-*.secret", Taken: catalogue.TakenAtStart, IssuedBy: catalogue.IssuedOutside}}}
|
||||
@@ -510,7 +510,7 @@ func TestAGivenFamilyMemberWithoutItsValueIsAStandInAndNamedForeseen(t *testing.
|
||||
}
|
||||
|
||||
// Round 1, finding 5: the suffix internal names end in is a field of the Input, and the environment is never read.
|
||||
func TestTheInternalSuffixIsTheInputsAndNeverTheEnvironments(t *testing.T) {
|
||||
func testTheInternalSuffixIsTheInputsAndNeverTheEnvironments(t *testing.T) {
|
||||
t.Setenv(overlay.SuffixVar, "from-the-environment")
|
||||
in := aGrantMesh(t)
|
||||
got := rendered(t, in, "anchor", Foreseeing)
|
||||
@@ -532,7 +532,7 @@ func TestTheInternalSuffixIsTheInputsAndNeverTheEnvironments(t *testing.T) {
|
||||
}
|
||||
|
||||
// Round 2: a need answered on the same machine is a grant too (catalogue resolve.go gives it From: the node's own name).
|
||||
func TestAConsumerOnTheProvidersOwnNodeIsGrantedWithAStandInAndNamedForeseen(t *testing.T) {
|
||||
func testAConsumerOnTheProvidersOwnNodeIsGrantedWithAStandInAndNamedForeseen(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
in.Issued = nil
|
||||
laptop, anchor := nodeOf(t, &in, "laptop"), nodeOf(t, &in, "anchor")
|
||||
@@ -546,3 +546,23 @@ func TestAConsumerOnTheProvidersOwnNodeIsGrantedWithAStandInAndNamedForeseen(t *
|
||||
t.Errorf("foreseen %v", got.Foreseen)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCredentials runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestCredentials(t *testing.T) {
|
||||
t.Run("AnOwnSecretHeldIsCarriedAndOneNotHeldIsForeseenOrLeftOut", testAnOwnSecretHeldIsCarriedAndOneNotHeldIsForeseenOrLeftOut)
|
||||
t.Run("AnOutsideSecretIsPlacedOnlyOnceAPersonGaveIt", testAnOutsideSecretIsPlacedOnlyOnceAPersonGaveIt)
|
||||
t.Run("TheSendsRefusalsAreRefusedInTheSendsWords", testTheSendsRefusalsAreRefusedInTheSendsWords)
|
||||
t.Run("AGrantIsCreatedForEachCredentialMadeForAConsumer", testAGrantIsCreatedForEachCredentialMadeForAConsumer)
|
||||
t.Run("AConsumerWhoseIdentityOverflowsIsLeftOutOfTheGrantsAndNamed", testAConsumerWhoseIdentityOverflowsIsLeftOutOfTheGrantsAndNamed)
|
||||
t.Run("ACredentialBoundToAnotherProviderIsWithdrawnAndSaidWhereItIsBound", testACredentialBoundToAnotherProviderIsWithdrawnAndSaidWhereItIsBound)
|
||||
t.Run("ACertificateIsCarriedAsGivenOrStoodInForAndNamed", testACertificateIsCarriedAsGivenOrStoodInForAndNamed)
|
||||
t.Run("ACoreBoxTheInputHoldsNoneOfIsReturnedToKeepAndNothingIsWritten", testACoreBoxTheInputHoldsNoneOfIsReturnedToKeepAndNothingIsWritten)
|
||||
t.Run("TheBusUserListIsCarriedForTheMachineThatRunsTheBus", testTheBusUserListIsCarriedForTheMachineThatRunsTheBus)
|
||||
t.Run("NoSecretValueOfTheInputIsInWhatTheCompositionSays", testNoSecretValueOfTheInputIsInWhatTheCompositionSays)
|
||||
t.Run("AConsumerNoCredentialWasMadeForYetIsGrantedWithAStandInUnlessItsOfferHasNone", testAConsumerNoCredentialWasMadeForYetIsGrantedWithAStandInUnlessItsOfferHasNone)
|
||||
t.Run("AnOverflowingConsumerNoCredentialWasMadeForYetIsWithheld", testAnOverflowingConsumerNoCredentialWasMadeForYetIsWithheld)
|
||||
t.Run("GrantsComeInTheOrderOfProvisionConsumerModuleAndLocal", testGrantsComeInTheOrderOfProvisionConsumerModuleAndLocal)
|
||||
t.Run("AGivenFamilyMemberWithoutItsValueIsAStandInAndNamedForeseen", testAGivenFamilyMemberWithoutItsValueIsAStandInAndNamedForeseen)
|
||||
t.Run("TheInternalSuffixIsTheInputsAndNeverTheEnvironments", testTheInternalSuffixIsTheInputsAndNeverTheEnvironments)
|
||||
t.Run("AConsumerOnTheProvidersOwnNodeIsGrantedWithAStandInAndNamedForeseen", testAConsumerOnTheProvidersOwnNodeIsGrantedWithAStandInAndNamedForeseen)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func onTheTunnel(t *testing.T, in *Input, replaced bool) {
|
||||
// novox/hq ADR 0105 (mesh-controller network_test.go TestTheOverlaysRangeIsTheAdoptedTunnels): the range every address is
|
||||
// composed from is the adopted tunnel's, read from the tunnel the hub holds, never stored anywhere else. The environment
|
||||
// value of the controller is Input.OverlayCIDR here.
|
||||
func TestTheOverlaysRangeIsTheAdoptedTunnels(t *testing.T) {
|
||||
func testTheOverlaysRangeIsTheAdoptedTunnels(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.OverlayCIDR = "10.99.0.0/16"
|
||||
if got := newComposer(in).overlayRange(); got != "10.99.0.0/16" {
|
||||
@@ -83,7 +83,7 @@ func TestTheOverlaysRangeIsTheAdoptedTunnels(t *testing.T) {
|
||||
// A takeover is composed only for a hub whose assignment agrees with the tunnel (mesh-controller network_test.go
|
||||
// TestATakeoverIsNotComposedForAHubPlacedOffItsTunnel): an address or an endpoint port that differs would have the host stop
|
||||
// the found interface and raise the mesh's where no peer is listening.
|
||||
func TestATakeoverIsNotComposedForAHubPlacedOffItsTunnel(t *testing.T) {
|
||||
func testATakeoverIsNotComposedForAHubPlacedOffItsTunnel(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
onTheTunnel(t, &in, false)
|
||||
// aMesh placed anchor at 10.77.0.1 on :51820, the record of a hub placed before it took the tunnel over.
|
||||
@@ -105,7 +105,7 @@ func TestATakeoverIsNotComposedForAHubPlacedOffItsTunnel(t *testing.T) {
|
||||
|
||||
// 1360/AC2: the generator gives the addresses, peers and names of aMesh: anchor the hub at 10.77.0.1, laptop at 10.77.0.2
|
||||
// peering through it, both written for their machines.
|
||||
func TestTheGeneratorGivesTheMeshItsAddressesAndPeers(t *testing.T) {
|
||||
func testTheGeneratorGivesTheMeshItsAddressesAndPeers(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
gens, err := Generators(in)
|
||||
if err != nil {
|
||||
@@ -139,7 +139,7 @@ func TestTheGeneratorGivesTheMeshItsAddressesAndPeers(t *testing.T) {
|
||||
|
||||
// 1360/AC3: a node not on the private network (it runs nothing that puts it there) gets no address and no network, and the
|
||||
// one that stayed keeps its own.
|
||||
func TestANodeNotOnThePrivateNetworkGetsNoAddressAndNoNetwork(t *testing.T) {
|
||||
func testANodeNotOnThePrivateNetworkGetsNoAddressAndNoNetwork(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
nodeOf(t, &in, "laptop").Assigned = nil // it keeps its place and its address, and stops running the network
|
||||
gens, err := Generators(in)
|
||||
@@ -161,7 +161,7 @@ func TestANodeNotOnThePrivateNetworkGetsNoAddressAndNoNetwork(t *testing.T) {
|
||||
// 1360/AC3: a node whose resolution is refused is said with today's words: the network missing its hub names the
|
||||
// machine that could not be resolved, which is almost always why. The hub here holds no complete place (no key): a refused
|
||||
// machine with one keeps it on the network (issue 1833), so only one without is missing from it.
|
||||
func TestARefusedNodeIsSaidWhenTheNetworkCannotBeComposed(t *testing.T) {
|
||||
func testARefusedNodeIsSaidWhenTheNetworkCannotBeComposed(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
nodeOf(t, &in, "anchor").Place.Key = ""
|
||||
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Resources: []map[string]any{{"id": "r", "type": "directory", "path": "/var/lib/the-same", "mode": "0700"}}}
|
||||
@@ -180,7 +180,7 @@ func TestARefusedNodeIsSaidWhenTheNetworkCannotBeComposed(t *testing.T) {
|
||||
}
|
||||
|
||||
// 1360/AC4: Generators changes nothing in its Input.
|
||||
func TestGeneratorsChangesNothingInItsInput(t *testing.T) {
|
||||
func testGeneratorsChangesNothingInItsInput(t *testing.T) {
|
||||
unchanged(t, func() Input {
|
||||
in := aMesh(t)
|
||||
onTheTunnel(t, &in, true)
|
||||
@@ -194,7 +194,7 @@ func TestGeneratorsChangesNothingInItsInput(t *testing.T) {
|
||||
}
|
||||
|
||||
// Each field of Input that the network reads reaches the generator: change it and the generator changes.
|
||||
func TestEachFieldOfTheInputReachesTheGenerator(t *testing.T) {
|
||||
func testEachFieldOfTheInputReachesTheGenerator(t *testing.T) {
|
||||
addressesOf := func(in Input) map[string]string {
|
||||
t.Helper()
|
||||
gens, err := Generators(in)
|
||||
@@ -302,3 +302,14 @@ func TestEachFieldOfTheInputReachesTheGenerator(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestNetwork runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestNetwork(t *testing.T) {
|
||||
t.Run("TheOverlaysRangeIsTheAdoptedTunnels", testTheOverlaysRangeIsTheAdoptedTunnels)
|
||||
t.Run("ATakeoverIsNotComposedForAHubPlacedOffItsTunnel", testATakeoverIsNotComposedForAHubPlacedOffItsTunnel)
|
||||
t.Run("TheGeneratorGivesTheMeshItsAddressesAndPeers", testTheGeneratorGivesTheMeshItsAddressesAndPeers)
|
||||
t.Run("ANodeNotOnThePrivateNetworkGetsNoAddressAndNoNetwork", testANodeNotOnThePrivateNetworkGetsNoAddressAndNoNetwork)
|
||||
t.Run("ARefusedNodeIsSaidWhenTheNetworkCannotBeComposed", testARefusedNodeIsSaidWhenTheNetworkCannotBeComposed)
|
||||
t.Run("GeneratorsChangesNothingInItsInput", testGeneratorsChangesNothingInItsInput)
|
||||
t.Run("EachFieldOfTheInputReachesTheGenerator", testEachFieldOfTheInputReachesTheGenerator)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func aSmallMesh(t *testing.T) Input {
|
||||
// 1298/AC1: each node of a small mesh composes, its body is accepted by the node-engine's validator, and it names the resources the
|
||||
// controller composes for the same case: the private network's files on the nodes that run it, the provider's received file, the
|
||||
// consumer's file.
|
||||
func TestEachNodeOfASmallMeshComposesAndItsBodyIsAcceptedByTheValidator(t *testing.T) {
|
||||
func testEachNodeOfASmallMeshComposesAndItsBodyIsAcceptedByTheValidator(t *testing.T) {
|
||||
in := aSmallMesh(t)
|
||||
want := map[string][]string{
|
||||
"anchor": {"package:mesh-wireguard.overlay-tools", "file:mesh-wireguard.overlay-config", "service:mesh-wireguard.overlay-up", "file:objects.received-s3-bucket"},
|
||||
@@ -85,7 +85,7 @@ func TestEachNodeOfASmallMeshComposesAndItsBodyIsAcceptedByTheValidator(t *testi
|
||||
// 1298/AC2 (mesh-controller merge_gate_integration_test.go TestIssue236AManifestTheNodeEngineRefusesFailsThePullRequest, the manifest):
|
||||
// a service that omits its state is accepted by the catalogue's check and refused by the node-engine; Compose returns the validator's
|
||||
// problems in the node-engine's words and no error.
|
||||
func TestAManifestTheNodeEngineRefusesComesBackAsProblemsAndNoError(t *testing.T) {
|
||||
func testAManifestTheNodeEngineRefusesComesBackAsProblemsAndNoError(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
var lemurs catalogue.Manifest
|
||||
if err := json.Unmarshal([]byte(`{"module":"lemurs","version":"1","capabilities":["systemd"],
|
||||
@@ -113,7 +113,7 @@ func TestAManifestTheNodeEngineRefusesComesBackAsProblemsAndNoError(t *testing.T
|
||||
}
|
||||
|
||||
// 1298/AC4: composing the same Input twice gives byte-identical bodies, and the Input is unchanged.
|
||||
func TestComposingTwiceGivesTheSameBytesAndChangesNothing(t *testing.T) {
|
||||
func testComposingTwiceGivesTheSameBytesAndChangesNothing(t *testing.T) {
|
||||
mk := func() Input {
|
||||
in := aSmallMesh(t)
|
||||
nodeOf(t, &in, "anchor").Account = "jochens"
|
||||
@@ -147,7 +147,7 @@ func TestComposingTwiceGivesTheSameBytesAndChangesNothing(t *testing.T) {
|
||||
|
||||
// 1298/AC5: what a send would make is named in the result as foreseen and never invented: an own secret, a port, a core box, a grant's
|
||||
// sealed copy.
|
||||
func TestWhatASendWouldMakeIsNamedAsForeseenAndNeverInvented(t *testing.T) {
|
||||
func testWhatASendWouldMakeIsNamedAsForeseenAndNeverInvented(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
in.Issued[0].ForProvider = ""
|
||||
in.Catalogue["assistant"] = anAssistant()
|
||||
@@ -183,7 +183,7 @@ func TestWhatASendWouldMakeIsNamedAsForeseenAndNeverInvented(t *testing.T) {
|
||||
|
||||
// 1298/AC6: the body carries the sequence, epoch and generation the Input gives, and the module of each resource and the carried builds
|
||||
// only to a node whose Input says it reads modules (novox/hq issue 1145).
|
||||
func TestTheBodyCarriesTheOrderTheInputGivesAndTheBuildsOnlyToAnEngineThatReadsThem(t *testing.T) {
|
||||
func testTheBodyCarriesTheOrderTheInputGivesAndTheBuildsOnlyToAnEngineThatReadsThem(t *testing.T) {
|
||||
in := aSmallMesh(t)
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
laptop.Sequence, laptop.Epoch, laptop.Generation = 42, 57, 9
|
||||
@@ -246,7 +246,7 @@ func TestTheBodyCarriesTheOrderTheInputGivesAndTheBuildsOnlyToAnEngineThatReadsT
|
||||
}
|
||||
|
||||
// A module left out of a build set keeps the build it was last sent (novox/hq issue 259): the machine keeps that one.
|
||||
func TestAModuleLeftOutKeepsTheBuildItWasLastSent(t *testing.T) {
|
||||
func testAModuleLeftOutKeepsTheBuildItWasLastSent(t *testing.T) {
|
||||
c := newComposer(Input{CurrentBuilds: map[string]string{"a": "new-a", "b": "new-b"}})
|
||||
plan := catalogue.Resolution{Modules: []catalogue.Manifest{{Module: "a"}, {Module: "b"}, {Module: "c"}}}
|
||||
node := Node{SentBuilds: map[string]string{"b": "old-b", "c": "old-c"}, SentKnown: true}
|
||||
@@ -262,7 +262,7 @@ func TestAModuleLeftOutKeepsTheBuildItWasLastSent(t *testing.T) {
|
||||
|
||||
// An adopted node is told which modules were taken and, for every module it runs that is not, the ids of its resources
|
||||
// (novox/hq ADR 0100 and 0103); a converged node is told nothing, and its body is as it was before adoption.
|
||||
func TestAnAdoptedNodeIsToldWhatWasTakenAndWhatIsKept(t *testing.T) {
|
||||
func testAnAdoptedNodeIsToldWhatWasTakenAndWhatIsKept(t *testing.T) {
|
||||
in := aSmallMesh(t)
|
||||
d, _, err := Compose(in, "laptop")
|
||||
if err != nil || d.Adoption != nil {
|
||||
@@ -286,7 +286,7 @@ func TestAnAdoptedNodeIsToldWhatWasTakenAndWhatIsKept(t *testing.T) {
|
||||
// Issue 263 (merge_gate_integration_test.go TestIssue263AnIdentityARealMachineNameOverflows...): a change makes the network manager
|
||||
// require the object store's provision; on a machine whose name is six characters its identity is 26 against a bound of 20. The
|
||||
// composition of the provider returns the refusal, naming the module and the provision.
|
||||
func TestIssue263AnIdentityARealMachineNameOverflowsIsARefusal(t *testing.T) {
|
||||
func testIssue263AnIdentityARealMachineNameOverflowsIsARefusal(t *testing.T) {
|
||||
in := aGrantMesh(t)
|
||||
in.Catalogue["resolver"] = storeManifests()[1]
|
||||
in.Catalogue["networkmanager"] = catalogue.Manifest{Module: "networkmanager", Version: "1", Requires: []string{"wildcard-resolution", "s3-bucket"}}
|
||||
@@ -311,7 +311,7 @@ func TestIssue263AnIdentityARealMachineNameOverflowsIsARefusal(t *testing.T) {
|
||||
|
||||
// Round 1, finding 1 (plan.go keepRecorded): a recorded module kept at the build a machine runs is that machine's own resolution
|
||||
// and no other's; the commit carried for it is the kept one.
|
||||
func TestAKeptModuleChangesOnlyTheResolutionOfTheNodeThatKeepsIt(t *testing.T) {
|
||||
func testAKeptModuleChangesOnlyTheResolutionOfTheNodeThatKeepsIt(t *testing.T) {
|
||||
in := aSmallMesh(t)
|
||||
in.Catalogue["tool"] = catalogue.Manifest{Module: "tool", Version: "2"}
|
||||
for _, name := range []string{"anchor", "laptop"} {
|
||||
@@ -356,7 +356,7 @@ func TestAKeptModuleChangesOnlyTheResolutionOfTheNodeThatKeepsIt(t *testing.T) {
|
||||
|
||||
// Another node's kept build changes neither the rest of the mesh nor who is on the network: the controller reads both with the
|
||||
// current manifests, and only then keeps a recorded module for the node it composes (recorded_kept.go keepRecorded).
|
||||
func TestAnotherNodesKeptBuildDoesNotChangeTheRestOfTheMeshOrWhoIsOnTheNetwork(t *testing.T) {
|
||||
func testAnotherNodesKeptBuildDoesNotChangeTheRestOfTheMeshOrWhoIsOnTheNetwork(t *testing.T) {
|
||||
in := threeNodes(t)
|
||||
nodeOf(t, &in, "anchor").Kept = map[string]catalogue.Manifest{"objects": {Module: "objects", Version: "0"}, overlayName(): {Module: overlayName(), Version: "0"}}
|
||||
w, _, _, err := TheRestOfTheMesh(in, "laptop")
|
||||
@@ -373,7 +373,7 @@ func overlayName() string { return overlay.Name }
|
||||
|
||||
// Round 1, finding 6: the nodes the composition did not count as on the network are returned, said, not lost. laptop holds no
|
||||
// complete place (no key): one that does keeps it on the network (issue 1833) and is counted.
|
||||
func TestANodeNotCountedAsOnTheNetworkIsSaidInTheResult(t *testing.T) {
|
||||
func testANodeNotCountedAsOnTheNetworkIsSaidInTheResult(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
nodeOf(t, &in, "laptop").Place.Key = ""
|
||||
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Resources: []map[string]any{{"id": "r", "type": "directory", "path": "/var/lib/the-same", "mode": "0700"}}}
|
||||
@@ -406,3 +406,18 @@ func TestANodeNotCountedAsOnTheNetworkIsSaidInTheResult(t *testing.T) {
|
||||
t.Errorf("said %d times: %v", n, d.Said)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNode runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestNode(t *testing.T) {
|
||||
t.Run("EachNodeOfASmallMeshComposesAndItsBodyIsAcceptedByTheValidator", testEachNodeOfASmallMeshComposesAndItsBodyIsAcceptedByTheValidator)
|
||||
t.Run("AManifestTheNodeEngineRefusesComesBackAsProblemsAndNoError", testAManifestTheNodeEngineRefusesComesBackAsProblemsAndNoError)
|
||||
t.Run("ComposingTwiceGivesTheSameBytesAndChangesNothing", testComposingTwiceGivesTheSameBytesAndChangesNothing)
|
||||
t.Run("WhatASendWouldMakeIsNamedAsForeseenAndNeverInvented", testWhatASendWouldMakeIsNamedAsForeseenAndNeverInvented)
|
||||
t.Run("TheBodyCarriesTheOrderTheInputGivesAndTheBuildsOnlyToAnEngineThatReadsThem", testTheBodyCarriesTheOrderTheInputGivesAndTheBuildsOnlyToAnEngineThatReadsThem)
|
||||
t.Run("AModuleLeftOutKeepsTheBuildItWasLastSent", testAModuleLeftOutKeepsTheBuildItWasLastSent)
|
||||
t.Run("AnAdoptedNodeIsToldWhatWasTakenAndWhatIsKept", testAnAdoptedNodeIsToldWhatWasTakenAndWhatIsKept)
|
||||
t.Run("Issue263AnIdentityARealMachineNameOverflowsIsARefusal", testIssue263AnIdentityARealMachineNameOverflowsIsARefusal)
|
||||
t.Run("AKeptModuleChangesOnlyTheResolutionOfTheNodeThatKeepsIt", testAKeptModuleChangesOnlyTheResolutionOfTheNodeThatKeepsIt)
|
||||
t.Run("AnotherNodesKeptBuildDoesNotChangeTheRestOfTheMeshOrWhoIsOnTheNetwork", testAnotherNodesKeptBuildDoesNotChangeTheRestOfTheMeshOrWhoIsOnTheNetwork)
|
||||
t.Run("ANodeNotCountedAsOnTheNetworkIsSaidInTheResult", testANodeNotCountedAsOnTheNetworkIsSaidInTheResult)
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func placesOf(g *overlay.Generator) map[string]overlay.Node {
|
||||
|
||||
// 1833/AC1: four machines, the hub's own set does not resolve; the other three compose their declarations, and the hub alone is
|
||||
// refused, with an error that is its own set failing and names what could not be resolved.
|
||||
func TestOneMachineThatDoesNotResolveIsRefusedAlone(t *testing.T) {
|
||||
func testOneMachineThatDoesNotResolveIsRefusedAlone(t *testing.T) {
|
||||
in := fourOnTheNetwork(t)
|
||||
unresolvableBy(t, &in, "anchor")
|
||||
for _, node := range []string{"laptop", "ace", "box"} {
|
||||
@@ -79,7 +79,7 @@ func TestOneMachineThatDoesNotResolveIsRefusedAlone(t *testing.T) {
|
||||
|
||||
// 1833/AC2: the private network is composed with every machine on it: the hub that does not resolve keeps its place (key,
|
||||
// address, endpoint, site, hub role), so every other machine keeps its path through it.
|
||||
func TestAMachineThatDoesNotResolveKeepsItsPlaceOnTheNetwork(t *testing.T) {
|
||||
func testAMachineThatDoesNotResolveKeepsItsPlaceOnTheNetwork(t *testing.T) {
|
||||
in := fourOnTheNetwork(t)
|
||||
unresolvableBy(t, &in, "anchor")
|
||||
got := placesOf(networkOf(t, in))
|
||||
@@ -107,7 +107,7 @@ func TestAMachineThatDoesNotResolveKeepsItsPlaceOnTheNetwork(t *testing.T) {
|
||||
|
||||
// 1833/AC3: a machine that does not resolve and was never placed (a new machine: no key, no address) is left off the network,
|
||||
// which is composed from the rest -- here with the hub that does not resolve on its last place -- and that machine alone is refused.
|
||||
func TestANewMachineThatDoesNotResolveIsLeftOffAndRefusedAlone(t *testing.T) {
|
||||
func testANewMachineThatDoesNotResolveIsLeftOffAndRefusedAlone(t *testing.T) {
|
||||
in := fourOnTheNetwork(t)
|
||||
unresolvableBy(t, &in, "anchor")
|
||||
in.Nodes = append(in.Nodes, Node{Name: "fresh", Place: Place{Site: "there"},
|
||||
@@ -126,7 +126,7 @@ func TestANewMachineThatDoesNotResolveIsLeftOffAndRefusedAlone(t *testing.T) {
|
||||
|
||||
// 1833/AC4: a network that truly cannot be composed from what remains still fails: the hub does not resolve and has no
|
||||
// complete place (no key), so nothing is the hub; the refusal is today's, naming the machine that could not be resolved.
|
||||
func TestANetworkThatCannotBeComposedFromWhatRemainsStillFails(t *testing.T) {
|
||||
func testANetworkThatCannotBeComposedFromWhatRemainsStillFails(t *testing.T) {
|
||||
in := fourOnTheNetwork(t)
|
||||
unresolvableBy(t, &in, "anchor")
|
||||
nodeOf(t, &in, "anchor").Place.Key = ""
|
||||
@@ -147,7 +147,7 @@ func TestANetworkThatCannotBeComposedFromWhatRemainsStillFails(t *testing.T) {
|
||||
// 1833/AC2, a failure the composition's unchecked pass refuses too (two modules claiming one seat on the hub, the 1360/AC3
|
||||
// shape): the hub keeps its place in what every other machine is sent besides the tunnel -- its internal name and its address
|
||||
// among the sources "from the mesh" -- and another machine still composes.
|
||||
func TestAMachineThatDoesNotResolveKeepsItsNameAndItsAddressInTheMesh(t *testing.T) {
|
||||
func testAMachineThatDoesNotResolveKeepsItsNameAndItsAddressInTheMesh(t *testing.T) {
|
||||
in := fourOnTheNetwork(t)
|
||||
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Resources: []map[string]any{{"id": "r", "type": "directory", "path": "/var/lib/the-same", "mode": "0700"}}}
|
||||
in.Catalogue["rival-two"] = catalogue.Manifest{Module: "rival-two", Version: "1", Resources: []map[string]any{{"id": "r", "type": "directory", "path": "/var/lib/the-same", "mode": "0700"}}}
|
||||
@@ -167,3 +167,12 @@ func TestAMachineThatDoesNotResolveKeepsItsNameAndItsAddressInTheMesh(t *testing
|
||||
t.Errorf("another machine does not compose: %v %v", err, problems)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOneMachineAlone runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestOneMachineAlone(t *testing.T) {
|
||||
t.Run("OneMachineThatDoesNotResolveIsRefusedAlone", testOneMachineThatDoesNotResolveIsRefusedAlone)
|
||||
t.Run("AMachineThatDoesNotResolveKeepsItsPlaceOnTheNetwork", testAMachineThatDoesNotResolveKeepsItsPlaceOnTheNetwork)
|
||||
t.Run("ANewMachineThatDoesNotResolveIsLeftOffAndRefusedAlone", testANewMachineThatDoesNotResolveIsLeftOffAndRefusedAlone)
|
||||
t.Run("ANetworkThatCannotBeComposedFromWhatRemainsStillFails", testANetworkThatCannotBeComposedFromWhatRemainsStillFails)
|
||||
t.Run("AMachineThatDoesNotResolveKeepsItsNameAndItsAddressInTheMesh", testAMachineThatDoesNotResolveKeepsItsNameAndItsAddressInTheMesh)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func placed(t *testing.T, in Input, node string) Placed {
|
||||
|
||||
// 1363/AC1 and AC2: a port the Input holds as allocated on the node is the one composed; with none, no number is invented: the
|
||||
// manifest's own is composed and the port is named foreseen, as the Foreseeing mode does.
|
||||
func TestAnAllocatedPortIsComposedAndAnUnallocatedOneIsNamedForeseenNotInvented(t *testing.T) {
|
||||
func testAnAllocatedPortIsComposedAndAnUnallocatedOneIsNamedForeseenNotInvented(t *testing.T) {
|
||||
mk := func() Input {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["web"] = aWebModule()
|
||||
@@ -81,7 +81,7 @@ func TestAnAllocatedPortIsComposedAndAnUnallocatedOneIsNamedForeseenNotInvented(
|
||||
|
||||
// 1363/AC3: a port the operator gave is used, over the allocated one, and a consumer elsewhere is told it
|
||||
// (mesh-controller sendable_integration_test.go TestConsumersAreToldTheGivenPort).
|
||||
func TestAPortTheOperatorGaveIsUsedAndNotReallocated(t *testing.T) {
|
||||
func testAPortTheOperatorGaveIsUsedAndNotReallocated(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["store"] = aStoreModule()
|
||||
in.Catalogue["app"] = catalogue.Manifest{Module: "app", Version: "1", Requires: []string{"database"}}
|
||||
@@ -131,7 +131,7 @@ func TestAPortTheOperatorGaveIsUsedAndNotReallocated(t *testing.T) {
|
||||
// 1363/AC4: the seats held and taken reach the Rendering: where each mesh-scoped seat's holder put its ports, from the node's
|
||||
// given and assigned ports, never the manifest's own; and on an adopted node a holder assigned but not taken counts only by its
|
||||
// given ports (novox/hq ADR 0100).
|
||||
func TestSeatsHeldAndTakenReachTheRendering(t *testing.T) {
|
||||
func testSeatsHeldAndTakenReachTheRendering(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
holder := aStoreModule()
|
||||
holder.Claims = []catalogue.Claim{{Name: "mesh-store", Scope: catalogue.ScopeMesh}}
|
||||
@@ -163,7 +163,7 @@ func TestSeatsHeldAndTakenReachTheRendering(t *testing.T) {
|
||||
// 1363/AC4: local networks and outward links (mesh-controller local_network_test.go TestNodeShowsWhichAttachedNetworksCountAndWhy,
|
||||
// the values): a private network on a link facing outside counts, a public subnet and the private network's own link never do; a
|
||||
// machine that said none judges to nothing.
|
||||
func TestLocalNetworksAndOutwardLinksReachTheRendering(t *testing.T) {
|
||||
func testLocalNetworksAndOutwardLinksReachTheRendering(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
laptop.OutwardLinks = []string{"eth0", "eth1"}
|
||||
@@ -184,7 +184,7 @@ func TestLocalNetworksAndOutwardLinksReachTheRendering(t *testing.T) {
|
||||
}
|
||||
|
||||
// 1363/AC4: accounts, the names of the mesh, the mesh range and the operator's export reach the Rendering.
|
||||
func TestAccountsNamesAndTheOperatorsExportReachTheRendering(t *testing.T) {
|
||||
func testAccountsNamesAndTheOperatorsExportReachTheRendering(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
nodeOf(t, &in, "anchor").Account = "jochens"
|
||||
in.OperatorExport = &catalogue.KeptExport{}
|
||||
@@ -223,7 +223,7 @@ func TestAccountsNamesAndTheOperatorsExportReachTheRendering(t *testing.T) {
|
||||
|
||||
// The names the operator gave to peers of an adopted tunnel answer until they enrol (novox/hq issue 112); a node of the mesh owns
|
||||
// its name.
|
||||
func TestACarriedPeerIsNamedUntilItEnrols(t *testing.T) {
|
||||
func testACarriedPeerIsNamedUntilItEnrols(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.CarriedPeers = []CarriedPeer{{PublicKey: "K1", Address: "192.0.2.5", Named: "printer"},
|
||||
{PublicKey: "K2", Address: "192.0.2.6", Named: "laptop"}, {PublicKey: "K3", Address: "192.0.2.7", Named: "late", EnrolledAs: "late"}}
|
||||
@@ -234,7 +234,7 @@ func TestACarriedPeerIsNamedUntilItEnrols(t *testing.T) {
|
||||
}
|
||||
|
||||
// A node-engine older than a contract is not sent the field it would refuse (novox/hq ADR 0240 and after).
|
||||
func TestTheNodeEnginesContractGatesWhatItIsSent(t *testing.T) {
|
||||
func testTheNodeEnginesContractGatesWhatItIsSent(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
if r := placed(t, in, "laptop").Rendering; r.ReadsHealth || r.JudgesRoot || r.ReadsBusy || r.Hands {
|
||||
@@ -252,7 +252,7 @@ func TestTheNodeEnginesContractGatesWhatItIsSent(t *testing.T) {
|
||||
|
||||
// The artifact store as a node reaches it: over the private network by its holder's name and the port it put it on, or on loopback
|
||||
// for the holder alone while nothing is on the network (novox/hq 04-ISSUES/102).
|
||||
func TestTheArtifactStoreIsReachedOverTheNetworkOrOnLoopbackForItsHolder(t *testing.T) {
|
||||
func testTheArtifactStoreIsReachedOverTheNetworkOrOnLoopbackForItsHolder(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["artifacts"] = catalogue.Manifest{Module: "artifacts", Version: "1",
|
||||
Claims: []catalogue.Claim{{Name: "container-image-registry", Scope: catalogue.ScopeMesh}},
|
||||
@@ -295,7 +295,7 @@ func TestTheArtifactStoreIsReachedOverTheNetworkOrOnLoopbackForItsHolder(t *test
|
||||
// The store's address is the image seat's holder's listen open to the mesh, on the port its node put it on, and every
|
||||
// name of the store answers it (novox/hq ADR 0632 §1): a module serving the retired provision artifact-store is no store,
|
||||
// and a holder opening two listens to the mesh says which is the store by no guess.
|
||||
func TestTheStoreIsFoundByTheImageSeatsHolderAndItsListen(t *testing.T) {
|
||||
func testTheStoreIsFoundByTheImageSeatsHolderAndItsListen(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["old"] = catalogue.Manifest{Module: "old", Version: "1",
|
||||
Serves: map[string]map[string]any{catalogue.ArtifactStoreProvision: {"port": 5100}}}
|
||||
@@ -409,7 +409,7 @@ func TestTheStoreIsFoundByTheImageSeatsHolderAndItsListen(t *testing.T) {
|
||||
|
||||
// A zone a module declares is placed where the mesh put it: settled from that node's settings, at the node's private address, on
|
||||
// the port the answering listen is published on there (novox/hq ADR 0199); the same zone declared twice is refused, by name.
|
||||
func TestAZoneIsPlacedWhereTheMeshPutItAndTheSameZoneTwiceIsRefused(t *testing.T) {
|
||||
func testAZoneIsPlacedWhereTheMeshPutItAndTheSameZoneTwiceIsRefused(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
lab := catalogue.Manifest{Module: "lab", Version: "1", Zone: &catalogue.Zone{Name: "${setting:zone}", Listen: "dns"},
|
||||
Listens: []catalogue.Listening{{Name: "dns", Port: 53, Protocol: "udp", From: catalogue.FromMesh}}}
|
||||
@@ -432,7 +432,7 @@ func TestAZoneIsPlacedWhereTheMeshPutItAndTheSameZoneTwiceIsRefused(t *testing.T
|
||||
|
||||
// Every holder of a replicated seat is listed by internal name at its private address (novox/hq ADR 0223): the holders on record,
|
||||
// and only the sole claimant when there are none; a holder off the private network is left out.
|
||||
func TestEveryHolderOfAReplicatedSeatIsListedOnTheNetwork(t *testing.T) {
|
||||
func testEveryHolderOfAReplicatedSeatIsListedOnTheNetwork(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
resolver := catalogue.Manifest{Module: "resolver", Version: "1",
|
||||
Provides: []catalogue.Offer{{Name: "wildcard-resolution", Scope: catalogue.ScopeMesh}},
|
||||
@@ -460,3 +460,18 @@ func TestEveryHolderOfAReplicatedSeatIsListedOnTheNetwork(t *testing.T) {
|
||||
t.Errorf("a holder off the network is listed: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRendering runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestRendering(t *testing.T) {
|
||||
t.Run("AnAllocatedPortIsComposedAndAnUnallocatedOneIsNamedForeseenNotInvented", testAnAllocatedPortIsComposedAndAnUnallocatedOneIsNamedForeseenNotInvented)
|
||||
t.Run("APortTheOperatorGaveIsUsedAndNotReallocated", testAPortTheOperatorGaveIsUsedAndNotReallocated)
|
||||
t.Run("SeatsHeldAndTakenReachTheRendering", testSeatsHeldAndTakenReachTheRendering)
|
||||
t.Run("LocalNetworksAndOutwardLinksReachTheRendering", testLocalNetworksAndOutwardLinksReachTheRendering)
|
||||
t.Run("AccountsNamesAndTheOperatorsExportReachTheRendering", testAccountsNamesAndTheOperatorsExportReachTheRendering)
|
||||
t.Run("ACarriedPeerIsNamedUntilItEnrols", testACarriedPeerIsNamedUntilItEnrols)
|
||||
t.Run("TheNodeEnginesContractGatesWhatItIsSent", testTheNodeEnginesContractGatesWhatItIsSent)
|
||||
t.Run("TheArtifactStoreIsReachedOverTheNetworkOrOnLoopbackForItsHolder", testTheArtifactStoreIsReachedOverTheNetworkOrOnLoopbackForItsHolder)
|
||||
t.Run("TheStoreIsFoundByTheImageSeatsHolderAndItsListen", testTheStoreIsFoundByTheImageSeatsHolderAndItsListen)
|
||||
t.Run("AZoneIsPlacedWhereTheMeshPutItAndTheSameZoneTwiceIsRefused", testAZoneIsPlacedWhereTheMeshPutItAndTheSameZoneTwiceIsRefused)
|
||||
t.Run("EveryHolderOfAReplicatedSeatIsListedOnTheNetwork", testEveryHolderOfAReplicatedSeatIsListedOnTheNetwork)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// Declared as accesses to an operator-owned path (novox/hq ADR 0051), they co-resolve. An access
|
||||
// is not a resource and never enters the duplicate-owner map, so this is the exact case the
|
||||
// resolver refuses above when the same path is owned — and does not, when it is merely accessed.
|
||||
func TestTwoModulesAccessingOnePathCoResolve(t *testing.T) {
|
||||
func testTwoModulesAccessingOnePathCoResolve(t *testing.T) {
|
||||
a := mod("a", nil, nil, nil)
|
||||
a.Accesses = []mcat.Access{{Path: "/services/media/downloads", Mode: mcat.AccessReadWrite}}
|
||||
b := mod("b", nil, nil, nil)
|
||||
@@ -41,7 +41,7 @@ func TestTwoModulesAccessingOnePathCoResolve(t *testing.T) {
|
||||
|
||||
// The mirror of the case above, so the sharing vocabulary does not weaken the rule it sits beside:
|
||||
// two modules OWNING one path is still refused, exactly as before accesses existed.
|
||||
func TestTwoModulesOwningOnePathAreStillRefused(t *testing.T) {
|
||||
func testTwoModulesOwningOnePathAreStillRefused(t *testing.T) {
|
||||
a := mod("a", nil, nil, nil)
|
||||
a.Resources = []map[string]any{
|
||||
{"id": "lib", "type": "directory", "path": "/services/media/movies", "mode": "0755"}}
|
||||
@@ -62,7 +62,7 @@ func TestTwoModulesOwningOnePathAreStillRefused(t *testing.T) {
|
||||
// another module was told to expect the operator to provide would create and chown it — and the
|
||||
// two intentions cannot both hold, so it is refused by name. This is what keeps the distinction
|
||||
// machine-checkable rather than a convention nobody enforces.
|
||||
func TestAModuleMayNotOwnWhatAnotherAccesses(t *testing.T) {
|
||||
func testAModuleMayNotOwnWhatAnotherAccesses(t *testing.T) {
|
||||
owns := mod("owns", nil, nil, nil)
|
||||
owns.Resources = []map[string]any{
|
||||
{"id": "lib", "type": "directory", "path": "/services/media/movies", "mode": "0755"}}
|
||||
@@ -78,3 +78,10 @@ func TestAModuleMayNotOwnWhatAnotherAccesses(t *testing.T) {
|
||||
t.Errorf("the refusal does not explain the ownership conflict: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAccesses runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestAccesses(t *testing.T) {
|
||||
t.Run("TwoModulesAccessingOnePathCoResolve", testTwoModulesAccessingOnePathCoResolve)
|
||||
t.Run("TwoModulesOwningOnePathAreStillRefused", testTwoModulesOwningOnePathAreStillRefused)
|
||||
t.Run("AModuleMayNotOwnWhatAnotherAccesses", testAModuleMayNotOwnWhatAnotherAccesses)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func byID(resources []map[string]any) map[string]map[string]any {
|
||||
return out
|
||||
}
|
||||
|
||||
func TestAnAdoptedNodeIsDeclaredOpeningsFromTheSameInputsAsTheFilter(t *testing.T) {
|
||||
func testAnAdoptedNodeIsDeclaredOpeningsFromTheSameInputsAsTheFilter(t *testing.T) {
|
||||
composed, err := Compose(anAdoptedAnchor(), anchorRendering(true))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -134,7 +134,7 @@ func TestAnAdoptedNodeIsDeclaredOpeningsFromTheSameInputsAsTheFilter(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnAdoptedNodeLoadsNoFilterOfTheMeshs(t *testing.T) {
|
||||
func testAnAdoptedNodeLoadsNoFilterOfTheMeshs(t *testing.T) {
|
||||
composed, err := Compose(anAdoptedAnchor(), anchorRendering(true))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -193,7 +193,7 @@ func TestAnAdoptedNodeLoadsNoFilterOfTheMeshs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAConvergedNodeIsDeclaredItsFilterAndNoOpenings(t *testing.T) {
|
||||
func testAConvergedNodeIsDeclaredItsFilterAndNoOpenings(t *testing.T) {
|
||||
composed, err := Compose(anAdoptedAnchor(), anchorRendering(false))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -219,7 +219,7 @@ func TestAConvergedNodeIsDeclaredItsFilterAndNoOpenings(t *testing.T) {
|
||||
}
|
||||
|
||||
// The table the installer raises and the controller declares, character for character.
|
||||
func TestTheGuardIsExactlyThisTable(t *testing.T) {
|
||||
func testTheGuardIsExactlyThisTable(t *testing.T) {
|
||||
const golden = `table inet mesh_guard {}
|
||||
delete table inet mesh_guard
|
||||
table inet mesh_guard {
|
||||
@@ -263,7 +263,7 @@ func keys[V any](m map[string]V) []string {
|
||||
|
||||
// novox/hq ADR 0100: the foundation's ports are the node's. Given 5433 for the store, every place
|
||||
// that uses the port reads it from there: the container, the filter, the openings, the guard.
|
||||
func TestAGivenPortIsUsedEverywhereThePortIs(t *testing.T) {
|
||||
func testAGivenPortIsUsedEverywhereThePortIs(t *testing.T) {
|
||||
given := map[string]map[int]int{"postgres": {5432: 5433}, "lavinmq": {15672: 15673}}
|
||||
for _, adopted := range []bool{true, false} {
|
||||
with := anchorRendering(adopted)
|
||||
@@ -301,7 +301,7 @@ func TestAGivenPortIsUsedEverywhereThePortIs(t *testing.T) {
|
||||
// module publishes that the filter admits from the private network only, and the ports its
|
||||
// manifest guards. A module assigned but not taken is not guarded: its port may still be the
|
||||
// predecessor's.
|
||||
func TestTheGuardIsDerivedFromTakenModulesOnly(t *testing.T) {
|
||||
func testTheGuardIsDerivedFromTakenModulesOnly(t *testing.T) {
|
||||
guardOf := func(with mcat.Rendering) string {
|
||||
t.Helper()
|
||||
composed, err := Compose(anAdoptedAnchor(), with)
|
||||
@@ -351,7 +351,7 @@ func TestTheGuardIsDerivedFromTakenModulesOnly(t *testing.T) {
|
||||
|
||||
// novox/hq ADR 0038: only a published port is the mesh's to move. A module that binds the machine
|
||||
// itself listens where its software was told to, so giving it a machine port is refused.
|
||||
func TestAGivenPortIsRefusedForAPortNoContainerPublishes(t *testing.T) {
|
||||
func testAGivenPortIsRefusedForAPortNoContainerPublishes(t *testing.T) {
|
||||
onTheMachine := mcat.Manifest{Module: "daemon",
|
||||
Listens: []mcat.Listening{{Port: 9000, From: mcat.FromMesh}}, Guards: []int{9000}}
|
||||
layers := []mcat.Layer{{From: "node anchor",
|
||||
@@ -364,7 +364,7 @@ func TestAGivenPortIsRefusedForAPortNoContainerPublishes(t *testing.T) {
|
||||
|
||||
// novox/hq ADR 0103: a guarded port this node is told to open to everyone is opened, not guarded.
|
||||
// An opening from everywhere beside a guard dropping it is one statement refusing the other.
|
||||
func TestAGuardedPortOpenedToEveryoneIsNotGuarded(t *testing.T) {
|
||||
func testAGuardedPortOpenedToEveryoneIsNotGuarded(t *testing.T) {
|
||||
with := anchorRendering(true)
|
||||
with.Settings["postgres"] = []mcat.Layer{{From: "node anchor",
|
||||
Placement: map[string]any{mcat.ExposeSetting: map[string]any{"5432": mcat.FromEverywhere}}}}
|
||||
@@ -420,7 +420,7 @@ func portsAsThePlanWould(m mcat.Manifest, given map[int]int) map[int]int {
|
||||
|
||||
// novox/hq ADR 0100 and 0038: the machine side of a long-form mapping is a port the module
|
||||
// publishes, so a node may move it — and a module may name a mapping by either end.
|
||||
func TestAGivenPortNamesEitherEndOfWhatTheModulePublishes(t *testing.T) {
|
||||
func testAGivenPortNamesEitherEndOfWhatTheModulePublishes(t *testing.T) {
|
||||
forge := aForge()
|
||||
node := func(v any) []mcat.Layer {
|
||||
return []mcat.Layer{{From: "node anchor", Placement: map[string]any{mcat.PortsSetting: v}}}
|
||||
@@ -516,7 +516,7 @@ func TestAGivenPortNamesEitherEndOfWhatTheModulePublishes(t *testing.T) {
|
||||
// And the number reaches everything derived from it. The fault this is written against moved the
|
||||
// container's mapping alone: the filter opened the port the software had left, the adopted node's
|
||||
// opening named it too, the guard refused it, and a consumer was sent to it.
|
||||
func TestAGivenMachineSideReachesTheFilterTheOpeningAndTheConsumer(t *testing.T) {
|
||||
func testAGivenMachineSideReachesTheFilterTheOpeningAndTheConsumer(t *testing.T) {
|
||||
forge := aForge()
|
||||
given, err := GivenPorts(forge, []mcat.Layer{{From: "node anchor",
|
||||
Placement: map[string]any{mcat.PortsSetting: map[string]any{"2222": float64(222)}}}})
|
||||
@@ -587,7 +587,7 @@ func TestAGivenMachineSideReachesTheFilterTheOpeningAndTheConsumer(t *testing.T)
|
||||
// And the mapping itself moves under either name, because Rendering.Given is a map anybody
|
||||
// composing a declaration hands in: keyed by the machine side, which is what a module declaring
|
||||
// 2222 calls its port, only the outside moves and the container's own port stays as written.
|
||||
func TestAMappingIsMovedUnderEitherOfItsNames(t *testing.T) {
|
||||
func testAMappingIsMovedUnderEitherOfItsNames(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
written string
|
||||
given map[int]int
|
||||
@@ -608,7 +608,7 @@ func TestAMappingIsMovedUnderEitherOfItsNames(t *testing.T) {
|
||||
// The same on a node that was given nothing, which is where the derivation was never at fault:
|
||||
// a long-form mapping is published where the manifest put it, and an adopted node opens that port
|
||||
// on the forwarded path like any other. What broke it was the number reaching only the mapping.
|
||||
func TestALongFormPortIsOpenedWhereTheManifestPublishesIt(t *testing.T) {
|
||||
func testALongFormPortIsOpenedWhereTheManifestPublishesIt(t *testing.T) {
|
||||
forge := aForge()
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{forge}}
|
||||
composed, err := Compose(r, mcat.Rendering{
|
||||
@@ -627,3 +627,19 @@ func TestALongFormPortIsOpenedWhereTheManifestPublishesIt(t *testing.T) {
|
||||
t.Fatalf("no opening for the forge's published ssh port: %v", keys(got))
|
||||
}
|
||||
}
|
||||
|
||||
// TestAdoption runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestAdoption(t *testing.T) {
|
||||
t.Run("AnAdoptedNodeIsDeclaredOpeningsFromTheSameInputsAsTheFilter", testAnAdoptedNodeIsDeclaredOpeningsFromTheSameInputsAsTheFilter)
|
||||
t.Run("AnAdoptedNodeLoadsNoFilterOfTheMeshs", testAnAdoptedNodeLoadsNoFilterOfTheMeshs)
|
||||
t.Run("AConvergedNodeIsDeclaredItsFilterAndNoOpenings", testAConvergedNodeIsDeclaredItsFilterAndNoOpenings)
|
||||
t.Run("TheGuardIsExactlyThisTable", testTheGuardIsExactlyThisTable)
|
||||
t.Run("AGivenPortIsUsedEverywhereThePortIs", testAGivenPortIsUsedEverywhereThePortIs)
|
||||
t.Run("TheGuardIsDerivedFromTakenModulesOnly", testTheGuardIsDerivedFromTakenModulesOnly)
|
||||
t.Run("AGivenPortIsRefusedForAPortNoContainerPublishes", testAGivenPortIsRefusedForAPortNoContainerPublishes)
|
||||
t.Run("AGuardedPortOpenedToEveryoneIsNotGuarded", testAGuardedPortOpenedToEveryoneIsNotGuarded)
|
||||
t.Run("AGivenPortNamesEitherEndOfWhatTheModulePublishes", testAGivenPortNamesEitherEndOfWhatTheModulePublishes)
|
||||
t.Run("AGivenMachineSideReachesTheFilterTheOpeningAndTheConsumer", testAGivenMachineSideReachesTheFilterTheOpeningAndTheConsumer)
|
||||
t.Run("AMappingIsMovedUnderEitherOfItsNames", testAMappingIsMovedUnderEitherOfItsNames)
|
||||
t.Run("ALongFormPortIsOpenedWhereTheManifestPublishesIt", testALongFormPortIsOpenedWhereTheManifestPublishesIt)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
func TestTheAgentAccountFactFallsBackToTheOperatorAndIsNeverRootOnlyWhenItsOwn(t *testing.T) {
|
||||
func testTheAgentAccountFactFallsBackToTheOperatorAndIsNeverRootOnlyWhenItsOwn(t *testing.T) {
|
||||
facts := machineFacts(mcat.Resolution{Node: "anchor", Account: "ops"}, nil, "")
|
||||
if facts["agent-account"] != "ops" || facts["agent-home"] != "/home/ops" || facts["agent-root"] != "" {
|
||||
t.Errorf("with no agent account named, agents run as the operator: %v", facts)
|
||||
@@ -40,7 +40,7 @@ const agentModule = `{"module": "agent", "version": "1", "resources": [
|
||||
"owner": "${machine:agent-account}"}
|
||||
]}`
|
||||
|
||||
func TestTheAgentAccountIsDeclaredNeverRootOnlyToAnEngineThatJudgesIt(t *testing.T) {
|
||||
func testTheAgentAccountIsDeclaredNeverRootOnlyToAnEngineThatJudgesIt(t *testing.T) {
|
||||
m, err := decodeForTest([]byte(agentModule))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -81,3 +81,9 @@ func TestTheAgentAccountIsDeclaredNeverRootOnlyToAnEngineThatJudgesIt(t *testing
|
||||
t.Errorf("with no agent account, the agent's directory is the operator's: %v", home)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAgentAccount runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestAgentAccount(t *testing.T) {
|
||||
t.Run("TheAgentAccountFactFallsBackToTheOperatorAndIsNeverRootOnlyWhenItsOwn", testTheAgentAccountFactFallsBackToTheOperatorAndIsNeverRootOnlyWhenItsOwn)
|
||||
t.Run("TheAgentAccountIsDeclaredNeverRootOnlyToAnEngineThatJudgesIt", testTheAgentAccountIsDeclaredNeverRootOnlyToAnEngineThatJudgesIt)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
var digest = "sha256:" + strings.Repeat("d", 64)
|
||||
|
||||
// **The address is composed into a declaration, and the record never carries it.**
|
||||
func TestAnImageTheMeshBuiltIsRoutedThroughTheStoreWhenDeclared(t *testing.T) {
|
||||
func testAnImageTheMeshBuiltIsRoutedThroughTheStoreWhenDeclared(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "gitea", Version: "1", Resources: []map[string]any{
|
||||
{"id": "server", "type": "container", "name": "mesh-gitea", "artifact": "server"},
|
||||
{"id": "config", "type": "archive", "path": "/etc/gitea", "artifact": "config"},
|
||||
@@ -95,7 +95,7 @@ func TestAnImageTheMeshBuiltIsRoutedThroughTheStoreWhenDeclared(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnImageInTheStoreWithNoStoreToFetchItFromIsRefused(t *testing.T) {
|
||||
func testAnImageInTheStoreWithNoStoreToFetchItFromIsRefused(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "gitea", Version: "1", Resources: []map[string]any{
|
||||
{"id": "server", "type": "container", "name": "mesh-gitea",
|
||||
"image": mcat.ArtifactStoreScheme + "gitea/server@" + digest},
|
||||
@@ -109,7 +109,7 @@ func TestAnImageInTheStoreWithNoStoreToFetchItFromIsRefused(t *testing.T) {
|
||||
// **A reference recorded with an address before this follows the store too** — when the mesh
|
||||
// built it. A module running an image straight from a public registry under its own name is left
|
||||
// exactly where it says: `quay.io/keycloak/keycloak` is not the mesh's, whatever it is called.
|
||||
func TestAReferenceRecordedWithAnAddressFollowsTheStoreWhenTheMeshBuiltIt(t *testing.T) {
|
||||
func testAReferenceRecordedWithAnAddressFollowsTheStoreWhenTheMeshBuiltIt(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "keycloak", Version: "1", Resources: []map[string]any{
|
||||
{"id": "server", "type": "container", "name": "mesh-keycloak",
|
||||
"image": "anchor.internal:5100/keycloak/server@" + digest},
|
||||
@@ -139,3 +139,10 @@ func TestAReferenceRecordedWithAnAddressFollowsTheStoreWhenTheMeshBuiltIt(t *tes
|
||||
t.Errorf("with no build record, a reference was rewritten: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestArtifacts runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestArtifacts(t *testing.T) {
|
||||
t.Run("AnImageTheMeshBuiltIsRoutedThroughTheStoreWhenDeclared", testAnImageTheMeshBuiltIsRoutedThroughTheStoreWhenDeclared)
|
||||
t.Run("AnImageInTheStoreWithNoStoreToFetchItFromIsRefused", testAnImageInTheStoreWithNoStoreToFetchItFromIsRefused)
|
||||
t.Run("AReferenceRecordedWithAnAddressFollowsTheStoreWhenTheMeshBuiltIt", testAReferenceRecordedWithAnAddressFollowsTheStoreWhenTheMeshBuiltIt)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func gammaLeftOut(with mcat.Rendering) mcat.Rendering {
|
||||
return with
|
||||
}
|
||||
|
||||
func TestTheBackupPlacementIsTheTextTheOldPlaceholdersRender(t *testing.T) {
|
||||
func testTheBackupPlacementIsTheTextTheOldPlaceholdersRender(t *testing.T) {
|
||||
// The old form is an unmoved holder: its placeholders are the controller's alone.
|
||||
oldHolder := strings.Replace(backupHolder, `"moved":true,`, "", 1)
|
||||
all := []mcat.Manifest{held(t, oldHolder, builtWith("restic", map[string]string{"backups": oldBackupText, "data": oldDataText}))}
|
||||
@@ -88,7 +88,7 @@ func TestTheBackupPlacementIsTheTextTheOldPlaceholdersRender(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnUnknownBackupKeyIsRefused(t *testing.T) {
|
||||
func testAnUnknownBackupKeyIsRefused(t *testing.T) {
|
||||
r := backupsOn(t, "${backup:rows}", placedDataTxt, backupModules...)
|
||||
if _, err := Compose(r, handingTo("store:5000")); err == nil || !strings.Contains(err.Error(), "backup:rows") {
|
||||
t.Errorf("handed, an unknown key is %v", err)
|
||||
@@ -112,3 +112,9 @@ func fileOf(t *testing.T, r mcat.Resolution, with mcat.Rendering, id string) str
|
||||
t.Fatalf("%s was not composed", id)
|
||||
return ""
|
||||
}
|
||||
|
||||
// TestBackupPlacement runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestBackupPlacement(t *testing.T) {
|
||||
t.Run("TheBackupPlacementIsTheTextTheOldPlaceholdersRender", testTheBackupPlacementIsTheTextTheOldPlaceholdersRender)
|
||||
t.Run("AnUnknownBackupKeyIsRefused", testAnUnknownBackupKeyIsRefused)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// Everything needed for one now reaches the file that needs it: the address and port from what the
|
||||
// provider serves, the name to present from what the mesh decided, the database name from what the
|
||||
// module itself contributed, and the password through the sealed hole the host fills.
|
||||
func TestAConsumerCanWriteAConnectionString(t *testing.T) {
|
||||
func testAConsumerCanWriteAConnectionString(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "workstation",
|
||||
Modules: []mcat.Manifest{{
|
||||
@@ -66,7 +66,7 @@ func TestAConsumerCanWriteAConnectionString(t *testing.T) {
|
||||
// provider is not published. Cross-node consumers already got this (the plan re-derives the served
|
||||
// facts with the provider's assignment); the same-node need was settled before the assignment and
|
||||
// carried the declared port until now.
|
||||
func TestASameNodeProviderIsAnnouncedAtThePortItIsPublishedOn(t *testing.T) {
|
||||
func testASameNodeProviderIsAnnouncedAtThePortItIsPublishedOn(t *testing.T) {
|
||||
provider := mcat.Manifest{
|
||||
Module: "postgres", Version: "1",
|
||||
Provides: mcat.FromAnywhere("postgres-database"),
|
||||
@@ -121,7 +121,7 @@ func TestASameNodeProviderIsAnnouncedAtThePortItIsPublishedOn(t *testing.T) {
|
||||
|
||||
// A port is 5432, not 5432.000000 — which is what a number decoded from JSON would write, and what
|
||||
// every connection string in the world would refuse.
|
||||
func TestAPortIsWrittenAsAPort(t *testing.T) {
|
||||
func testAPortIsWrittenAsAPort(t *testing.T) {
|
||||
if got := plainly(float64(5432)); got != "5432" {
|
||||
t.Errorf("a port was rendered as %q", got)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func TestAPortIsWrittenAsAPort(t *testing.T) {
|
||||
|
||||
// The name the provider will create is the name the consumer is told to present. One derivation,
|
||||
// so the two agree by construction rather than by two conventions written on the same day.
|
||||
func TestTheProviderAndTheConsumerAgreeOnTheName(t *testing.T) {
|
||||
func testTheProviderAndTheConsumerAgreeOnTheName(t *testing.T) {
|
||||
provider, err := Resolve(shelf(mcat.Manifest{
|
||||
Module: "postgres", Version: "1", Provides: mcat.FromAnywhere("postgres-database"),
|
||||
Grants: map[string]string{"postgres-database": "/var/lib/postgres/grants"},
|
||||
@@ -167,7 +167,7 @@ func TestTheProviderAndTheConsumerAgreeOnTheName(t *testing.T) {
|
||||
}
|
||||
|
||||
// A binding the module does not have is a typo, refused where it was written.
|
||||
func TestAFileCannotNameABindingTheModuleDoesNotHave(t *testing.T) {
|
||||
func testAFileCannotNameABindingTheModuleDoesNotHave(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "workstation",
|
||||
Modules: []mcat.Manifest{{
|
||||
@@ -190,7 +190,7 @@ func TestAFileCannotNameABindingTheModuleDoesNotHave(t *testing.T) {
|
||||
|
||||
// A key the provider does not serve is refused too. Written through, the literal placeholder
|
||||
// becomes a hostname, and the failure names neither the module nor the mesh.
|
||||
func TestAKeyTheProviderDoesNotServeIsRefused(t *testing.T) {
|
||||
func testAKeyTheProviderDoesNotServeIsRefused(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "workstation",
|
||||
Modules: []mcat.Manifest{{
|
||||
@@ -217,7 +217,7 @@ func TestAKeyTheProviderDoesNotServeIsRefused(t *testing.T) {
|
||||
// A machine's resolver configuration must name its resolver by address — it cannot resolve the name
|
||||
// of the thing it resolves names with (novox/hq ADR 0194). So a binding offers the providing
|
||||
// machine's private address beside its name, and only when the machine has one.
|
||||
func TestABindingOffersTheProvidersAddress(t *testing.T) {
|
||||
func testABindingOffersTheProvidersAddress(t *testing.T) {
|
||||
consumer := func() mcat.Resolution {
|
||||
return mcat.Resolution{
|
||||
Node: "workstation",
|
||||
@@ -244,3 +244,14 @@ func TestABindingOffersTheProvidersAddress(t *testing.T) {
|
||||
t.Fatal("a file naming an address the mesh does not have was composed")
|
||||
}
|
||||
}
|
||||
|
||||
// TestBoundIntoFiles runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestBoundIntoFiles(t *testing.T) {
|
||||
t.Run("AConsumerCanWriteAConnectionString", testAConsumerCanWriteAConnectionString)
|
||||
t.Run("ASameNodeProviderIsAnnouncedAtThePortItIsPublishedOn", testASameNodeProviderIsAnnouncedAtThePortItIsPublishedOn)
|
||||
t.Run("APortIsWrittenAsAPort", testAPortIsWrittenAsAPort)
|
||||
t.Run("TheProviderAndTheConsumerAgreeOnTheName", testTheProviderAndTheConsumerAgreeOnTheName)
|
||||
t.Run("AFileCannotNameABindingTheModuleDoesNotHave", testAFileCannotNameABindingTheModuleDoesNotHave)
|
||||
t.Run("AKeyTheProviderDoesNotServeIsRefused", testAKeyTheProviderDoesNotServeIsRefused)
|
||||
t.Run("ABindingOffersTheProvidersAddress", testABindingOffersTheProvidersAddress)
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func boundFrom(t *testing.T, r mcat.Resolution, consumer, provision string) mcat
|
||||
return mcat.Needed{}
|
||||
}
|
||||
|
||||
func TestTheIncidentAMachinesOwnStoreKeepsItsConsumersWhenTheSeatIsHeldElsewhere(t *testing.T) {
|
||||
func testTheIncidentAMachinesOwnStoreKeepsItsConsumersWhenTheSeatIsHeldElsewhere(t *testing.T) {
|
||||
got, err := Resolve(storeMesh(), homeAssigned(), home, storeWorld())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -84,7 +84,7 @@ func TestTheIncidentAMachinesOwnStoreKeepsItsConsumersWhenTheSeatIsHeldElsewhere
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheIncidentWithEveryConsumerOnRecordStillMovesNothing(t *testing.T) {
|
||||
func testTheIncidentWithEveryConsumerOnRecordStillMovesNothing(t *testing.T) {
|
||||
w := storeWorld()
|
||||
w.Bound = map[string]map[string]mcat.Chosen{}
|
||||
for _, c := range incidentConsumers {
|
||||
@@ -104,7 +104,7 @@ func TestTheIncidentWithEveryConsumerOnRecordStillMovesNothing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPinElsewhereStillMovesAStoresConsumers(t *testing.T) {
|
||||
func testAPinElsewhereStillMovesAStoresConsumers(t *testing.T) {
|
||||
w := storeWorld()
|
||||
w.Pinned = map[string]mcat.Chosen{"postgres-database": {Node: "anchor", Module: "store"}}
|
||||
w.Bound = map[string]map[string]mcat.Chosen{"board": {"postgres-database": {Node: "home", Module: "store"}}}
|
||||
@@ -131,7 +131,7 @@ func laptopWorld(holder string) mcat.World {
|
||||
|
||||
var laptop = mcat.Node{Name: "laptop", At: "laptop.internal"}
|
||||
|
||||
func TestABoundConsumerStaysWhenTheSeatsHolderChanges(t *testing.T) {
|
||||
func testABoundConsumerStaysWhenTheSeatsHolderChanges(t *testing.T) {
|
||||
w := laptopWorld("home")
|
||||
w.Bound = map[string]map[string]mcat.Chosen{"board": {"postgres-database": {Node: "anchor", Module: "store"}}}
|
||||
got, err := Resolve(storeMesh(), []string{"board"}, laptop, w)
|
||||
@@ -166,7 +166,7 @@ func TestABoundConsumerStaysWhenTheSeatsHolderChanges(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestABoundConsumerWhoseProviderIsGoneIsRefusedNotMoved(t *testing.T) {
|
||||
func testABoundConsumerWhoseProviderIsGoneIsRefusedNotMoved(t *testing.T) {
|
||||
w := laptopWorld("anchor")
|
||||
w.Offered["postgres-database"] = w.Offered["postgres-database"][:1] // only anchor's store is left
|
||||
w.Bound = map[string]map[string]mcat.Chosen{"board": {"postgres-database": {Node: "home", Module: "store"}}}
|
||||
@@ -182,7 +182,7 @@ func TestABoundConsumerWhoseProviderIsGoneIsRefusedNotMoved(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAMachinesOwnStoreUnassignedRefusesItsBoundConsumers(t *testing.T) {
|
||||
func testAMachinesOwnStoreUnassignedRefusesItsBoundConsumers(t *testing.T) {
|
||||
w := storeWorld()
|
||||
w.Bound = map[string]map[string]mcat.Chosen{"board": {"postgres-database": {Node: "home", Module: "store"}}}
|
||||
_, err := Resolve(storeMesh(), []string{"board"}, home, w)
|
||||
@@ -192,7 +192,7 @@ func TestAMachinesOwnStoreUnassignedRefusesItsBoundConsumers(t *testing.T) {
|
||||
}
|
||||
|
||||
// The first pass asks only what a machine offers, and is never refused by a binding.
|
||||
func TestTheFirstPassKeepsNoBinding(t *testing.T) {
|
||||
func testTheFirstPassKeepsNoBinding(t *testing.T) {
|
||||
w := storeWorld()
|
||||
w.Unchecked = true
|
||||
w.Bound = map[string]map[string]mcat.Chosen{"board": {"postgres-database": {Node: "gone", Module: "store"}}}
|
||||
@@ -203,7 +203,7 @@ func TestTheFirstPassKeepsNoBinding(t *testing.T) {
|
||||
|
||||
// An offer saying it keeps nothing is answered by the seat's holder as the resolver is, even where it
|
||||
// grants a credential.
|
||||
func TestAStoreSayingItKeepsNothingFollowsTheSeat(t *testing.T) {
|
||||
func testAStoreSayingItKeepsNothingFollowsTheSeat(t *testing.T) {
|
||||
shelf := storeMesh()
|
||||
no := false
|
||||
s := shelf["store"]
|
||||
@@ -217,3 +217,15 @@ func TestAStoreSayingItKeepsNothingFollowsTheSeat(t *testing.T) {
|
||||
t.Errorf("bound to %s; it keeps nothing, and the seat is held on anchor", n.From)
|
||||
}
|
||||
}
|
||||
|
||||
// TestBound runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestBound(t *testing.T) {
|
||||
t.Run("TheIncidentAMachinesOwnStoreKeepsItsConsumersWhenTheSeatIsHeldElsewhere", testTheIncidentAMachinesOwnStoreKeepsItsConsumersWhenTheSeatIsHeldElsewhere)
|
||||
t.Run("TheIncidentWithEveryConsumerOnRecordStillMovesNothing", testTheIncidentWithEveryConsumerOnRecordStillMovesNothing)
|
||||
t.Run("APinElsewhereStillMovesAStoresConsumers", testAPinElsewhereStillMovesAStoresConsumers)
|
||||
t.Run("ABoundConsumerStaysWhenTheSeatsHolderChanges", testABoundConsumerStaysWhenTheSeatsHolderChanges)
|
||||
t.Run("ABoundConsumerWhoseProviderIsGoneIsRefusedNotMoved", testABoundConsumerWhoseProviderIsGoneIsRefusedNotMoved)
|
||||
t.Run("AMachinesOwnStoreUnassignedRefusesItsBoundConsumers", testAMachinesOwnStoreUnassignedRefusesItsBoundConsumers)
|
||||
t.Run("TheFirstPassKeepsNoBinding", testTheFirstPassKeepsNoBinding)
|
||||
t.Run("AStoreSayingItKeepsNothingFollowsTheSeat", testAStoreSayingItKeepsNothingFollowsTheSeat)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// and the property that matters is that a second one anywhere is refused *when it is assigned*,
|
||||
// not discovered later as two servers holding different halves of the mesh's traffic. A second
|
||||
// bus is not a degraded mesh; it is two meshes that both believe they are the one.
|
||||
func TestASecondMeshBusAnywhereIsRefusedByName(t *testing.T) {
|
||||
func testASecondMeshBusAnywhereIsRefusedByName(t *testing.T) {
|
||||
nats := catalogueManifest(t, "nats")
|
||||
|
||||
if _, err := Resolve(shelf(nats), []string{"nats"}, workstation(), mcat.World{}); err != nil {
|
||||
@@ -37,7 +37,7 @@ func TestASecondMeshBusAnywhereIsRefusedByName(t *testing.T) {
|
||||
// The seat is the server's role, not the product's name (novox/hq ADR 0079). A different
|
||||
// implementation of the bus claims the same seat, and the mesh refuses it for the same reason —
|
||||
// which is the property that lets the bus be replaced at all.
|
||||
func TestTheSeatRefusesADifferentBusToo(t *testing.T) {
|
||||
func testTheSeatRefusesADifferentBusToo(t *testing.T) {
|
||||
nats := catalogueManifest(t, "nats")
|
||||
held := mcat.World{Held: []mcat.Held{{Claim: "mesh-broker", Scope: mcat.ScopeMesh,
|
||||
Node: "anchor", Module: "some-other-broker"}}}
|
||||
@@ -47,3 +47,9 @@ func TestTheSeatRefusesADifferentBusToo(t *testing.T) {
|
||||
t.Fatal("the seat admitted a second holder because the module's name differed")
|
||||
}
|
||||
}
|
||||
|
||||
// TestBrokerSeat runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestBrokerSeat(t *testing.T) {
|
||||
t.Run("ASecondMeshBusAnywhereIsRefusedByName", testASecondMeshBusAnywhereIsRefusedByName)
|
||||
t.Run("TheSeatRefusesADifferentBusToo", testTheSeatRefusesADifferentBusToo)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func brokeredShelf() map[string]mcat.Manifest {
|
||||
return shelf(mcat.Manifest{Module: "postgres", Version: "1", Provides: mcat.FromAnywhere("postgres-database")}, mcat.Manifest{Module: "meshboard", Version: "1", Requires: []string{"postgres-database"}})
|
||||
}
|
||||
|
||||
func TestADatabaseIsNotInstalledOnEveryMachineThatUsesOne(t *testing.T) {
|
||||
func testADatabaseIsNotInstalledOnEveryMachineThatUsesOne(t *testing.T) {
|
||||
// The fault this whole distinction exists for.
|
||||
got, err := Resolve(brokeredShelf(), []string{"meshboard"}, reachable(), mcat.World{Offered: onNetwork("anchor")})
|
||||
if err != nil {
|
||||
@@ -40,7 +40,7 @@ func TestADatabaseIsNotInstalledOnEveryMachineThatUsesOne(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhatAMachineTakesFromElsewhereIsRecorded(t *testing.T) {
|
||||
func testWhatAMachineTakesFromElsewhereIsRecorded(t *testing.T) {
|
||||
// It is the only part of a node's set that stops working when a *different* machine goes
|
||||
// away, and it is where a credential will have to be handed back.
|
||||
got, err := Resolve(brokeredShelf(), []string{"meshboard"}, reachable(), mcat.World{Offered: onNetwork("anchor")})
|
||||
@@ -58,7 +58,7 @@ func TestWhatAMachineTakesFromElsewhereIsRecorded(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNothingInTheMeshProvidingItIsRefusedWithSomewhereToPutIt(t *testing.T) {
|
||||
func testNothingInTheMeshProvidingItIsRefusedWithSomewhereToPutIt(t *testing.T) {
|
||||
// Refused rather than installed here. Choosing a machine to put a database on is a decision
|
||||
// with consequences, and nothing resolving a web application should make it silently.
|
||||
_, err := Resolve(brokeredShelf(), []string{"meshboard"}, workstation(), mcat.World{})
|
||||
@@ -70,7 +70,7 @@ func TestNothingInTheMeshProvidingItIsRefusedWithSomewhereToPutIt(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoNodesProvidingItIsRefusedRatherThanPicked(t *testing.T) {
|
||||
func testTwoNodesProvidingItIsRefusedRatherThanPicked(t *testing.T) {
|
||||
// Same rule as everywhere else. Picking one would be a guess about which database a person
|
||||
// meant, and the wrong guess is somebody's data in the wrong place.
|
||||
_, err := Resolve(brokeredShelf(), []string{"meshboard"}, reachable(), mcat.World{Offered: onNetwork("anchor", "archive")})
|
||||
@@ -84,7 +84,7 @@ func TestTwoNodesProvidingItIsRefusedRatherThanPicked(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSayingWhichOneSettlesIt(t *testing.T) {
|
||||
func testSayingWhichOneSettlesIt(t *testing.T) {
|
||||
got, err := Resolve(brokeredShelf(), []string{"meshboard"}, reachable(), mcat.World{
|
||||
Offered: onNetwork("anchor", "archive"),
|
||||
Pinned: map[string]mcat.Chosen{"postgres-database": {Node: "archive", Module: "postgres"}},
|
||||
@@ -97,7 +97,7 @@ func TestSayingWhichOneSettlesIt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeingPointedAtAMachineThatDoesNotProvideItIsRefused(t *testing.T) {
|
||||
func testBeingPointedAtAMachineThatDoesNotProvideItIsRefused(t *testing.T) {
|
||||
// Rather than falling back to one that does. A fallback would quietly move somebody's data to
|
||||
// a machine they did not choose, which is the whole reason the question is asked.
|
||||
_, err := Resolve(brokeredShelf(), []string{"meshboard"}, reachable(), mcat.World{
|
||||
@@ -112,7 +112,7 @@ func TestBeingPointedAtAMachineThatDoesNotProvideItIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneProviderDoesNotOverruleAChoice(t *testing.T) {
|
||||
func testOneProviderDoesNotOverruleAChoice(t *testing.T) {
|
||||
// A single answer is normally taken silently. Not when somebody said they wanted a different
|
||||
// one -- that is the mesh overruling a person, which it does nowhere else.
|
||||
_, err := Resolve(brokeredShelf(), []string{"meshboard"}, reachable(), mcat.World{
|
||||
@@ -127,7 +127,7 @@ func TestOneProviderDoesNotOverruleAChoice(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestACatalogueThatDisagreesAboutScopeIsRefused(t *testing.T) {
|
||||
func testACatalogueThatDisagreesAboutScopeIsRefused(t *testing.T) {
|
||||
// If one module says a database is local and another says it is anywhere, the same
|
||||
// requirement means two things depending on which one happens to answer it.
|
||||
_, err := Resolve(shelf(mcat.Manifest{Module: "postgres", Version: "1", Provides: mcat.FromAnywhere("postgres-database")}, mcat.Manifest{Module: "sqlite", Version: "1", Provides: mcat.Offers("postgres-database")}, mcat.Manifest{Module: "meshboard", Version: "1", Requires: []string{"postgres-database"}}), []string{"meshboard"}, workstation(), mcat.World{})
|
||||
@@ -139,7 +139,7 @@ func TestACatalogueThatDisagreesAboutScopeIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestALocalRequirementIsStillAnsweredLocally(t *testing.T) {
|
||||
func testALocalRequirementIsStillAnsweredLocally(t *testing.T) {
|
||||
// The change must not have made everything brokered. A shell is still installed here.
|
||||
got, err := Resolve(shelf(mcat.Manifest{Module: "zsh", Version: "1", Provides: mcat.Offers("shell")}, mcat.Manifest{Module: "tools", Version: "1", Requires: []string{"shell"}}), []string{"tools"}, workstation(), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -173,7 +173,7 @@ func binding(t *testing.T, out []map[string]any) map[string]any {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestAnAppIsToldWhereItsDatabaseIs(t *testing.T) {
|
||||
func testAnAppIsToldWhereItsDatabaseIs(t *testing.T) {
|
||||
// Knowing it needs the anchor's database is useless to the program that needs it unless the
|
||||
// program is told. This is the whole point of the field.
|
||||
got, err := Resolve(boundShelf(), []string{"meshboard"}, reachable(), mcat.World{Offered: map[string][]mcat.Provider{"postgres-database": {{Node: "anchor", At: "anchor.internal",
|
||||
@@ -191,7 +191,7 @@ func TestAnAppIsToldWhereItsDatabaseIs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestItSaysWhereTheCredentialIsInstead(t *testing.T) {
|
||||
func testItSaysWhereTheCredentialIsInstead(t *testing.T) {
|
||||
// A missing field looks like a bug; a stated absence looks like a boundary. Somebody wiring
|
||||
// this up must not spend an afternoon looking for the password field.
|
||||
//
|
||||
@@ -211,7 +211,7 @@ func TestItSaysWhereTheCredentialIsInstead(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoMachinesThatCannotReachEachOtherAreRefused(t *testing.T) {
|
||||
func testTwoMachinesThatCannotReachEachOtherAreRefused(t *testing.T) {
|
||||
// An app on one machine and a database on another that share no private network is a mesh
|
||||
// that reports itself configured and does not work. Said here rather than discovered as a
|
||||
// connection timing out.
|
||||
@@ -228,7 +228,7 @@ func TestTwoMachinesThatCannotReachEachOtherAreRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheProviderBeingOffTheNetworkIsAlsoRefused(t *testing.T) {
|
||||
func testTheProviderBeingOffTheNetworkIsAlsoRefused(t *testing.T) {
|
||||
// Both directions, because the failure is identical from either end and the remedy differs.
|
||||
_, err := Resolve(boundShelf(), []string{"meshboard"}, reachable(), mcat.World{Offered: map[string][]mcat.Provider{"postgres-database": {{Node: "anchor"}}}})
|
||||
if err == nil {
|
||||
@@ -239,7 +239,7 @@ func TestTheProviderBeingOffTheNetworkIsAlsoRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBindingSomethingAnsweredHereWritesNothing(t *testing.T) {
|
||||
func testBindingSomethingAnsweredHereWritesNothing(t *testing.T) {
|
||||
// A file saying "it is on this node" is a fact nobody needs and one more thing to keep true.
|
||||
got, err := Resolve(shelf(mcat.Manifest{Module: "zsh", Version: "1", Provides: mcat.Offers("shell")}, mcat.Manifest{Module: "tools", Version: "1", Requires: []string{"shell"},
|
||||
Binds: map[string]string{"shell": "/etc/tools/shell.json"}},
|
||||
@@ -253,3 +253,21 @@ func TestBindingSomethingAnsweredHereWritesNothing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestBrokered runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestBrokered(t *testing.T) {
|
||||
t.Run("ADatabaseIsNotInstalledOnEveryMachineThatUsesOne", testADatabaseIsNotInstalledOnEveryMachineThatUsesOne)
|
||||
t.Run("WhatAMachineTakesFromElsewhereIsRecorded", testWhatAMachineTakesFromElsewhereIsRecorded)
|
||||
t.Run("NothingInTheMeshProvidingItIsRefusedWithSomewhereToPutIt", testNothingInTheMeshProvidingItIsRefusedWithSomewhereToPutIt)
|
||||
t.Run("TwoNodesProvidingItIsRefusedRatherThanPicked", testTwoNodesProvidingItIsRefusedRatherThanPicked)
|
||||
t.Run("SayingWhichOneSettlesIt", testSayingWhichOneSettlesIt)
|
||||
t.Run("BeingPointedAtAMachineThatDoesNotProvideItIsRefused", testBeingPointedAtAMachineThatDoesNotProvideItIsRefused)
|
||||
t.Run("OneProviderDoesNotOverruleAChoice", testOneProviderDoesNotOverruleAChoice)
|
||||
t.Run("ACatalogueThatDisagreesAboutScopeIsRefused", testACatalogueThatDisagreesAboutScopeIsRefused)
|
||||
t.Run("ALocalRequirementIsStillAnsweredLocally", testALocalRequirementIsStillAnsweredLocally)
|
||||
t.Run("AnAppIsToldWhereItsDatabaseIs", testAnAppIsToldWhereItsDatabaseIs)
|
||||
t.Run("ItSaysWhereTheCredentialIsInstead", testItSaysWhereTheCredentialIsInstead)
|
||||
t.Run("TwoMachinesThatCannotReachEachOtherAreRefused", testTwoMachinesThatCannotReachEachOtherAreRefused)
|
||||
t.Run("TheProviderBeingOffTheNetworkIsAlsoRefused", testTheProviderBeingOffTheNetworkIsAlsoRefused)
|
||||
t.Run("BindingSomethingAnsweredHereWritesNothing", testBindingSomethingAnsweredHereWritesNothing)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func sharesOf(t *testing.T, values map[string]any) string {
|
||||
const sortedSharesJSON = `[{"methods":["get","put"],"to":"print-and-scan"},{"methods":["put"],"to":"seat:node-files"}]`
|
||||
|
||||
// 1591/AC3: the values a consumer gives carry the shares sorted by `to`, remote (grant) and co-located alike.
|
||||
func TestTheGrantCarriesTheSharesSorted(t *testing.T) {
|
||||
func testTheGrantCarriesTheSharesSorted(t *testing.T) {
|
||||
m := mustParse(t, filesWithShares)
|
||||
remote := mcat.Resolution{Node: "laptop", Modules: []mcat.Manifest{m}}
|
||||
values, asks, err := ContributionsFrom(remote, "s3-bucket", "files", mcat.SettingsBy{})
|
||||
@@ -88,7 +88,7 @@ func TestTheGrantCarriesTheSharesSorted(t *testing.T) {
|
||||
}
|
||||
|
||||
// 1591/AC5: a consumer whose contributes to s3-bucket names `shares` itself is refused.
|
||||
func TestAConsumerCannotContributeSharesItself(t *testing.T) {
|
||||
func testAConsumerCannotContributeSharesItself(t *testing.T) {
|
||||
_, err := decodeForTest([]byte(`{"module":"files","version":"1",
|
||||
"contributes":{"s3-bucket":{"shares":"x"}},
|
||||
"requires":[{"name":"s3-bucket","shares":[{"to":"a","methods":["get"]}]}]}`))
|
||||
@@ -103,3 +103,9 @@ func TestAConsumerCannotContributeSharesItself(t *testing.T) {
|
||||
t.Error("a contributed `shares` reached the grant")
|
||||
}
|
||||
}
|
||||
|
||||
// TestBucketShares runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestBucketShares(t *testing.T) {
|
||||
t.Run("TheGrantCarriesTheSharesSorted", testTheGrantCarriesTheSharesSorted)
|
||||
t.Run("AConsumerCannotContributeSharesItself", testAConsumerCannotContributeSharesItself)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func routeProxy() mcat.Manifest {
|
||||
//
|
||||
// The consequence is silent and total: route-proxy wrote an empty CA bundle, fell back to the
|
||||
// system trust store, could not verify the internal authority, and no certificate was ever issued.
|
||||
func TestACoLocatedProvidersServedValuesReachItsConsumer(t *testing.T) {
|
||||
func testACoLocatedProvidersServedValuesReachItsConsumer(t *testing.T) {
|
||||
r, err := Resolve(shelf(stepCAWithItsRoot(), routeProxy()),
|
||||
[]string{"step-ca", "route-proxy"}, reachable(), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -105,7 +105,7 @@ func TestACoLocatedProvidersServedValuesReachItsConsumer(t *testing.T) {
|
||||
|
||||
// And the binding file says the same thing, for a consumer that reads the binding rather than a
|
||||
// substituted placeholder. The two are one fact and must not be able to disagree.
|
||||
func TestACoLocatedConsumersBindingCarriesTheSettledValues(t *testing.T) {
|
||||
func testACoLocatedConsumersBindingCarriesTheSettledValues(t *testing.T) {
|
||||
r, err := Resolve(shelf(stepCAWithItsRoot(), routeProxy()),
|
||||
[]string{"step-ca", "route-proxy"}, reachable(), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -147,7 +147,7 @@ func TestACoLocatedConsumersBindingCarriesTheSettledValues(t *testing.T) {
|
||||
// the time the requirement came up — so which path a co-located binding took depended on the order
|
||||
// a person happened to assign things in. Settling after the closure is known removes that: both
|
||||
// orders now produce the same file.
|
||||
func TestACoLocatedProviderIsSettledWhicheverWayItWasPulledIn(t *testing.T) {
|
||||
func testACoLocatedProviderIsSettledWhicheverWayItWasPulledIn(t *testing.T) {
|
||||
for _, assigned := range [][]string{
|
||||
{"step-ca", "route-proxy"},
|
||||
{"route-proxy", "step-ca"},
|
||||
@@ -178,7 +178,7 @@ func TestACoLocatedProviderIsSettledWhicheverWayItWasPulledIn(t *testing.T) {
|
||||
//
|
||||
// The redirect uses the CONTRIBUTING module's assignment: the port belongs to the workload, and
|
||||
// using the provider's map would move it to wherever the proxy happens to be published.
|
||||
func TestASameNodeContributionNamesThePortTheMachinePublishes(t *testing.T) {
|
||||
func testASameNodeContributionNamesThePortTheMachinePublishes(t *testing.T) {
|
||||
gitea := mcat.Manifest{
|
||||
Module: "gitea", Version: "1",
|
||||
Listens: []mcat.Listening{{Port: 3000, Protocol: "tcp", From: mcat.FromMesh}},
|
||||
@@ -232,7 +232,7 @@ func TestASameNodeContributionNamesThePortTheMachinePublishes(t *testing.T) {
|
||||
// Its port belongs to that machine's assignment, which this node's map knows nothing about —
|
||||
// applying this node's map to it would move a remote workload's port to wherever a local module of
|
||||
// the same name happens to be published, which is worse than the fault being fixed.
|
||||
func TestAContributionFromAnotherMachineKeepsItsOwnPort(t *testing.T) {
|
||||
func testAContributionFromAnotherMachineKeepsItsOwnPort(t *testing.T) {
|
||||
r, err := Resolve(shelf(routeProxy(), stepCA()),
|
||||
[]string{"route-proxy", "step-ca"}, reachable(), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -270,7 +270,7 @@ func TestAContributionFromAnotherMachineKeepsItsOwnPort(t *testing.T) {
|
||||
// consumer's declared port until the CONSUMER's machine's assignments are applied to it. The
|
||||
// declaration layer cannot do it — those assignments are not this machine's, which is the line the
|
||||
// test above holds — so the grant layer is handed them and does it there.
|
||||
func TestAContributionIsRedirectedToWhereItsOwnMachinePublishedIt(t *testing.T) {
|
||||
func testAContributionIsRedirectedToWhereItsOwnMachinePublishedIt(t *testing.T) {
|
||||
published := map[int]int{3000: 20000}
|
||||
|
||||
got := AtPublishedPort(map[string]any{"name": "git.example.tld", "port": 3000}, "forge", published)
|
||||
@@ -304,3 +304,13 @@ func asStrings(v any) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// TestCoLocated runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestCoLocated(t *testing.T) {
|
||||
t.Run("ACoLocatedProvidersServedValuesReachItsConsumer", testACoLocatedProvidersServedValuesReachItsConsumer)
|
||||
t.Run("ACoLocatedConsumersBindingCarriesTheSettledValues", testACoLocatedConsumersBindingCarriesTheSettledValues)
|
||||
t.Run("ACoLocatedProviderIsSettledWhicheverWayItWasPulledIn", testACoLocatedProviderIsSettledWhicheverWayItWasPulledIn)
|
||||
t.Run("ASameNodeContributionNamesThePortTheMachinePublishes", testASameNodeContributionNamesThePortTheMachinePublishes)
|
||||
t.Run("AContributionFromAnotherMachineKeepsItsOwnPort", testAContributionFromAnotherMachineKeepsItsOwnPort)
|
||||
t.Run("AContributionIsRedirectedToWhereItsOwnMachinePublishedIt", testAContributionIsRedirectedToWhereItsOwnMachinePublishedIt)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func collectedBarsOn(t *testing.T, caps map[string]bool) mcat.Resolution {
|
||||
return r
|
||||
}
|
||||
|
||||
func TestACollectorMayNameTheBarsBlocksAsACollectionAndNoOtherDataKind(t *testing.T) {
|
||||
func testACollectorMayNameTheBarsBlocksAsACollectionAndNoOtherDataKind(t *testing.T) {
|
||||
bars := held(t, collectedBars, builtWith("bars", map[string]string{"bars": collectedBarsText}))
|
||||
if _, err := Compose(collectedBarsOn(t, nil), handingTo("store:5000")); err != nil {
|
||||
t.Fatalf("the handed collector is refused: %v", err)
|
||||
@@ -59,7 +59,7 @@ func TestACollectorMayNameTheBarsBlocksAsACollectionAndNoOtherDataKind(t *testin
|
||||
// composed before it, for a machine with neither capability, the battery, the power meter and both. Where the
|
||||
// collector is not handed the controller fills the files; where it is, it names the items for the client, which
|
||||
// fills the same files (mesh-catalog's provisioner client holds that half against the same golden files).
|
||||
func TestTheBarsOfTheCatalogueAreTheSameHandedOrNot(t *testing.T) {
|
||||
func testTheBarsOfTheCatalogueAreTheSameHandedOrNot(t *testing.T) {
|
||||
read := func(name string) string {
|
||||
b, err := os.ReadFile(filepath.Join("testdata", "bars", name))
|
||||
if err != nil {
|
||||
@@ -108,3 +108,9 @@ func TestTheBarsOfTheCatalogueAreTheSameHandedOrNot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestCollectionsBar runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestCollectionsBar(t *testing.T) {
|
||||
t.Run("ACollectorMayNameTheBarsBlocksAsACollectionAndNoOtherDataKind", testACollectorMayNameTheBarsBlocksAsACollectionAndNoOtherDataKind)
|
||||
t.Run("TheBarsOfTheCatalogueAreTheSameHandedOrNot", testTheBarsOfTheCatalogueAreTheSameHandedOrNot)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func computedShelf() map[string]mcat.Manifest {
|
||||
Provides: mcat.Offers("private-network")})
|
||||
}
|
||||
|
||||
func TestAComputedModuleIsAskedAboutTheNodeItIsFor(t *testing.T) {
|
||||
func testAComputedModuleIsAskedAboutTheNodeItIsFor(t *testing.T) {
|
||||
// The generator gets a node name, not a plan. Everything it needs is the whole mesh, which
|
||||
// it was built with — this is the one thing a node could never work out for itself.
|
||||
got, err := Resolve(computedShelf(), []string{"mesh-network"}, workstation(), mcat.World{})
|
||||
@@ -51,7 +51,7 @@ func TestAComputedModuleIsAskedAboutTheNodeItIsFor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAMachineNobodyGaveItGetsNothing(t *testing.T) {
|
||||
func testAMachineNobodyGaveItGetsNothing(t *testing.T) {
|
||||
// The whole point of making the network a module. Before this, every machine with an address
|
||||
// was on the private network and there was no way to say one should stay off.
|
||||
got, err := Resolve(computedShelf(), nil, workstation(), mcat.World{})
|
||||
@@ -71,7 +71,7 @@ func TestAMachineNobodyGaveItGetsNothing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignedAndNotYetPartOfItIsNotAFailure(t *testing.T) {
|
||||
func testAssignedAndNotYetPartOfItIsNotAFailure(t *testing.T) {
|
||||
// A machine given the network module before it has a place on it. Brief and ordinary — the
|
||||
// answer is "nothing yet", and treating it as an error would make an ordering a fault.
|
||||
got, _ := Resolve(computedShelf(), []string{"mesh-network"}, workstation(), mcat.World{})
|
||||
@@ -85,7 +85,7 @@ func TestAssignedAndNotYetPartOfItIsNotAFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAGeneratorThisControlPlaneDoesNotHaveIsRefused(t *testing.T) {
|
||||
func testAGeneratorThisControlPlaneDoesNotHaveIsRefused(t *testing.T) {
|
||||
// Sending a machine a module with no files would look like it worked. Named in the message,
|
||||
// because the only fix is a control plane that has it.
|
||||
got, _ := Resolve(shelf(mcat.Manifest{Module: "weather", Computed: "the-weather"}), []string{"weather"}, workstation(), mcat.World{})
|
||||
@@ -99,7 +99,7 @@ func TestAGeneratorThisControlPlaneDoesNotHaveIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSettingsApplyToAComputedModuleToo(t *testing.T) {
|
||||
func testSettingsApplyToAComputedModuleToo(t *testing.T) {
|
||||
// Being computed is about where the files come from, not about whether they are configurable.
|
||||
// A line drawn there would be arbitrary and nobody could predict it.
|
||||
got, _ := Resolve(computedShelf(), []string{"mesh-network"}, workstation(), mcat.World{})
|
||||
@@ -121,7 +121,7 @@ func TestSettingsApplyToAComputedModuleToo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoWaysToBeOnAPrivateNetworkRefuseAndNameBoth(t *testing.T) {
|
||||
func testTwoWaysToBeOnAPrivateNetworkRefuseAndNameBoth(t *testing.T) {
|
||||
// WireGuard is one way. The refusing rule is what makes a second one safe to add: assigning
|
||||
// both is caught rather than producing a machine on two networks that each half-work.
|
||||
_, err := Resolve(shelf(mcat.Manifest{Module: "mesh-network", Computed: "mesh-network",
|
||||
@@ -152,7 +152,7 @@ func (reloading) Resources(node string) ([]map[string]any, bool, error) {
|
||||
}, true, nil
|
||||
}
|
||||
|
||||
func TestWhatAServiceIsReloadedOnIsNamedAsTheHostWillSeeIt(t *testing.T) {
|
||||
func testWhatAServiceIsReloadedOnIsNamedAsTheHostWillSeeIt(t *testing.T) {
|
||||
// Ids are prefixed with their module on the way out. An unprefixed reload-on would name a
|
||||
// resource the host never sees, and the runtime would never be reloaded for its trust.
|
||||
got, err := Resolve(computedShelf(), []string{"mesh-network"}, workstation(), mcat.World{})
|
||||
@@ -182,3 +182,14 @@ func TestWhatAServiceIsReloadedOnIsNamedAsTheHostWillSeeIt(t *testing.T) {
|
||||
t.Errorf("reload-on names %v, the file is %v", service["reload-on"], file["id"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestComputed runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestComputed(t *testing.T) {
|
||||
t.Run("AComputedModuleIsAskedAboutTheNodeItIsFor", testAComputedModuleIsAskedAboutTheNodeItIsFor)
|
||||
t.Run("AMachineNobodyGaveItGetsNothing", testAMachineNobodyGaveItGetsNothing)
|
||||
t.Run("AssignedAndNotYetPartOfItIsNotAFailure", testAssignedAndNotYetPartOfItIsNotAFailure)
|
||||
t.Run("AGeneratorThisControlPlaneDoesNotHaveIsRefused", testAGeneratorThisControlPlaneDoesNotHaveIsRefused)
|
||||
t.Run("SettingsApplyToAComputedModuleToo", testSettingsApplyToAComputedModuleToo)
|
||||
t.Run("TwoWaysToBeOnAPrivateNetworkRefuseAndNameBoth", testTwoWaysToBeOnAPrivateNetworkRefuseAndNameBoth)
|
||||
t.Run("WhatAServiceIsReloadedOnIsNamedAsTheHostWillSeeIt", testWhatAServiceIsReloadedOnIsNamedAsTheHostWillSeeIt)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ const configDunst = `{"module": "dunst", "version": "1",
|
||||
|
||||
// ${config:<key>} fills exactly as ${setting:<key>} does: the module rewritten from settings to config composes
|
||||
// to the same bytes, with no layer, with the node's, and with the mesh's under the node's.
|
||||
func TestAModuleRewrittenFromSettingsToConfigComposesByteIdentically(t *testing.T) {
|
||||
func testAModuleRewrittenFromSettingsToConfigComposesByteIdentically(t *testing.T) {
|
||||
composed := func(manifest string, layers []mcat.Layer) []byte {
|
||||
t.Helper()
|
||||
m, err := decodeForTest([]byte(manifest))
|
||||
@@ -128,7 +128,7 @@ func TestAModuleRewrittenFromSettingsToConfigComposesByteIdentically(t *testing.
|
||||
|
||||
// A required value nothing sets is refused at composition in the config form's words: ${config:<key>} and the
|
||||
// config verb, never `settings set` (review of mesh-controller#320). The settings form's words are unchanged.
|
||||
func TestAnUnsetRequiredValueIsRefusedInTheConfigFormsWords(t *testing.T) {
|
||||
func testAnUnsetRequiredValueIsRefusedInTheConfigFormsWords(t *testing.T) {
|
||||
m, err := parseRaw(t, inConfigForm())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -179,3 +179,9 @@ func TestAnUnsetRequiredValueIsRefusedInTheConfigFormsWords(t *testing.T) {
|
||||
t.Fatalf("the settings form's refusal changed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestConfig runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestConfig(t *testing.T) {
|
||||
t.Run("AModuleRewrittenFromSettingsToConfigComposesByteIdentically", testAModuleRewrittenFromSettingsToConfigComposesByteIdentically)
|
||||
t.Run("AnUnsetRequiredValueIsRefusedInTheConfigFormsWords", testAnUnsetRequiredValueIsRefusedInTheConfigFormsWords)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func received(t *testing.T, out []map[string]any) []mcat.Contribution {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestTheFileTheProviderGetsIsMachineReadable(t *testing.T) {
|
||||
func testTheFileTheProviderGetsIsMachineReadable(t *testing.T) {
|
||||
// It is written for a program, and the first version put a `//` header above the JSON — a
|
||||
// file that says "do not edit" to a person and fails to parse for the thing meant to read it.
|
||||
got, _ := Resolve(shelf(proxy(), published("board", "board", 8080)), []string{"board"}, workstation(), mcat.World{})
|
||||
@@ -72,7 +72,7 @@ func TestTheFileTheProviderGetsIsMachineReadable(t *testing.T) {
|
||||
t.Fatal("no received file")
|
||||
}
|
||||
|
||||
func TestAModuleTellsItsProviderWhatItNeeds(t *testing.T) {
|
||||
func testAModuleTellsItsProviderWhatItNeeds(t *testing.T) {
|
||||
got, err := Resolve(shelf(proxy(), published("board", "board", 8080)), []string{"board"}, workstation(), mcat.World{})
|
||||
|
||||
if err != nil {
|
||||
@@ -91,7 +91,7 @@ func TestAModuleTellsItsProviderWhatItNeeds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContributingToSomethingIsRequiringIt(t *testing.T) {
|
||||
func testContributingToSomethingIsRequiringIt(t *testing.T) {
|
||||
// Asking to be published means a publisher must exist. A module that had to say both would
|
||||
// eventually say one, and the failure would be a machine where nothing serves the route.
|
||||
got, err := Resolve(shelf(proxy(), published("board", "board", 8080)), []string{"board"}, workstation(), mcat.World{})
|
||||
@@ -104,7 +104,7 @@ func TestContributingToSomethingIsRequiringIt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNothingToContributeToIsRefused(t *testing.T) {
|
||||
func testNothingToContributeToIsRefused(t *testing.T) {
|
||||
_, err := Resolve(shelf(published("board", "board", 8080)), []string{"board"}, workstation(), mcat.World{})
|
||||
|
||||
if err == nil {
|
||||
@@ -115,7 +115,7 @@ func TestNothingToContributeToIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEveryPublisherOnTheMachineIsInOneFile(t *testing.T) {
|
||||
func testEveryPublisherOnTheMachineIsInOneFile(t *testing.T) {
|
||||
got, err := Resolve(shelf(proxy(),
|
||||
published("board", "board", 8080),
|
||||
published("archive", "archive", 9000),
|
||||
@@ -135,7 +135,7 @@ func TestEveryPublisherOnTheMachineIsInOneFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAProviderWithNoConsumersStillGetsTheFile(t *testing.T) {
|
||||
func testAProviderWithNoConsumersStillGetsTheFile(t *testing.T) {
|
||||
// Empty rather than absent. A provider that finds no file cannot tell "nothing asked for me"
|
||||
// from "the mesh never wrote it", and those want completely different responses — the same
|
||||
// rule the host follows about a service that does not exist.
|
||||
@@ -148,7 +148,7 @@ func TestAProviderWithNoConsumersStillGetsTheFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheProviderCanReloadWhenTheRoutesChange(t *testing.T) {
|
||||
func testTheProviderCanReloadWhenTheRoutesChange(t *testing.T) {
|
||||
// A proxy that got a new route and did not reload is a route that silently does not work.
|
||||
// The same fault the private network had when a peer list changed under a running interface,
|
||||
// which is why the received file has a name a module can point at.
|
||||
@@ -171,7 +171,7 @@ func TestTheProviderCanReloadWhenTheRoutesChange(t *testing.T) {
|
||||
t.Fatal("no service in the declaration")
|
||||
}
|
||||
|
||||
func TestARouteCanBeSetPerMesh(t *testing.T) {
|
||||
func testARouteCanBeSetPerMesh(t *testing.T) {
|
||||
// The hostname is exactly the kind of thing that differs between one mesh and the next. A
|
||||
// module whose route could not be set would have to be edited to be reused anywhere.
|
||||
got, _ := Resolve(shelf(proxy(), published("board", "board", 8080)), []string{"board"}, workstation(), mcat.World{})
|
||||
@@ -191,7 +191,7 @@ func TestARouteCanBeSetPerMesh(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestASettingReachesAContributionOnlyWhereItDeclaresTheKey(t *testing.T) {
|
||||
func testASettingReachesAContributionOnlyWhereItDeclaresTheKey(t *testing.T) {
|
||||
// novox/hq 04-ISSUES/173: the mail module's site name, set so its environment file could read
|
||||
// it, arrived in every route it contributed. A setting overrides a key the contribution
|
||||
// declares and adds none — the provider reads the contribution as a contract.
|
||||
@@ -238,7 +238,7 @@ func grantedTo(t *testing.T, out []map[string]any) []mcat.Contribution {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestAConsumersOwnContributionsAreStillThere(t *testing.T) {
|
||||
func testAConsumersOwnContributionsAreStillThere(t *testing.T) {
|
||||
// Cross-node grants are merged in with this machine's own, because from the provider's side
|
||||
// they are the same thing — somebody wanting something — and a provider that had to read two
|
||||
// lists would read one of them.
|
||||
@@ -253,7 +253,7 @@ func TestAConsumersOwnContributionsAreStillThere(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestARequireOnlyConsumerOfAParameterlessProvisionStillAsks(t *testing.T) {
|
||||
func testARequireOnlyConsumerOfAParameterlessProvisionStillAsks(t *testing.T) {
|
||||
// A consumer that requires a parameterless provision (one whose serves names no consumer key —
|
||||
// redis-cache, amqp) contributes no payload, but it still ASKS for the provision and must be
|
||||
// granted a credential. Keying "asks" on contributions alone gave its grant From="" — read as
|
||||
@@ -277,7 +277,7 @@ func TestARequireOnlyConsumerOfAParameterlessProvisionStillAsks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAConsumerThatStoppedAskingIsWithdrawn(t *testing.T) {
|
||||
func testAConsumerThatStoppedAskingIsWithdrawn(t *testing.T) {
|
||||
// Withdrawal is how a credential is taken away. The provisioner removes what nobody asks for,
|
||||
// and it can only do that if the mesh stops asking — a consumer that was unassigned would
|
||||
// otherwise keep a working login for ever, and nothing would say so.
|
||||
@@ -309,3 +309,19 @@ func TestAConsumerThatStoppedAskingIsWithdrawn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestContributes runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestContributes(t *testing.T) {
|
||||
t.Run("TheFileTheProviderGetsIsMachineReadable", testTheFileTheProviderGetsIsMachineReadable)
|
||||
t.Run("AModuleTellsItsProviderWhatItNeeds", testAModuleTellsItsProviderWhatItNeeds)
|
||||
t.Run("ContributingToSomethingIsRequiringIt", testContributingToSomethingIsRequiringIt)
|
||||
t.Run("NothingToContributeToIsRefused", testNothingToContributeToIsRefused)
|
||||
t.Run("EveryPublisherOnTheMachineIsInOneFile", testEveryPublisherOnTheMachineIsInOneFile)
|
||||
t.Run("AProviderWithNoConsumersStillGetsTheFile", testAProviderWithNoConsumersStillGetsTheFile)
|
||||
t.Run("TheProviderCanReloadWhenTheRoutesChange", testTheProviderCanReloadWhenTheRoutesChange)
|
||||
t.Run("ARouteCanBeSetPerMesh", testARouteCanBeSetPerMesh)
|
||||
t.Run("ASettingReachesAContributionOnlyWhereItDeclaresTheKey", testASettingReachesAContributionOnlyWhereItDeclaresTheKey)
|
||||
t.Run("AConsumersOwnContributionsAreStillThere", testAConsumersOwnContributionsAreStillThere)
|
||||
t.Run("ARequireOnlyConsumerOfAParameterlessProvisionStillAsks", testARequireOnlyConsumerOfAParameterlessProvisionStillAsks)
|
||||
t.Run("AConsumerThatStoppedAskingIsWithdrawn", testAConsumerThatStoppedAskingIsWithdrawn)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
func TestAContributionDependsOnTheSeatThatPlacesIt(t *testing.T) {
|
||||
func testAContributionDependsOnTheSeatThatPlacesIt(t *testing.T) {
|
||||
env := mod("theme", nil, nil, nil)
|
||||
env.Environment = &mcat.Environment{Variables: map[string]string{"GTK_THEME": "Adwaita:dark"}}
|
||||
path := mod("toolchain", nil, nil, nil)
|
||||
@@ -43,7 +43,7 @@ func TestAContributionDependsOnTheSeatThatPlacesIt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAHolderMeetsItsOwnContribution(t *testing.T) {
|
||||
func testAHolderMeetsItsOwnContribution(t *testing.T) {
|
||||
// The display server's module contributes nothing to its own seat today, but the zsh module's
|
||||
// environment contributions do go to another seat: a claim meets only the seat it names.
|
||||
zsh := mod("zsh", nil, nil, nil, mcat.Claim{Name: mcat.LoginShellSeat})
|
||||
@@ -56,3 +56,9 @@ func TestAHolderMeetsItsOwnContribution(t *testing.T) {
|
||||
t.Errorf("zsh alone: unheld %v, want only %s (its shell code is its own seat's)", unheld, mcat.EnvironmentSeat)
|
||||
}
|
||||
}
|
||||
|
||||
// TestContributionDependencies runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestContributionDependencies(t *testing.T) {
|
||||
t.Run("AContributionDependsOnTheSeatThatPlacesIt", testAContributionDependsOnTheSeatThatPlacesIt)
|
||||
t.Run("AHolderMeetsItsOwnContribution", testAHolderMeetsItsOwnContribution)
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func pics() mcat.Manifest {
|
||||
|
||||
// The three places the derived value lands must agree, because agreeing is the whole point: the
|
||||
// consumer's own file, the binding it reads as JSON, and the provider's contributions entry.
|
||||
func TestADerivedValueReachesBothEndsAndAgrees(t *testing.T) {
|
||||
func testADerivedValueReachesBothEndsAndAgrees(t *testing.T) {
|
||||
r, err := Resolve(shelf(store(), files()), []string{"store", "files"}, reachable(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -122,7 +122,7 @@ func TestADerivedValueReachesBothEndsAndAgrees(t *testing.T) {
|
||||
}
|
||||
|
||||
// Two consumers of one provider on one machine get two buckets, and neither gets the other's.
|
||||
func TestTwoConsumersOfOneProviderGetTheirOwnDerivation(t *testing.T) {
|
||||
func testTwoConsumersOfOneProviderGetTheirOwnDerivation(t *testing.T) {
|
||||
r, err := Resolve(shelf(store(), files(), pics()),
|
||||
[]string{"store", "files", "pics"}, reachable(), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -160,7 +160,7 @@ func TestTwoConsumersOfOneProviderGetTheirOwnDerivation(t *testing.T) {
|
||||
// An operator may still set what the provider serves where its definition asks (${setting:…}), and
|
||||
// the mesh still derives the rest: the setting is filled first, then the consumer's half. (Until
|
||||
// novox/hq issue 696 the layer replaced the served bucket whole; a layer replaces no served key now.)
|
||||
func TestASettingComposesWithADerivedValue(t *testing.T) {
|
||||
func testASettingComposesWithADerivedValue(t *testing.T) {
|
||||
prefixed := store()
|
||||
prefixed.Serves["s3-bucket"]["bucket"] = "${setting:bucket-prefix}${consumer:as:dns}"
|
||||
r, err := Resolve(shelf(prefixed, files()), []string{"store", "files"}, reachable(), mcat.World{})
|
||||
@@ -186,7 +186,7 @@ func TestASettingComposesWithADerivedValue(t *testing.T) {
|
||||
}
|
||||
|
||||
// `dns` is checked against an identity the mesh actually mints, not an invented string.
|
||||
func TestTheDNSAlphabetIsTheMintedIdentityWithItsSeparatorRewritten(t *testing.T) {
|
||||
func testTheDNSAlphabetIsTheMintedIdentityWithItsSeparatorRewritten(t *testing.T) {
|
||||
as := mcat.ConsumerIdentity("anchor", mcat.IdentitySource("ncloud", "nextcloud"))
|
||||
if err := mcat.CheckIdentity("anchor", mcat.IdentitySource("ncloud", "nextcloud")); err != nil {
|
||||
t.Fatalf("the mesh would not mint this identity at all: %v", err)
|
||||
@@ -203,7 +203,7 @@ func TestTheDNSAlphabetIsTheMintedIdentityWithItsSeparatorRewritten(t *testing.T
|
||||
// The check that would have caught the one wrong instance: a consumer that writes the derived
|
||||
// value into its own definition instead of asking for it is refused, whether it transcribed the
|
||||
// right answer or a predecessor's.
|
||||
func TestAConsumerThatTranscribesWhatItsProviderDerivesIsRefused(t *testing.T) {
|
||||
func testAConsumerThatTranscribesWhatItsProviderDerivesIsRefused(t *testing.T) {
|
||||
as := mcat.ConsumerIdentity("workstation", mcat.IdentitySource("files", "files"))
|
||||
transcribed := strings.ReplaceAll(as, "_", "-")
|
||||
|
||||
@@ -278,7 +278,7 @@ func storeGrants(t *testing.T, out []map[string]any) []mcat.Contribution {
|
||||
//
|
||||
// Refused, loudly, at the one place that can see both halves. Lifting it means giving the
|
||||
// consumer's side a local dimension, which is a decision and not an omission.
|
||||
func TestAConsumerWithSeveralHoldersOfADerivingProviderIsRefused(t *testing.T) {
|
||||
func testAConsumerWithSeveralHoldersOfADerivingProviderIsRefused(t *testing.T) {
|
||||
m := files()
|
||||
// Two holders of the one provision, the shape ADR 0094 gives a module that keeps several.
|
||||
m.Secrets = nil
|
||||
@@ -310,3 +310,13 @@ func TestAConsumerWithSeveralHoldersOfADerivingProviderIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestDerivedForConsumer runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestDerivedForConsumer(t *testing.T) {
|
||||
t.Run("ADerivedValueReachesBothEndsAndAgrees", testADerivedValueReachesBothEndsAndAgrees)
|
||||
t.Run("TwoConsumersOfOneProviderGetTheirOwnDerivation", testTwoConsumersOfOneProviderGetTheirOwnDerivation)
|
||||
t.Run("ASettingComposesWithADerivedValue", testASettingComposesWithADerivedValue)
|
||||
t.Run("TheDNSAlphabetIsTheMintedIdentityWithItsSeparatorRewritten", testTheDNSAlphabetIsTheMintedIdentityWithItsSeparatorRewritten)
|
||||
t.Run("AConsumerThatTranscribesWhatItsProviderDerivesIsRefused", testAConsumerThatTranscribesWhatItsProviderDerivesIsRefused)
|
||||
t.Run("AConsumerWithSeveralHoldersOfADerivingProviderIsRefused", testAConsumerWithSeveralHoldersOfADerivingProviderIsRefused)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func placedModule() mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPathlessDirectoryResolvesUnderTheNodesRoot(t *testing.T) {
|
||||
func testAPathlessDirectoryResolvesUnderTheNodesRoot(t *testing.T) {
|
||||
m := placedModule()
|
||||
dirs := dirsFor(m, mcat.Rendering{})
|
||||
if dirs["data"] != "/var/lib/photos/data" {
|
||||
@@ -34,7 +34,7 @@ func TestAPathlessDirectoryResolvesUnderTheNodesRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDirReferencesBecomeThePlaceInEveryField(t *testing.T) {
|
||||
func testDirReferencesBecomeThePlaceInEveryField(t *testing.T) {
|
||||
m := placedModule()
|
||||
dirs := dirsFor(m, mcat.Rendering{})
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestDirReferencesBecomeThePlaceInEveryField(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAStatedPathIsThePlacementAndStillAnswersByName(t *testing.T) {
|
||||
func testAStatedPathIsThePlacementAndStillAnswersByName(t *testing.T) {
|
||||
m := placedModule()
|
||||
// The adopted-machine case: data that must sit where the predecessor already put it.
|
||||
m.Resources[0]["path"] = "/services/mssql/data/"
|
||||
@@ -89,7 +89,7 @@ func TestAStatedPathIsThePlacementAndStillAnswersByName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillingForOneNodeLeaksIntoNoOther(t *testing.T) {
|
||||
func testFillingForOneNodeLeaksIntoNoOther(t *testing.T) {
|
||||
m := placedModule()
|
||||
first := shallowCopy(m.Resources[2])
|
||||
if err := dirInto(first, dirsFor(m, mcat.Rendering{DataRoot: "/first"}), m.Module); err != nil {
|
||||
@@ -107,7 +107,7 @@ func TestFillingForOneNodeLeaksIntoNoOther(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAReferenceToNoDirectoryRefusesAtCompositionToo(t *testing.T) {
|
||||
func testAReferenceToNoDirectoryRefusesAtCompositionToo(t *testing.T) {
|
||||
m := placedModule()
|
||||
container := shallowCopy(m.Resources[2])
|
||||
container["env"] = map[string]any{"DATA": "${dir:date}"}
|
||||
@@ -117,7 +117,7 @@ func TestAReferenceToNoDirectoryRefusesAtCompositionToo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheAssignmentsOwnRootIsAPlace(t *testing.T) {
|
||||
func testTheAssignmentsOwnRootIsAPlace(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "mailu", Resources: []map[string]any{
|
||||
{"id": "state", "type": "directory", "place": ".", "mode": "0700"},
|
||||
{"id": "data-mail", "type": "directory"},
|
||||
@@ -141,7 +141,7 @@ func TestTheAssignmentsOwnRootIsAPlace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheManifestsMapsArePlaced(t *testing.T) {
|
||||
func testTheManifestsMapsArePlaced(t *testing.T) {
|
||||
m := mcat.Manifest{
|
||||
Module: "photos",
|
||||
Resources: []map[string]any{
|
||||
@@ -173,7 +173,7 @@ func TestTheManifestsMapsArePlaced(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheMeshsDirectoryForAModuleIsAPlace(t *testing.T) {
|
||||
func testTheMeshsDirectoryForAModuleIsAPlace(t *testing.T) {
|
||||
// novox/hq issue 174. What the mesh writes for a module — its bus credential, its bindings —
|
||||
// is the mesh's plumbing under <root>/mesh/<module>, and the definition names it by id.
|
||||
m := mcat.Manifest{Module: "umami",
|
||||
@@ -210,7 +210,7 @@ func TestTheMeshsDirectoryForAModuleIsAPlace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoModulesPlacedRootsAreNoCollision(t *testing.T) {
|
||||
func testTwoModulesPlacedRootsAreNoCollision(t *testing.T) {
|
||||
a := mcat.Manifest{Module: "gitea", Resources: []map[string]any{
|
||||
{"id": "state", "type": "directory", "place": "."},
|
||||
{"id": "env", "type": "file", "path": "${dir:state}/server.env", "content": ""},
|
||||
@@ -240,7 +240,7 @@ func shallowCopy(resource map[string]any) map[string]any {
|
||||
return copied
|
||||
}
|
||||
|
||||
func TestADirectoryBeneathAPlacedOneIsPlacedWithIt(t *testing.T) {
|
||||
func testADirectoryBeneathAPlacedOneIsPlacedWithIt(t *testing.T) {
|
||||
// An adopted layout keeps a subdirectory the predecessor made under the mesh's directory
|
||||
// (issue 174: a forge's runtime state, a manager's output). Stated as beneath the placed one,
|
||||
// it moves with it — a node's root moves both, and the definition names no host path.
|
||||
@@ -269,3 +269,17 @@ func TestADirectoryBeneathAPlacedOneIsPlacedWithIt(t *testing.T) {
|
||||
t.Fatalf("a reference to the subdirectory resolves whole; got %v", container["volumes"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestDirInto runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestDirInto(t *testing.T) {
|
||||
t.Run("APathlessDirectoryResolvesUnderTheNodesRoot", testAPathlessDirectoryResolvesUnderTheNodesRoot)
|
||||
t.Run("DirReferencesBecomeThePlaceInEveryField", testDirReferencesBecomeThePlaceInEveryField)
|
||||
t.Run("AStatedPathIsThePlacementAndStillAnswersByName", testAStatedPathIsThePlacementAndStillAnswersByName)
|
||||
t.Run("FillingForOneNodeLeaksIntoNoOther", testFillingForOneNodeLeaksIntoNoOther)
|
||||
t.Run("AReferenceToNoDirectoryRefusesAtCompositionToo", testAReferenceToNoDirectoryRefusesAtCompositionToo)
|
||||
t.Run("TheAssignmentsOwnRootIsAPlace", testTheAssignmentsOwnRootIsAPlace)
|
||||
t.Run("TheManifestsMapsArePlaced", testTheManifestsMapsArePlaced)
|
||||
t.Run("TheMeshsDirectoryForAModuleIsAPlace", testTheMeshsDirectoryForAModuleIsAPlace)
|
||||
t.Run("TwoModulesPlacedRootsAreNoCollision", testTwoModulesPlacedRootsAreNoCollision)
|
||||
t.Run("ADirectoryBeneathAPlacedOneIsPlacedWithIt", testADirectoryBeneathAPlacedOneIsPlacedWithIt)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func networkingShelf(extra ...mcat.Manifest) map[string]mcat.Manifest {
|
||||
return shelf(append(base, extra...)...)
|
||||
}
|
||||
|
||||
func TestOneWordBringsUpTheNetwork(t *testing.T) {
|
||||
func testOneWordBringsUpTheNetwork(t *testing.T) {
|
||||
// The case that has to stay easy. Nothing is asked, because with one answer to each
|
||||
// requirement there was never a question.
|
||||
got, err := Resolve(networkingShelf(), []string{"networking"}, workstation(), mcat.World{})
|
||||
@@ -34,7 +34,7 @@ func TestOneWordBringsUpTheNetwork(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestASecondVPNTurnsItIntoAChoice(t *testing.T) {
|
||||
func testASecondVPNTurnsItIntoAChoice(t *testing.T) {
|
||||
// And the choice is offered rather than made. A default here would be the flavor field coming
|
||||
// back under another name.
|
||||
_, err := Resolve(networkingShelf(mcat.Manifest{Module: "tailscale", Provides: mcat.Offers("private-network"),
|
||||
@@ -51,7 +51,7 @@ func TestASecondVPNTurnsItIntoAChoice(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChoosingIsAssigning(t *testing.T) {
|
||||
func testChoosingIsAssigning(t *testing.T) {
|
||||
// No second verb. Assigning the one you want answers the requirement, and the bundle takes it.
|
||||
got, err := Resolve(networkingShelf(mcat.Manifest{Module: "tailscale",
|
||||
Provides: mcat.Offers("private-network", "name-resolution"),
|
||||
@@ -70,7 +70,7 @@ func TestChoosingIsAssigning(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChoosingOneVPNCannotDragTheOtherBackIn(t *testing.T) {
|
||||
func testChoosingOneVPNCannotDragTheOtherBackIn(t *testing.T) {
|
||||
// This happened. The person chose tailscale; the names module required the mesh's own
|
||||
// addressing; only WireGuard provides that; so both were installed and nobody was told.
|
||||
//
|
||||
@@ -88,7 +88,7 @@ func TestChoosingOneVPNCannotDragTheOtherBackIn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamesNeedTheMeshsOwnAddresses(t *testing.T) {
|
||||
func testNamesNeedTheMeshsOwnAddresses(t *testing.T) {
|
||||
// Names are computed from addresses the mesh handed out. Over a VPN that hands out its own,
|
||||
// the mesh has nothing to write, so the names module requires the addressing rather than a
|
||||
// private network in general — otherwise a machine gets a hosts file full of addresses that
|
||||
@@ -105,7 +105,7 @@ func TestNamesNeedTheMeshsOwnAddresses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestARequirementWantedTwiceIsReportedOnce(t *testing.T) {
|
||||
func testARequirementWantedTwiceIsReportedOnce(t *testing.T) {
|
||||
// Two identical lines make a person hunt for the difference between them before realising
|
||||
// there is none.
|
||||
_, err := Resolve(shelf(mcat.Manifest{Module: "one", Requires: []string{"shell"}}, mcat.Manifest{Module: "two", Requires: []string{"shell"}}, mcat.Manifest{Module: "bash", Provides: mcat.Offers("shell")}, mcat.Manifest{Module: "zsh", Provides: mcat.Offers("shell")}), []string{"one", "two"}, workstation(), mcat.World{})
|
||||
@@ -117,3 +117,13 @@ func TestARequirementWantedTwiceIsReportedOnce(t *testing.T) {
|
||||
t.Fatalf("the same requirement was reported %d times:\n%v", n, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDomain runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestDomain(t *testing.T) {
|
||||
t.Run("OneWordBringsUpTheNetwork", testOneWordBringsUpTheNetwork)
|
||||
t.Run("ASecondVPNTurnsItIntoAChoice", testASecondVPNTurnsItIntoAChoice)
|
||||
t.Run("ChoosingIsAssigning", testChoosingIsAssigning)
|
||||
t.Run("ChoosingOneVPNCannotDragTheOtherBackIn", testChoosingOneVPNCannotDragTheOtherBackIn)
|
||||
t.Run("NamesNeedTheMeshsOwnAddresses", testNamesNeedTheMeshsOwnAddresses)
|
||||
t.Run("ARequirementWantedTwiceIsReportedOnce", testARequirementWantedTwiceIsReportedOnce)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func aMediaServer() mcat.Manifest {
|
||||
|
||||
// And the routed set is read through the name, so the endpoint the proxy serves is known without a
|
||||
// reader joining two numbers.
|
||||
func TestTheRoutedEndpointIsFoundByName(t *testing.T) {
|
||||
func testTheRoutedEndpointIsFoundByName(t *testing.T) {
|
||||
routed := RoutedPorts(aMediaServer())
|
||||
if !routed[80] {
|
||||
t.Fatalf("the routed endpoint was not found by name: %v", routed)
|
||||
@@ -45,7 +45,7 @@ func TestTheRoutedEndpointIsFoundByName(t *testing.T) {
|
||||
// **Two endpoints of different shapes, configured as themselves.** The web endpoint's reach asks for
|
||||
// names and leaves its port to the proxy; the stream endpoint's reach governs its port, because
|
||||
// clients dial it and there is no name.
|
||||
func TestTwoEndpointsOfDifferentShapesAreConfiguredSeparately(t *testing.T) {
|
||||
func testTwoEndpointsOfDifferentShapesAreConfiguredSeparately(t *testing.T) {
|
||||
m := aMediaServer()
|
||||
settings := mcat.SettingsBy{"media": {{From: "node anchor", Values: map[string]any{mcat.ReachSetting: map[string]any{"80": mcat.ReachBoth, "32400": mcat.ReachPublic}}}}}
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestTwoEndpointsOfDifferentShapesAreConfiguredSeparately(t *testing.T) {
|
||||
//
|
||||
// Caught after the catalogue had already been changed to name endpoints, and before the mesh picked
|
||||
// those manifests up — which is the only reason nothing broke.
|
||||
func TestARouteNamingAnEndpointStillCarriesItsPort(t *testing.T) {
|
||||
func testARouteNamingAnEndpointStillCarriesItsPort(t *testing.T) {
|
||||
m := aMediaServer()
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{m},
|
||||
PublicDomain: "example.test", At: "anchor.internal"}
|
||||
@@ -119,7 +119,7 @@ func TestARouteNamingAnEndpointStillCarriesItsPort(t *testing.T) {
|
||||
// And the declared port, not the machine one: the redirection to where the machine published it
|
||||
// happens later and is keyed on the declared number, so filling the machine port in here would be
|
||||
// redirected twice or not at all.
|
||||
func TestTheEndpointsDeclaredPortIsFilledInNotTheMachineOne(t *testing.T) {
|
||||
func testTheEndpointsDeclaredPortIsFilledInNotTheMachineOne(t *testing.T) {
|
||||
m := aMediaServer()
|
||||
values := map[string]any{mcat.RouteEndpoint: "web", "label": "media"}
|
||||
portOfEndpoint(values, endpointPorts(m))
|
||||
@@ -134,10 +134,19 @@ func TestTheEndpointsDeclaredPortIsFilledInNotTheMachineOne(t *testing.T) {
|
||||
}
|
||||
|
||||
// A route that repeats a port keeps it, because that is the older shape and still read.
|
||||
func TestARouteThatRepeatsItsPortKeepsIt(t *testing.T) {
|
||||
func testARouteThatRepeatsItsPortKeepsIt(t *testing.T) {
|
||||
values := map[string]any{mcat.RouteEndpoint: "web", "port": 8080}
|
||||
portOfEndpoint(values, map[string]int{"web": 80})
|
||||
if got, _ := asPort(values["port"]); got != 8080 {
|
||||
t.Fatalf("the port it stated was overwritten with %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestEndpoint runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestEndpoint(t *testing.T) {
|
||||
t.Run("TheRoutedEndpointIsFoundByName", testTheRoutedEndpointIsFoundByName)
|
||||
t.Run("TwoEndpointsOfDifferentShapesAreConfiguredSeparately", testTwoEndpointsOfDifferentShapesAreConfiguredSeparately)
|
||||
t.Run("ARouteNamingAnEndpointStillCarriesItsPort", testARouteNamingAnEndpointStillCarriesItsPort)
|
||||
t.Run("TheEndpointsDeclaredPortIsFilledInNotTheMachineOne", testTheEndpointsDeclaredPortIsFilledInNotTheMachineOne)
|
||||
t.Run("ARouteThatRepeatsItsPortKeepsIt", testARouteThatRepeatsItsPortKeepsIt)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func configured(block map[string]any) mcat.SettingsBy {
|
||||
// **One block per endpoint, saying all three things.** The machine port, the subdomain and the reach
|
||||
// were `ports`, the route's label and `reach`, each keyed by a port number, so configuring a module
|
||||
// with two endpoints of different shapes meant knowing which number was which.
|
||||
func TestAnEndpointsBlockSaysPortLabelAndReach(t *testing.T) {
|
||||
func testAnEndpointsBlockSaysPortLabelAndReach(t *testing.T) {
|
||||
m := aMediaServer()
|
||||
// stream's reach NARROWS what the manifest says — the manifest has it from anywhere, the
|
||||
// assignment says internal. Chosen deliberately: a reach that agrees with the manifest proves
|
||||
@@ -68,7 +68,7 @@ func TestAnEndpointsBlockSaysPortLabelAndReach(t *testing.T) {
|
||||
|
||||
// A block that says only a reach leaves the port to the mesh and the label to the module, which is the
|
||||
// ordinary case and must not require writing the other two.
|
||||
func TestABlockMaySayOnlyAReach(t *testing.T) {
|
||||
func testABlockMaySayOnlyAReach(t *testing.T) {
|
||||
m := aMediaServer()
|
||||
settings := configured(map[string]any{"web": map[string]any{"reach": mcat.ReachInternal}})
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{m},
|
||||
@@ -89,10 +89,17 @@ func TestABlockMaySayOnlyAReach(t *testing.T) {
|
||||
}
|
||||
|
||||
// **Two places giving one endpoint a machine port is the confusion this key exists to end.**
|
||||
func TestAnEndpointGivenAPortTwiceIsRefused(t *testing.T) {
|
||||
func testAnEndpointGivenAPortTwiceIsRefused(t *testing.T) {
|
||||
m := aMediaServer()
|
||||
_, err := GivenPorts(m, []mcat.Layer{{From: "node anchor", Placement: map[string]any{mcat.EndpointsSetting: map[string]any{"web": map[string]any{"port": 20009}}, mcat.PortsSetting: map[string]any{"80": 30000}}}})
|
||||
if err == nil || !strings.Contains(err.Error(), "published once") {
|
||||
t.Fatalf("an endpoint given two machine ports was accepted: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestEndpointsSetting runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestEndpointsSetting(t *testing.T) {
|
||||
t.Run("AnEndpointsBlockSaysPortLabelAndReach", testAnEndpointsBlockSaysPortLabelAndReach)
|
||||
t.Run("ABlockMaySayOnlyAReach", testABlockMaySayOnlyAReach)
|
||||
t.Run("AnEndpointGivenAPortTwiceIsRefused", testAnEndpointGivenAPortTwiceIsRefused)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestTheServiceManagerReadsTheSystemdRenderingAsMeant(t *testing.T) {
|
||||
if _, err := os.Stat(generator); err != nil {
|
||||
t.Skip("NOT JUDGED: no environment.d generator on this machine, so the service manager's reading " +
|
||||
"of the rendering is judged only where systemd runs; the rendering itself is held byte for byte " +
|
||||
"by TestTheEnvironmentRendersForTheServiceManagerByteForByte")
|
||||
"by testTheEnvironmentRendersForTheServiceManagerByteForByte")
|
||||
}
|
||||
const base = "/usr/bin:/bin"
|
||||
read := func(conf string) map[string]string {
|
||||
|
||||
@@ -74,7 +74,7 @@ PATH=/home/op/go/bin:/usr/local/go/bin:/home/op/.local/bin:/home/op/bin${PATH:+:
|
||||
PATH=${PATH:+$PATH:}/opt/agent/bin:/opt/scripts
|
||||
`
|
||||
|
||||
func TestTheEnvironmentRendersForAPOSIXShellByteForByte(t *testing.T) {
|
||||
func testTheEnvironmentRendersForAPOSIXShellByteForByte(t *testing.T) {
|
||||
env, err := environmentOn(contributors(), operatorFacts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -84,7 +84,7 @@ func TestTheEnvironmentRendersForAPOSIXShellByteForByte(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheEnvironmentRendersForTheServiceManagerByteForByte(t *testing.T) {
|
||||
func testTheEnvironmentRendersForTheServiceManagerByteForByte(t *testing.T) {
|
||||
env, err := environmentOn(contributors(), operatorFacts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -95,7 +95,7 @@ func TestTheEnvironmentRendersForTheServiceManagerByteForByte(t *testing.T) {
|
||||
}
|
||||
|
||||
// Nothing contributed renders nothing, in both formats — not an empty `export PATH`.
|
||||
func TestNoContributionsRenderNothing(t *testing.T) {
|
||||
func testNoContributionsRenderNothing(t *testing.T) {
|
||||
env, err := environmentOn([]mcat.Manifest{{Module: "postgres"}}, operatorFacts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -106,7 +106,7 @@ func TestNoContributionsRenderNothing(t *testing.T) {
|
||||
}
|
||||
|
||||
// A ${machine:…} fact the machine does not have is refused naming the module, as a file's is.
|
||||
func TestAContributedFactTheMachineLacksIsRefused(t *testing.T) {
|
||||
func testAContributedFactTheMachineLacksIsRefused(t *testing.T) {
|
||||
_, err := environmentOn(contributors(), map[string]string{"name": "server"})
|
||||
if err == nil || !strings.Contains(err.Error(), "go-toolchain sets GOPATH") ||
|
||||
!strings.Contains(err.Error(), "${machine:account-home}") {
|
||||
@@ -115,7 +115,7 @@ func TestAContributedFactTheMachineLacksIsRefused(t *testing.T) {
|
||||
}
|
||||
|
||||
// ADR 0203 §5: two modules setting one variable are refused, both named — neither silently wins.
|
||||
func TestAVariableTwoModulesSetIsRefusedNamingBoth(t *testing.T) {
|
||||
func testAVariableTwoModulesSetIsRefusedNamingBoth(t *testing.T) {
|
||||
modules := append(contributors(), mcat.Manifest{Module: "neovim", Environment: &mcat.Environment{
|
||||
Variables: map[string]string{"EDITOR": "nvim"}}})
|
||||
_, err := environmentOn(modules, operatorFacts)
|
||||
@@ -171,7 +171,7 @@ func zshHolder() mcat.Manifest {
|
||||
// byte, because the shell's code is placed after every other placeholder pass and in one pass — a
|
||||
// scanner for the mesh's placeholders that ran after it would read `${XDG_CACHE_HOME:-…}` and
|
||||
// `${(%):-%n}` as the mesh's, or fill a `${machine:…}` some module wrote for its shell to see.
|
||||
func TestShellCodeReachesTheHoldersFileByteForByte(t *testing.T) {
|
||||
func testShellCodeReachesTheHoldersFileByteForByte(t *testing.T) {
|
||||
modules := append(shells(), zshHolder(), mcat.Manifest{Module: "sly", Shell: []mcat.ShellCode{
|
||||
{For: "zsh", Slot: "last", Code: "echo ${machine:account-home} ${secret:x} ${shell:zsh:first} ${environment:posix}"},
|
||||
}})
|
||||
@@ -212,7 +212,7 @@ func TestShellCodeReachesTheHoldersFileByteForByte(t *testing.T) {
|
||||
}
|
||||
|
||||
// The holder of node-environment places both renderings, and they are the same as rendered alone.
|
||||
func TestTheEnvironmentHolderPlacesBothRenderings(t *testing.T) {
|
||||
func testTheEnvironmentHolderPlacesBothRenderings(t *testing.T) {
|
||||
holder := mcat.Manifest{Module: "node-env", Claims: []mcat.Claim{{Name: mcat.EnvironmentSeat, Scope: mcat.ScopeNode}},
|
||||
Resources: []map[string]any{
|
||||
{"id": "posix", "type": "file", "path": "${machine:account-home}/.config/mesh/environment.sh",
|
||||
@@ -236,3 +236,14 @@ func TestTheEnvironmentHolderPlacesBothRenderings(t *testing.T) {
|
||||
t.Fatalf("the environment.d file is\n%v", by["node-env.systemd"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestEnvironmentInto runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestEnvironmentInto(t *testing.T) {
|
||||
t.Run("TheEnvironmentRendersForAPOSIXShellByteForByte", testTheEnvironmentRendersForAPOSIXShellByteForByte)
|
||||
t.Run("TheEnvironmentRendersForTheServiceManagerByteForByte", testTheEnvironmentRendersForTheServiceManagerByteForByte)
|
||||
t.Run("NoContributionsRenderNothing", testNoContributionsRenderNothing)
|
||||
t.Run("AContributedFactTheMachineLacksIsRefused", testAContributedFactTheMachineLacksIsRefused)
|
||||
t.Run("AVariableTwoModulesSetIsRefusedNamingBoth", testAVariableTwoModulesSetIsRefusedNamingBoth)
|
||||
t.Run("ShellCodeReachesTheHoldersFileByteForByte", testShellCodeReachesTheHoldersFileByteForByte)
|
||||
t.Run("TheEnvironmentHolderPlacesBothRenderings", testTheEnvironmentHolderPlacesBothRenderings)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
// A machine that has not said which links face outside is sent no filter, and the refusal names the
|
||||
// module that would have loaded it so the reader knows what is being withheld.
|
||||
func TestAMachineThatNamedNoOutwardLinkIsSentNoFilter(t *testing.T) {
|
||||
func testAMachineThatNamedNoOutwardLinkIsSentNoFilter(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{
|
||||
{Module: "nftables", Filtering: &mcat.Filtering{Into: "/etc/mesh/filter.nft"}},
|
||||
{Module: "web", Listens: []mcat.Listening{{Port: 443, From: mcat.FromEverywhere}}},
|
||||
@@ -35,7 +35,7 @@ func TestAMachineThatNamedNoOutwardLinkIsSentNoFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
// The rule set is the machine's, not the asking module's.
|
||||
func TestTheModuleAskingForTheRuleSetGetsEveryModulesPorts(t *testing.T) {
|
||||
func testTheModuleAskingForTheRuleSetGetsEveryModulesPorts(t *testing.T) {
|
||||
r := mcat.Resolution{Modules: []mcat.Manifest{
|
||||
{Module: "firewall", Filtering: &mcat.Filtering{Into: "/etc/mesh/filter.nft"}},
|
||||
{Module: "web", Listens: []mcat.Listening{{Port: 443, From: mcat.FromEverywhere}}},
|
||||
@@ -191,7 +191,7 @@ func TestTheModuleAskingForTheRuleSetGetsEveryModulesPorts(t *testing.T) {
|
||||
// a credential, a rule set. Written after the service, the service is applied first, fails, and
|
||||
// the next reconcile fixes it. A fault that repairs itself on the second attempt is worse than one
|
||||
// that does not: what gets remembered is that it works.
|
||||
func TestWhatTheMeshComputesIsAppliedBeforeWhatTheModuleDeclared(t *testing.T) {
|
||||
func testWhatTheMeshComputesIsAppliedBeforeWhatTheModuleDeclared(t *testing.T) {
|
||||
r := mcat.Resolution{Modules: []mcat.Manifest{{
|
||||
Module: "firewall",
|
||||
Filtering: &mcat.Filtering{Into: "/etc/nftables.conf"},
|
||||
@@ -219,7 +219,7 @@ func TestWhatTheMeshComputesIsAppliedBeforeWhatTheModuleDeclared(t *testing.T) {
|
||||
|
||||
// The same, for a module whose resources are computed elsewhere — that branch replaces the
|
||||
// module's resources wholesale, and merging in the wrong place would throw away its credentials.
|
||||
func TestAComputedModuleStillGetsWhatTheMeshMadeForIt(t *testing.T) {
|
||||
func testAComputedModuleStillGetsWhatTheMeshMadeForIt(t *testing.T) {
|
||||
r := mcat.Resolution{Modules: []mcat.Manifest{{
|
||||
Module: "networking", Computed: "mesh-network",
|
||||
OwnSecrets: mcat.OwnSecrets{"key": {Path: "/var/lib/mesh/key"}},
|
||||
@@ -253,7 +253,7 @@ func (computedOnce) Resources(string) ([]map[string]any, bool, error) {
|
||||
// binding carries what the provider said a consumer must know, which is the port. A build machine
|
||||
// sharing a node with the registry it pushes to sat in a loop saying it could not read its own
|
||||
// binding, because none was written.
|
||||
func TestSomethingAnsweredOnThisMachineIsStillBound(t *testing.T) {
|
||||
func testSomethingAnsweredOnThisMachineIsStillBound(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "anchor", At: "anchor.internal",
|
||||
Modules: []mcat.Manifest{
|
||||
@@ -285,7 +285,7 @@ func TestSomethingAnsweredOnThisMachineIsStillBound(t *testing.T) {
|
||||
}
|
||||
|
||||
// And a machine not on the private network still reaches itself.
|
||||
func TestAMachineOffTheNetworkIsBoundToItselfByAnAddressThatWorks(t *testing.T) {
|
||||
func testAMachineOffTheNetworkIsBoundToItselfByAnAddressThatWorks(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "alone",
|
||||
Modules: []mcat.Manifest{
|
||||
@@ -325,7 +325,7 @@ func (cannotSay) Listens(string) ([]mcat.Listening, error) {
|
||||
//
|
||||
// Closing a port on the evidence of a failure to look is how a machine is severed by a fault
|
||||
// somewhere else entirely — and the machine it would sever is the hub.
|
||||
func TestAGeneratorThatCannotSayRefusesTheRuleSet(t *testing.T) {
|
||||
func testAGeneratorThatCannotSayRefusesTheRuleSet(t *testing.T) {
|
||||
_, err := Filtering(mcat.Resolution{Node: "anchor",
|
||||
Modules: []mcat.Manifest{{Module: "networking", Computed: "mesh-network"}},
|
||||
}, map[string]mcat.Generator{"mesh-network": cannotSay{}}, nil, nil)
|
||||
@@ -342,7 +342,7 @@ func TestAGeneratorThatCannotSayRefusesTheRuleSet(t *testing.T) {
|
||||
// The case this exists for: a resolver restarting when the mesh rewrites the names. Those are
|
||||
// computed by the mesh and belong to its module, not to the daemon's — so without this the
|
||||
// daemon would serve the names it started with for ever, while every check reported success.
|
||||
func TestAServiceCanReflectAnotherModulesFile(t *testing.T) {
|
||||
func testAServiceCanReflectAnotherModulesFile(t *testing.T) {
|
||||
out, err := Declaration(mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{{
|
||||
Module: "dnsmasq",
|
||||
Resources: []map[string]any{
|
||||
@@ -387,7 +387,7 @@ func TestAServiceCanReflectAnotherModulesFile(t *testing.T) {
|
||||
// walks outward from what was assigned, which puts a consumer first — and a service that reads a
|
||||
// file another module writes then starts before the file exists, fails, and is fixed by the next
|
||||
// reconcile. That is the worst shape a fault can take: what gets remembered is that it works.
|
||||
func TestWhatAnsweredARequirementIsAppliedFirst(t *testing.T) {
|
||||
func testWhatAnsweredARequirementIsAppliedFirst(t *testing.T) {
|
||||
got, err := Resolve(map[string]mcat.Manifest{
|
||||
"dnsmasq": {Module: "dnsmasq", Requires: []string{"resolver-data"}},
|
||||
"data": {Module: "data", Provides: []mcat.Offer{{Name: "resolver-data"}}},
|
||||
@@ -401,7 +401,7 @@ func TestWhatAnsweredARequirementIsAppliedFirst(t *testing.T) {
|
||||
}
|
||||
|
||||
// Through a chain, not only one step: a machine applies what the thing it needs needs, first.
|
||||
func TestAChainOfRequirementsIsAppliedFromTheBottom(t *testing.T) {
|
||||
func testAChainOfRequirementsIsAppliedFromTheBottom(t *testing.T) {
|
||||
got, err := Resolve(map[string]mcat.Manifest{
|
||||
"top": {Module: "top", Requires: []string{"middle-thing"}},
|
||||
"middle": {Module: "middle", Provides: []mcat.Offer{{Name: "middle-thing"}}, Requires: []string{"bottom-thing"}},
|
||||
@@ -419,7 +419,7 @@ func TestAChainOfRequirementsIsAppliedFromTheBottom(t *testing.T) {
|
||||
// Modules with no relation keep the order selection gave them — assigned first, then what they
|
||||
// pulled in. A sort that reshuffled unrelated modules would make every declaration's diff
|
||||
// unreadable for no gain.
|
||||
func TestUnrelatedModulesKeepTheirOrder(t *testing.T) {
|
||||
func testUnrelatedModulesKeepTheirOrder(t *testing.T) {
|
||||
got, err := Resolve(map[string]mcat.Manifest{
|
||||
"one": {Module: "one"},
|
||||
"two": {Module: "two"},
|
||||
@@ -436,7 +436,7 @@ func TestUnrelatedModulesKeepTheirOrder(t *testing.T) {
|
||||
|
||||
// Two modules requiring each other are both applied rather than refused: a cycle here is not a
|
||||
// machine that cannot work, and refusing would make a cooperating pair impossible to assign.
|
||||
func TestTwoModulesRequiringEachOtherAreStillApplied(t *testing.T) {
|
||||
func testTwoModulesRequiringEachOtherAreStillApplied(t *testing.T) {
|
||||
got, err := Resolve(map[string]mcat.Manifest{
|
||||
"a": {Module: "a", Provides: []mcat.Offer{{Name: "from-a"}}, Requires: []string{"from-b"}},
|
||||
"b": {Module: "b", Provides: []mcat.Offer{{Name: "from-b"}}, Requires: []string{"from-a"}},
|
||||
@@ -460,7 +460,7 @@ func named(r mcat.Resolution) []string {
|
||||
// A port's source is a per-node setting, not a manifest constant: the same module is internal on
|
||||
// one machine and public on another (novox/hq ADR 0046). postgres listens from the mesh by default;
|
||||
// a setting on one node exposes it to anywhere, and the rule set follows.
|
||||
func TestExposureSettingOverridesAListensSource(t *testing.T) {
|
||||
func testExposureSettingOverridesAListensSource(t *testing.T) {
|
||||
postgres := mcat.Manifest{Module: "postgres", Version: "1",
|
||||
Listens: []mcat.Listening{{Port: 5432, From: mcat.FromMesh, Why: "the database"}}}
|
||||
|
||||
@@ -484,7 +484,7 @@ func TestExposureSettingOverridesAListensSource(t *testing.T) {
|
||||
|
||||
// Exposure refuses a setting that names a port the module does not listen on, or a source that is
|
||||
// not a real one — a setting reaching nothing is worse than none (novox/hq ADR 0043/0046).
|
||||
func TestExposureRefusesAPortNotListenedOnAndABadSource(t *testing.T) {
|
||||
func testExposureRefusesAPortNotListenedOnAndABadSource(t *testing.T) {
|
||||
postgres := mcat.Manifest{Module: "postgres", Listens: []mcat.Listening{{Port: 5432, From: mcat.FromMesh}}}
|
||||
layer := func(port, source string) []mcat.Layer {
|
||||
return []mcat.Layer{{From: "node", Placement: map[string]any{mcat.ExposeSetting: map[string]any{port: source}}}}
|
||||
@@ -500,3 +500,21 @@ func TestExposureRefusesAPortNotListenedOnAndABadSource(t *testing.T) {
|
||||
t.Error("a source that is not mesh/anywhere/machine was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
// TestFiltering runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestFiltering(t *testing.T) {
|
||||
t.Run("AMachineThatNamedNoOutwardLinkIsSentNoFilter", testAMachineThatNamedNoOutwardLinkIsSentNoFilter)
|
||||
t.Run("TheModuleAskingForTheRuleSetGetsEveryModulesPorts", testTheModuleAskingForTheRuleSetGetsEveryModulesPorts)
|
||||
t.Run("WhatTheMeshComputesIsAppliedBeforeWhatTheModuleDeclared", testWhatTheMeshComputesIsAppliedBeforeWhatTheModuleDeclared)
|
||||
t.Run("AComputedModuleStillGetsWhatTheMeshMadeForIt", testAComputedModuleStillGetsWhatTheMeshMadeForIt)
|
||||
t.Run("SomethingAnsweredOnThisMachineIsStillBound", testSomethingAnsweredOnThisMachineIsStillBound)
|
||||
t.Run("AMachineOffTheNetworkIsBoundToItselfByAnAddressThatWorks", testAMachineOffTheNetworkIsBoundToItselfByAnAddressThatWorks)
|
||||
t.Run("AGeneratorThatCannotSayRefusesTheRuleSet", testAGeneratorThatCannotSayRefusesTheRuleSet)
|
||||
t.Run("AServiceCanReflectAnotherModulesFile", testAServiceCanReflectAnotherModulesFile)
|
||||
t.Run("WhatAnsweredARequirementIsAppliedFirst", testWhatAnsweredARequirementIsAppliedFirst)
|
||||
t.Run("AChainOfRequirementsIsAppliedFromTheBottom", testAChainOfRequirementsIsAppliedFromTheBottom)
|
||||
t.Run("UnrelatedModulesKeepTheirOrder", testUnrelatedModulesKeepTheirOrder)
|
||||
t.Run("TwoModulesRequiringEachOtherAreStillApplied", testTwoModulesRequiringEachOtherAreStillApplied)
|
||||
t.Run("ExposureSettingOverridesAListensSource", testExposureSettingOverridesAListensSource)
|
||||
t.Run("ExposureRefusesAPortNotListenedOnAndABadSource", testExposureRefusesAPortNotListenedOnAndABadSource)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func catalogueManifest(t *testing.T, module string) mcat.Manifest {
|
||||
return m
|
||||
}
|
||||
|
||||
func TestTheForgesPortIsGivenLikeAnyOtherProvidersPort(t *testing.T) {
|
||||
func testTheForgesPortIsGivenLikeAnyOtherProvidersPort(t *testing.T) {
|
||||
forge := catalogueManifest(t, "gitea")
|
||||
|
||||
// The catalogue's number is a default and the node's setting moves it.
|
||||
@@ -66,7 +66,7 @@ func TestTheForgesPortIsGivenLikeAnyOtherProvidersPort(t *testing.T) {
|
||||
|
||||
// The forge holds the seats it answers for (novox/hq ADR 0110, 0111), parsed by the real parser —
|
||||
// which refuses a delivering seat claimed by a module that does not provide what it delivers.
|
||||
func TestTheForgeHoldsTheNpmAndGitSeats(t *testing.T) {
|
||||
func testTheForgeHoldsTheNpmAndGitSeats(t *testing.T) {
|
||||
forge := catalogueManifest(t, "gitea")
|
||||
holds := map[string]bool{}
|
||||
for _, c := range forge.Claims {
|
||||
@@ -96,7 +96,7 @@ func TestTheForgeHoldsTheNpmAndGitSeats(t *testing.T) {
|
||||
// wrong on every node whose assignment differs, and wrong for a second reason on a node given the
|
||||
// port (ADR 0100). Composed through the whole path, because what proves the placeholder resolves
|
||||
// in an `env` at all is a declaration, not a manifest.
|
||||
func TestTheForgesOwnAddressFollowsThePortTheNodeGaveIt(t *testing.T) {
|
||||
func testTheForgesOwnAddressFollowsThePortTheNodeGaveIt(t *testing.T) {
|
||||
forge, err := catalogueManifest(t, "gitea").Resolve(forgeBuilt(catalogueManifest(t, "gitea")))
|
||||
if err != nil {
|
||||
t.Fatalf("the forge's manifest does not resolve against its own build: %v", err)
|
||||
@@ -187,7 +187,7 @@ func declaredGiteaSsh(t *testing.T, given map[int]int) map[string]any {
|
||||
// `222` is the mesh's own public convention for the forge's ssh, written directly in the
|
||||
// manifest's `ports` — every node the forge has run on used the same number, so it needs no
|
||||
// per-node setting to reach it.
|
||||
func TestTheForgesSshPortIsTheMeshsFixedConventionByDefault(t *testing.T) {
|
||||
func testTheForgesSshPortIsTheMeshsFixedConventionByDefault(t *testing.T) {
|
||||
forge := catalogueManifest(t, "gitea")
|
||||
// Nothing was given — no node moved this port — which is the ordinary answer: the mesh only
|
||||
// reports what a setting moved, and the manifest's own `222:22` needs no move to be reached.
|
||||
@@ -208,7 +208,7 @@ func TestTheForgesSshPortIsTheMeshsFixedConventionByDefault(t *testing.T) {
|
||||
// there.** The setting names the port the module itself listens on — 22, gitea's own sshd, the
|
||||
// same number `listens` uses — not the mesh's own default machine-side number, so moving it does
|
||||
// not require guessing what the manifest happens to default to.
|
||||
func TestANodeMayGiveTheForgesSshPortADifferentNumber(t *testing.T) {
|
||||
func testANodeMayGiveTheForgesSshPortADifferentNumber(t *testing.T) {
|
||||
forge := catalogueManifest(t, "gitea")
|
||||
given, err := GivenPorts(forge, []mcat.Layer{{From: "anchor",
|
||||
Placement: map[string]any{mcat.PortsSetting: map[string]any{"22": float64(9022)}}}})
|
||||
@@ -268,3 +268,12 @@ func catalogueResolved(t *testing.T, module string, built ...mcat.Built) mcat.Ma
|
||||
}
|
||||
return held
|
||||
}
|
||||
|
||||
// TestFoundationManifests runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestFoundationManifests(t *testing.T) {
|
||||
t.Run("TheForgesPortIsGivenLikeAnyOtherProvidersPort", testTheForgesPortIsGivenLikeAnyOtherProvidersPort)
|
||||
t.Run("TheForgeHoldsTheNpmAndGitSeats", testTheForgeHoldsTheNpmAndGitSeats)
|
||||
t.Run("TheForgesOwnAddressFollowsThePortTheNodeGaveIt", testTheForgesOwnAddressFollowsThePortTheNodeGaveIt)
|
||||
t.Run("TheForgesSshPortIsTheMeshsFixedConventionByDefault", testTheForgesSshPortIsTheMeshsFixedConventionByDefault)
|
||||
t.Run("ANodeMayGiveTheForgesSshPortADifferentNumber", testANodeMayGiveTheForgesSshPortADifferentNumber)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func runtimesOwn() mcat.Manifest {
|
||||
}}
|
||||
}
|
||||
|
||||
func TestAGeneratedResourceCollidingWithAModulesIsRefused(t *testing.T) {
|
||||
func testAGeneratedResourceCollidingWithAModulesIsRefused(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "workstation", Modules: []mcat.Manifest{
|
||||
{Module: "mesh-network", Computed: "mesh-network", Provides: mcat.Offers("private-network")},
|
||||
runtimesOwn(),
|
||||
@@ -32,7 +32,7 @@ func TestAGeneratedResourceCollidingWithAModulesIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAGeneratedResourceBesideAModulesOwnIsComposed(t *testing.T) {
|
||||
func testAGeneratedResourceBesideAModulesOwnIsComposed(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "workstation", Modules: []mcat.Manifest{
|
||||
{Module: "mesh-network", Computed: "mesh-network", Provides: mcat.Offers("private-network")},
|
||||
runtimesOwn(),
|
||||
@@ -52,7 +52,7 @@ func TestAGeneratedResourceBesideAModulesOwnIsComposed(t *testing.T) {
|
||||
}
|
||||
|
||||
// The catalogue's container runtime module states the mesh's registry itself (ADR 0222).
|
||||
func TestTheRuntimesModuleTrustsTheMeshsRegistry(t *testing.T) {
|
||||
func testTheRuntimesModuleTrustsTheMeshsRegistry(t *testing.T) {
|
||||
docker := catalogueManifest(t, "docker")
|
||||
r := mcat.Resolution{Node: "workstation", Modules: []mcat.Manifest{docker}}
|
||||
out, err := Declaration(r, mcat.Rendering{
|
||||
@@ -81,3 +81,10 @@ func TestTheRuntimesModuleTrustsTheMeshsRegistry(t *testing.T) {
|
||||
t.Fatalf("with no store on the network, the runtime is told %q", content)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGeneratedCollision runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestGeneratedCollision(t *testing.T) {
|
||||
t.Run("AGeneratedResourceCollidingWithAModulesIsRefused", testAGeneratedResourceCollidingWithAModulesIsRefused)
|
||||
t.Run("AGeneratedResourceBesideAModulesOwnIsComposed", testAGeneratedResourceBesideAModulesOwnIsComposed)
|
||||
t.Run("TheRuntimesModuleTrustsTheMeshsRegistry", testTheRuntimesModuleTrustsTheMeshsRegistry)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func aProviderWithABundle() mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAGrantSecretIsOwnedByTheAccountThatProvisions(t *testing.T) {
|
||||
func testAGrantSecretIsOwnedByTheAccountThatProvisions(t *testing.T) {
|
||||
r, err := Resolve(shelf(aProviderWithABundle()), []string{"mongodb"}, reachable(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -72,7 +72,7 @@ func TestAGrantSecretIsOwnedByTheAccountThatProvisions(t *testing.T) {
|
||||
|
||||
// And a provider whose code still runs in a container keeps the owner it declares, so this
|
||||
// changes nothing for the modules the runtime has not taken.
|
||||
func TestAContainerProvidersGrantSecretKeepsItsDeclaredOwner(t *testing.T) {
|
||||
func testAContainerProvidersGrantSecretKeepsItsDeclaredOwner(t *testing.T) {
|
||||
m := aProviderWithABundle()
|
||||
m.Bundles = nil
|
||||
m.SecretsOwner = "65534:65534"
|
||||
@@ -103,3 +103,9 @@ func fmtPath(r map[string]any) string {
|
||||
p, _ := r["path"].(string)
|
||||
return p
|
||||
}
|
||||
|
||||
// TestGrantSecretOwner runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestGrantSecretOwner(t *testing.T) {
|
||||
t.Run("AGrantSecretIsOwnedByTheAccountThatProvisions", testAGrantSecretIsOwnedByTheAccountThatProvisions)
|
||||
t.Run("AContainerProvidersGrantSecretKeepsItsDeclaredOwner", testAContainerProvidersGrantSecretKeepsItsDeclaredOwner)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func windowManager() mcat.Manifest {
|
||||
}
|
||||
|
||||
// §3: a display is resolved on the requiring module's own node.
|
||||
func TestAMachineReachRequirementResolvesToTheProviderOnItsOwnNode(t *testing.T) {
|
||||
func testAMachineReachRequirementResolvesToTheProviderOnItsOwnNode(t *testing.T) {
|
||||
cat := shelf(windowManager(), displayServer("xorg", "x11-display", mcat.DisplayServerSeat))
|
||||
got, err := Resolve(cat, []string{"xorg", "i3"}, workstation(), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -33,7 +33,7 @@ func TestAMachineReachRequirementResolvesToTheProviderOnItsOwnNode(t *testing.T)
|
||||
}
|
||||
|
||||
// §3: never answered by installing a provider, and never by another machine's.
|
||||
func TestAMachineReachRequirementIsNotPulledInNorAnsweredFromAnotherNode(t *testing.T) {
|
||||
func testAMachineReachRequirementIsNotPulledInNorAnsweredFromAnotherNode(t *testing.T) {
|
||||
cat := shelf(windowManager(),
|
||||
displayServer("xorg", "x11-display", mcat.DisplayServerSeat),
|
||||
displayServer("xwayland", "x11-display"))
|
||||
@@ -65,10 +65,17 @@ func TestAMachineReachRequirementIsNotPulledInNorAnsweredFromAnotherNode(t *test
|
||||
}
|
||||
}
|
||||
|
||||
func TestACatalogueDisagreeingAboutAProvisionsReachIsRefused(t *testing.T) {
|
||||
func testACatalogueDisagreeingAboutAProvisionsReachIsRefused(t *testing.T) {
|
||||
cat := shelf(windowManager(), displayServer("xorg", "x11-display"), mcat.Manifest{Module: "fake-x", Provides: mcat.Offers("x11-display")})
|
||||
_, err := Resolve(cat, []string{"xorg", "i3"}, workstation(), mcat.World{})
|
||||
if err == nil || !strings.Contains(err.Error(), `the catalogue disagrees about "x11-display"`) {
|
||||
t.Fatalf("a provision with and without the machine's reach gave %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGraphicalSession runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestGraphicalSession(t *testing.T) {
|
||||
t.Run("AMachineReachRequirementResolvesToTheProviderOnItsOwnNode", testAMachineReachRequirementResolvesToTheProviderOnItsOwnNode)
|
||||
t.Run("AMachineReachRequirementIsNotPulledInNorAnsweredFromAnotherNode", testAMachineReachRequirementIsNotPulledInNorAnsweredFromAnotherNode)
|
||||
t.Run("ACatalogueDisagreeingAboutAProvisionsReachIsRefused", testACatalogueDisagreeingAboutAProvisionsReachIsRefused)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func aContainerWithGroups(groups ...any) map[string]any {
|
||||
}
|
||||
|
||||
// 1636/AC3: a manifest container with groups: ["${setting:media-gid}"] resolves to the number the setting says.
|
||||
func TestAContainersGroupIsFilledFromTheSetting(t *testing.T) {
|
||||
func testAContainersGroupIsFilledFromTheSetting(t *testing.T) {
|
||||
r := aContainerWithGroups("${setting:media-gid}", float64(2001))
|
||||
layers := []mcat.Layer{{From: "ace", Values: map[string]any{"media-gid": float64(2000)}}}
|
||||
if err := settingInto(r, layers, "n8n"); err != nil {
|
||||
@@ -34,7 +34,7 @@ func TestAContainersGroupIsFilledFromTheSetting(t *testing.T) {
|
||||
}
|
||||
|
||||
// 1636/AC3: an unset value refuses the module by name, and the key and the remedy are named; nothing is dropped.
|
||||
func TestAnUnsetGroupRefusesTheModuleByName(t *testing.T) {
|
||||
func testAnUnsetGroupRefusesTheModuleByName(t *testing.T) {
|
||||
r := aContainerWithGroups("${setting:media-gid}")
|
||||
err := settingInto(r, nil, "n8n")
|
||||
if err == nil || !strings.Contains(err.Error(), "n8n") || !strings.Contains(err.Error(), "media-gid") {
|
||||
@@ -46,7 +46,7 @@ func TestAnUnsetGroupRefusesTheModuleByName(t *testing.T) {
|
||||
}
|
||||
|
||||
// 1636/AC2: a value that is not a whole number above zero cannot be a group.
|
||||
func TestAGroupThatIsNotAWholeNumberAboveZeroIsRefused(t *testing.T) {
|
||||
func testAGroupThatIsNotAWholeNumberAboveZeroIsRefused(t *testing.T) {
|
||||
for _, bad := range []any{"media", "-1", "0", float64(0), float64(2000.5), "2000:2000", "", true} {
|
||||
r := aContainerWithGroups("${setting:media-gid}")
|
||||
err := settingInto(r, []mcat.Layer{{From: "ace", Values: map[string]any{"media-gid": bad}}}, "n8n")
|
||||
@@ -58,7 +58,7 @@ func TestAGroupThatIsNotAWholeNumberAboveZeroIsRefused(t *testing.T) {
|
||||
|
||||
// 1636/AC3 composed for a machine, the way a push writes it: n8n's group is the number the machine's config value
|
||||
// says, written as a number, and the module is left out by name when the machine says none.
|
||||
func TestAComposedMachineGetsTheGroupTheConfigValueNames(t *testing.T) {
|
||||
func testAComposedMachineGetsTheGroupTheConfigValueNames(t *testing.T) {
|
||||
manifest, err := parseRaw(t, map[string]any{
|
||||
"module": "n8n", "version": "1",
|
||||
"config": map[string]any{"media-gid": map[string]any{"type": "number", "minimum": 1, "required": true,
|
||||
@@ -98,7 +98,7 @@ func TestAComposedMachineGetsTheGroupTheConfigValueNames(t *testing.T) {
|
||||
// The node-engine reads a container's groups only when it reports the capability (novox/hq ADR 0480 clause 7, issue 1638):
|
||||
// a module with a container that names groups is hosted on a machine that reports container-groups, and left out of one
|
||||
// that does not, the capability named, so the field is never sent to an engine that would refuse it.
|
||||
func TestAModuleWhoseContainerNamesGroupsIsHeldOnAMachineThatDoesNotReadThem(t *testing.T) {
|
||||
func testAModuleWhoseContainerNamesGroupsIsHeldOnAMachineThatDoesNotReadThem(t *testing.T) {
|
||||
n8n := mcat.Manifest{Module: "n8n", Resources: []map[string]any{aContainerWithGroups("${config:media-gid}")}}
|
||||
plain := mcat.Manifest{Module: "plain", Resources: []map[string]any{
|
||||
{"id": "server", "type": "container", "name": "p", "image": "x@sha256:" + strings.Repeat("b", 64)}}}
|
||||
@@ -125,3 +125,12 @@ func TestAModuleWhoseContainerNamesGroupsIsHeldOnAMachineThatDoesNotReadThem(t *
|
||||
t.Errorf("the module without groups is not the one hosted: %v", h)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGroups runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestGroups(t *testing.T) {
|
||||
t.Run("AContainersGroupIsFilledFromTheSetting", testAContainersGroupIsFilledFromTheSetting)
|
||||
t.Run("AnUnsetGroupRefusesTheModuleByName", testAnUnsetGroupRefusesTheModuleByName)
|
||||
t.Run("AGroupThatIsNotAWholeNumberAboveZeroIsRefused", testAGroupThatIsNotAWholeNumberAboveZeroIsRefused)
|
||||
t.Run("AComposedMachineGetsTheGroupTheConfigValueNames", testAComposedMachineGetsTheGroupTheConfigValueNames)
|
||||
t.Run("AModuleWhoseContainerNamesGroupsIsHeldOnAMachineThatDoesNotReadThem", testAModuleWhoseContainerNamesGroupsIsHeldOnAMachineThatDoesNotReadThem)
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func withDatabase(t *testing.T, raw, text string, moved bool) mcat.Resolution {
|
||||
// The forge's server.env composes for a handed module when what it requires has moved, its plan entry carrying the
|
||||
// provider's address, machine and the consumer's identity as today's binding file gives them; and is refused with the
|
||||
// text it has always had when the provider has not.
|
||||
func TestAHandedModuleMayNameWhatItRequiresWhereItsProviderHasMoved(t *testing.T) {
|
||||
func testAHandedModuleMayNameWhatItRequiresWhereItsProviderHasMoved(t *testing.T) {
|
||||
c, got := composeWith(t, databaseConsumer(t, "", true), handingTo("store:5000"))
|
||||
if strings.Contains(got, "sealed") {
|
||||
t.Fatalf("a handed module's declaration carries a sealed value: %s", got)
|
||||
@@ -79,7 +79,7 @@ func TestAHandedModuleMayNameWhatItRequiresWhereItsProviderHasMoved(t *testing.T
|
||||
// A handed module's credentials the vault keeps as one login per local name (issue 793): gitea's internal token and
|
||||
// admin password, which the `secret` provision hands as `${secret:<local>}`. Each is a plan entry naming its local,
|
||||
// its file declared placed and without a value; the template naming the local is allowed.
|
||||
func TestAHandedModulesLocalCredentialsOfTheVaultAreNamedByLocalInItsPlan(t *testing.T) {
|
||||
func testAHandedModulesLocalCredentialsOfTheVaultAreNamedByLocalInItsPlan(t *testing.T) {
|
||||
raw := strings.Replace(botMoved(), `"own-secrets":{"token":"${dir:state}/token"}`,
|
||||
`"requires":["secret"],"secrets":{"secret":{"internal-token":"${dir:state}/internal-token.secret",`+
|
||||
`"admin":"${dir:state}/admin.secret"}},"own-secrets":{"token":"${dir:state}/token"}`, 1)
|
||||
@@ -117,7 +117,7 @@ func TestAHandedModulesLocalCredentialsOfTheVaultAreNamedByLocalInItsPlan(t *tes
|
||||
// 1966); where it does not the node-engine must fill it from what the provider serves statically, cannot, and refuses
|
||||
// it as a handed module not handed, saying why the machine does not take it (issue 1966), where an unmarked module is
|
||||
// refused with the keys the binding says and that it is not moved.
|
||||
func TestAHandedModuleNamingARunTimeBoundKeyComposesOnlyWhereItIsHanded(t *testing.T) {
|
||||
func testAHandedModuleNamingARunTimeBoundKeyComposesOnlyWhereItIsHanded(t *testing.T) {
|
||||
text := "Host ${bound:postgres-database:at}\n KnownHost ${bound:postgres-database:known_host}\n"
|
||||
moved := strings.Replace(botMoved(), `"own-secrets":{"token":"${dir:state}/token"}`,
|
||||
`"requires":["postgres-database"],"own-secrets":{"token":"${dir:state}/token"}`, 1)
|
||||
@@ -166,3 +166,10 @@ func TestAHandedModuleNamingARunTimeBoundKeyComposesOnlyWhereItIsHanded(t *testi
|
||||
t.Errorf("the impossible branch says %q (handed file %v)", why, handedFile)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandedBound runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestHandedBound(t *testing.T) {
|
||||
t.Run("AHandedModuleMayNameWhatItRequiresWhereItsProviderHasMoved", testAHandedModuleMayNameWhatItRequiresWhereItsProviderHasMoved)
|
||||
t.Run("AHandedModulesLocalCredentialsOfTheVaultAreNamedByLocalInItsPlan", testAHandedModulesLocalCredentialsOfTheVaultAreNamedByLocalInItsPlan)
|
||||
t.Run("AHandedModuleNamingARunTimeBoundKeyComposesOnlyWhereItIsHanded", testAHandedModuleNamingARunTimeBoundKeyComposesOnlyWhereItIsHanded)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func consumerOn(t *testing.T, m mcat.Manifest, w mcat.World) mcat.Resolution {
|
||||
// binding file names as `${bound:<provision>:name|internal-name|name-<local>|internal-name-<local>}`, so a moved
|
||||
// provider's helper copies them into the consumer's entry and the client fills the same text. A consumer
|
||||
// contributing no label has the entry it had.
|
||||
func TestAHandedModulesPlanEntryCarriesTheNamesComposedForIt(t *testing.T) {
|
||||
func testAHandedModulesPlanEntryCarriesTheNamesComposedForIt(t *testing.T) {
|
||||
m := notifierConsumer(t, true, false)
|
||||
m.ContributesMany = map[string]map[string]map[string]any{
|
||||
"postgres-database": {"web": {"label": "git"}, "api": {"label": "git-api"}}}
|
||||
@@ -82,7 +82,7 @@ func TestAHandedModulesPlanEntryCarriesTheNamesComposedForIt(t *testing.T) {
|
||||
|
||||
// A plan entry names the tool of an offer whose credential the provider's software issues (issue 928), so the vault
|
||||
// asks that tool for each holder; an offer of any other form names none.
|
||||
func TestAHandedModulesPlanNamesTheCredentialToolOfASoftwareIssuedOffer(t *testing.T) {
|
||||
func testAHandedModulesPlanNamesTheCredentialToolOfASoftwareIssuedOffer(t *testing.T) {
|
||||
for credential, want := range map[string]string{
|
||||
``: "",
|
||||
`,"credential":{"own":"admin"}`: "",
|
||||
@@ -109,3 +109,9 @@ func TestAHandedModulesPlanNamesTheCredentialToolOfASoftwareIssuedOffer(t *testi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandedProviders runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestHandedProviders(t *testing.T) {
|
||||
t.Run("AHandedModulesPlanEntryCarriesTheNamesComposedForIt", testAHandedModulesPlanEntryCarriesTheNamesComposedForIt)
|
||||
t.Run("AHandedModulesPlanNamesTheCredentialToolOfASoftwareIssuedOffer", testAHandedModulesPlanNamesTheCredentialToolOfASoftwareIssuedOffer)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func healthManifest(t *testing.T, on string, health map[string]any, more ...map[
|
||||
return raw
|
||||
}
|
||||
|
||||
func TestHealthIsComposedAsThePortThisMachineGaveTheEndpoint(t *testing.T) {
|
||||
func testHealthIsComposedAsThePortThisMachineGaveTheEndpoint(t *testing.T) {
|
||||
m, err := decodeForTest(healthManifest(t, "server", map[string]any{"kind": "http", "endpoint": "web", "path": "/healthz",
|
||||
"needs": "postgres-database"}))
|
||||
if err != nil {
|
||||
@@ -82,7 +82,7 @@ func TestHealthIsComposedAsThePortThisMachineGaveTheEndpoint(t *testing.T) {
|
||||
|
||||
// What the controller composes the node-engine takes: every kind, composed for an engine that reads it,
|
||||
// passes the engine's own validator (mesh-host/validate) — one set of words on both sides.
|
||||
func TestEveryComposedHealthIsOneTheNodeEngineTakes(t *testing.T) {
|
||||
func testEveryComposedHealthIsOneTheNodeEngineTakes(t *testing.T) {
|
||||
for _, h := range []map[string]any{
|
||||
{"kind": "http", "endpoint": "web", "path": "/healthz", "status": 200, "body": "ok", "needs": "postgres-database"},
|
||||
{"kind": "tcp", "endpoint": "web", "interval": "10s", "timeout": "2s", "looks": 2, "grace": "0s"},
|
||||
@@ -102,3 +102,9 @@ func TestEveryComposedHealthIsOneTheNodeEngineTakes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestHealth runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestHealth(t *testing.T) {
|
||||
t.Run("HealthIsComposedAsThePortThisMachineGaveTheEndpoint", testHealthIsComposedAsThePortThisMachineGaveTheEndpoint)
|
||||
t.Run("EveryComposedHealthIsOneTheNodeEngineTakes", testEveryComposedHealthIsOneTheNodeEngineTakes)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func newBroker() mcat.Manifest {
|
||||
}
|
||||
|
||||
// Nothing on record: exactly the old rule. One claimant holds; two are refused.
|
||||
func TestWithNoHolderOnRecordTheSoleClaimantHoldsAndTwoAreRefused(t *testing.T) {
|
||||
func testWithNoHolderOnRecordTheSoleClaimantHoldsAndTwoAreRefused(t *testing.T) {
|
||||
busSeatDelivering(t, "mesh-bus")
|
||||
node := mcat.Node{Name: "anchor"}
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestWithNoHolderOnRecordTheSoleClaimantHoldsAndTwoAreRefused(t *testing.T)
|
||||
}
|
||||
|
||||
// With a holder on record, the other eligible assignment is silent: not refused, and not holding.
|
||||
func TestTheHolderOnRecordHoldsAndTheOtherClaimantStandsBesideIt(t *testing.T) {
|
||||
func testTheHolderOnRecordHoldsAndTheOtherClaimantStandsBesideIt(t *testing.T) {
|
||||
busSeatDelivering(t, "mesh-bus")
|
||||
node := mcat.Node{Name: "anchor"}
|
||||
record := []mcat.Held{{Claim: "mesh-broker", Scope: mcat.ScopeMesh, Node: "anchor", Module: "new-broker"}}
|
||||
@@ -61,7 +61,7 @@ func TestTheHolderOnRecordHoldsAndTheOtherClaimantStandsBesideIt(t *testing.T) {
|
||||
|
||||
// The record names a node too: an eligible module on another machine holds nothing, and its
|
||||
// machine's set still resolves.
|
||||
func TestAHolderOnRecordElsewhereLeavesThisMachinesClaimantSilent(t *testing.T) {
|
||||
func testAHolderOnRecordElsewhereLeavesThisMachinesClaimantSilent(t *testing.T) {
|
||||
busSeatDelivering(t, "mesh-bus")
|
||||
record := []mcat.Held{{Claim: "mesh-broker", Scope: mcat.ScopeMesh, Node: "anchor", Module: "new-broker"}}
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestAHolderOnRecordElsewhereLeavesThisMachinesClaimantSilent(t *testing.T)
|
||||
|
||||
// A machine being moved is handed its membership for the new bus as a sealed file in its own
|
||||
// declaration — the machine's, not any module's (design 28, task 5.2).
|
||||
func TestAMembershipForTheNewBusIsComposedAsASealedFile(t *testing.T) {
|
||||
func testAMembershipForTheNewBusIsComposedAsASealedFile(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor"}
|
||||
got, err := Compose(r, mcat.Rendering{BusMembership: "sealed-blob"})
|
||||
if err != nil {
|
||||
@@ -101,7 +101,7 @@ func TestAMembershipForTheNewBusIsComposedAsASealedFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestARefusalWithNothingOnRecordNamesTheHandover(t *testing.T) {
|
||||
func testARefusalWithNothingOnRecordNamesTheHandover(t *testing.T) {
|
||||
busSeatDelivering(t, "mesh-bus")
|
||||
elsewhere := []mcat.Held{{Claim: "mesh-broker", Scope: mcat.ScopeMesh, Node: "anchor", Module: "old-broker"}}
|
||||
|
||||
@@ -126,3 +126,12 @@ func brokerVerbs() []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// TestHoldings runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestHoldings(t *testing.T) {
|
||||
t.Run("WithNoHolderOnRecordTheSoleClaimantHoldsAndTwoAreRefused", testWithNoHolderOnRecordTheSoleClaimantHoldsAndTwoAreRefused)
|
||||
t.Run("TheHolderOnRecordHoldsAndTheOtherClaimantStandsBesideIt", testTheHolderOnRecordHoldsAndTheOtherClaimantStandsBesideIt)
|
||||
t.Run("AHolderOnRecordElsewhereLeavesThisMachinesClaimantSilent", testAHolderOnRecordElsewhereLeavesThisMachinesClaimantSilent)
|
||||
t.Run("AMembershipForTheNewBusIsComposedAsASealedFile", testAMembershipForTheNewBusIsComposedAsASealedFile)
|
||||
t.Run("ARefusalWithNothingOnRecordNamesTheHandover", testARefusalWithNothingOnRecordNamesTheHandover)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// A node's fail2ban jails are composed from the modules it runs (novox/hq to-be 31): the holder
|
||||
// (jailing) gathers every module's declared jail into one jail file and a filter file per jail.
|
||||
func TestJailsAreComposedFromTheNodesModules(t *testing.T) {
|
||||
func testJailsAreComposedFromTheNodesModules(t *testing.T) {
|
||||
modules := []mcat.Manifest{
|
||||
{Module: "fail2ban", Jailing: &mcat.Jailing{Into: "/etc/fail2ban/jail.d/mesh-composed.conf", FilterInto: "/etc/fail2ban/filter.d"}},
|
||||
{Module: "postgres", Jails: []mcat.Jail{{Name: "postgres-auth", Failregex: "auth failed from <HOST>", Jail: "port = 5432\nmaxretry = 5"}}},
|
||||
@@ -40,7 +40,7 @@ func TestJailsAreComposedFromTheNodesModules(t *testing.T) {
|
||||
|
||||
// A holder whose node runs no jail-declaring module still gets the file, empty — so removing the
|
||||
// last jail is a change the service restarts on, not a file that vanishes.
|
||||
func TestTheComposedJailFileIsWrittenEvenWhenEmpty(t *testing.T) {
|
||||
func testTheComposedJailFileIsWrittenEvenWhenEmpty(t *testing.T) {
|
||||
files := jailsInto([]mcat.Manifest{{Module: "fail2ban"}}, &mcat.Jailing{Into: "/x", FilterInto: "/f"})
|
||||
if len(files) != 1 || files[0]["id"] != mcat.ComposedJailsID() {
|
||||
t.Fatalf("the empty composed jail file was not written alone: %v", files)
|
||||
@@ -50,7 +50,7 @@ func TestTheComposedJailFileIsWrittenEvenWhenEmpty(t *testing.T) {
|
||||
// A changed pattern restarts fail2ban (novox/hq issue 191's rollout): the service restarts when the
|
||||
// composed jail file changes, and the filter is a file of its own, so the jail file names the
|
||||
// filter's digest. Changing only the failregex must change the jail file; the same pattern must not.
|
||||
func TestAChangedFilterChangesTheJailFile(t *testing.T) {
|
||||
func testAChangedFilterChangesTheJailFile(t *testing.T) {
|
||||
jailFile := func(failregex string) string {
|
||||
modules := []mcat.Manifest{
|
||||
{Module: "fail2ban", Jailing: &mcat.Jailing{Into: "/etc/fail2ban/jail.d/mesh.conf", FilterInto: "/etc/fail2ban/filter.d"}},
|
||||
@@ -72,3 +72,10 @@ func TestAChangedFilterChangesTheJailFile(t *testing.T) {
|
||||
t.Errorf("a changed pattern left the jail file as it was, so fail2ban keeps the old filter:\n%s", after)
|
||||
}
|
||||
}
|
||||
|
||||
// TestJailsInto runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestJailsInto(t *testing.T) {
|
||||
t.Run("JailsAreComposedFromTheNodesModules", testJailsAreComposedFromTheNodesModules)
|
||||
t.Run("TheComposedJailFileIsWrittenEvenWhenEmpty", testTheComposedJailFileIsWrittenEvenWhenEmpty)
|
||||
t.Run("AChangedFilterChangesTheJailFile", testAChangedFilterChangesTheJailFile)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func aModelUser() mcat.Manifest {
|
||||
// internet, so the rule that refuses two ends sharing no private network must not apply. This
|
||||
// node is deliberately not on the private network at all — under the old rule that alone would
|
||||
// refuse it.
|
||||
func TestAProvisionAnsweredByARecordDoesNotNeedAPrivateNetwork(t *testing.T) {
|
||||
func testAProvisionAnsweredByARecordDoesNotNeedAPrivateNetwork(t *testing.T) {
|
||||
got, err := Resolve(
|
||||
map[string]mcat.Manifest{"assistant": aModelUser()},
|
||||
[]string{"assistant"}, mcat.Node{Name: "workstation"}, mcat.World{
|
||||
@@ -45,7 +45,7 @@ func TestAProvisionAnsweredByARecordDoesNotNeedAPrivateNetwork(t *testing.T) {
|
||||
// Refused when the consumer has not said which — and the refusal names the candidates and the
|
||||
// command, because ADR 0024 warns this will be felt: a mesh holding three ways to reach a model
|
||||
// refuses every consumer that has not chosen.
|
||||
func TestAConsumerThatHasNotSaidWhichLicenceIsRefusedWithTheCandidates(t *testing.T) {
|
||||
func testAConsumerThatHasNotSaidWhichLicenceIsRefusedWithTheCandidates(t *testing.T) {
|
||||
_, err := Resolve(
|
||||
map[string]mcat.Manifest{"assistant": aModelUser()},
|
||||
[]string{"assistant"}, mcat.Node{Name: "workstation"}, mcat.World{Licences: map[string][]mcat.Record{"model-access": {
|
||||
@@ -63,7 +63,7 @@ func TestAConsumerThatHasNotSaidWhichLicenceIsRefusedWithTheCandidates(t *testin
|
||||
}
|
||||
|
||||
// A model the mesh runs itself answers it locally, and a record is not consulted.
|
||||
func TestAModelInTheMeshsOwnSetAnswersItWithoutALicence(t *testing.T) {
|
||||
func testAModelInTheMeshsOwnSetAnswersItWithoutALicence(t *testing.T) {
|
||||
got, err := Resolve(
|
||||
map[string]mcat.Manifest{
|
||||
"assistant": aModelUser(),
|
||||
@@ -85,7 +85,7 @@ func TestAModelInTheMeshsOwnSetAnswersItWithoutALicence(t *testing.T) {
|
||||
//
|
||||
// The mesh discarded the plaintext when the key was accepted and cannot seal another, so a
|
||||
// machine that resolved cleanly would receive no file and fail at whatever read it.
|
||||
func TestAModuleOnALicenceWithNoKeyIsRefusedRatherThanLeftEmpty(t *testing.T) {
|
||||
func testAModuleOnALicenceWithNoKeyIsRefusedRatherThanLeftEmpty(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "workstation",
|
||||
Modules: []mcat.Manifest{aModelUser()},
|
||||
@@ -101,7 +101,7 @@ func TestAModuleOnALicenceWithNoKeyIsRefusedRatherThanLeftEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
// And with a key, both files arrive: what is public, and what is not.
|
||||
func TestALicenceDeliversWhatIsPublicAndWhatIsSealed(t *testing.T) {
|
||||
func testALicenceDeliversWhatIsPublicAndWhatIsSealed(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "workstation",
|
||||
Modules: []mcat.Manifest{aModelUser()},
|
||||
@@ -151,7 +151,7 @@ func TestALicenceDeliversWhatIsPublicAndWhatIsSealed(t *testing.T) {
|
||||
// nothing — so refusing an unanswerable requirement there makes the machine disappear, and every
|
||||
// other machine is then told, wrongly, that the two of them share no network. A wrong answer about
|
||||
// a machine nobody asked about, caused by a fault on a third.
|
||||
func TestAnUnanswerableRequirementDoesNotRemoveAMachineFromTheMesh(t *testing.T) {
|
||||
func testAnUnanswerableRequirementDoesNotRemoveAMachineFromTheMesh(t *testing.T) {
|
||||
shelf := map[string]mcat.Manifest{
|
||||
"assistant": aModelUser(),
|
||||
"networking": {Module: "networking",
|
||||
@@ -187,7 +187,7 @@ func TestAnUnanswerableRequirementDoesNotRemoveAMachineFromTheMesh(t *testing.T)
|
||||
// consumer's needs — node scope set `local`, not `brokered`, so the delivering branch was skipped —
|
||||
// and the consumer's file was refused for naming a provision it "did not require". The endpoint is
|
||||
// keyless, but a port is still a fact nobody can invent.
|
||||
func TestAKeylessSameNodeProviderStillDeliversWhatItServes(t *testing.T) {
|
||||
func testAKeylessSameNodeProviderStillDeliversWhatItServes(t *testing.T) {
|
||||
provider := mcat.Manifest{Module: "local-model",
|
||||
Provides: []mcat.Offer{{Name: "model-access", Scope: mcat.ScopeNode}},
|
||||
Serves: map[string]map[string]any{
|
||||
@@ -257,3 +257,14 @@ func TestAKeylessSameNodeProviderStillDeliversWhatItServes(t *testing.T) {
|
||||
t.Fatalf("the bound file was not filled with the served endpoint, want %q:\n%s", want, env)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLicence runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestLicence(t *testing.T) {
|
||||
t.Run("AProvisionAnsweredByARecordDoesNotNeedAPrivateNetwork", testAProvisionAnsweredByARecordDoesNotNeedAPrivateNetwork)
|
||||
t.Run("AConsumerThatHasNotSaidWhichLicenceIsRefusedWithTheCandidates", testAConsumerThatHasNotSaidWhichLicenceIsRefusedWithTheCandidates)
|
||||
t.Run("AModelInTheMeshsOwnSetAnswersItWithoutALicence", testAModelInTheMeshsOwnSetAnswersItWithoutALicence)
|
||||
t.Run("AModuleOnALicenceWithNoKeyIsRefusedRatherThanLeftEmpty", testAModuleOnALicenceWithNoKeyIsRefusedRatherThanLeftEmpty)
|
||||
t.Run("ALicenceDeliversWhatIsPublicAndWhatIsSealed", testALicenceDeliversWhatIsPublicAndWhatIsSealed)
|
||||
t.Run("AnUnanswerableRequirementDoesNotRemoveAMachineFromTheMesh", testAnUnanswerableRequirementDoesNotRemoveAMachineFromTheMesh)
|
||||
t.Run("AKeylessSameNodeProviderStillDeliversWhatItServes", testAKeylessSameNodeProviderStillDeliversWhatItServes)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func judged(t *testing.T) []mcat.LocalNetwork {
|
||||
|
||||
// **A public subnet never counts** (ADR 0340 §2), and only a private one on a link facing outside does
|
||||
// (§3): the tunnel's and a bridge's are this machine's own, whatever their addresses.
|
||||
func TestOnlyAPrivateNetworkOnALinkFacingOutsideCounts(t *testing.T) {
|
||||
func testOnlyAPrivateNetworkOnALinkFacingOutsideCounts(t *testing.T) {
|
||||
got := CountedLocalNetworks(judged(t))
|
||||
want := []string{"192.168.1.0/24", "fd12:3456:789a::/64"}
|
||||
if strings.Join(got, " ") != strings.Join(want, " ") {
|
||||
@@ -79,7 +79,7 @@ func TestOnlyAPrivateNetworkOnALinkFacingOutsideCounts(t *testing.T) {
|
||||
|
||||
// **The filter admits the local network on that port's rule alone** (§5), beside the private network,
|
||||
// in both chains, and never the public subnet.
|
||||
func TestALocalNetworkPortIsAdmittedFromItsNetworksAndTheMesh(t *testing.T) {
|
||||
func testALocalNetworkPortIsAdmittedFromItsNetworksAndTheMesh(t *testing.T) {
|
||||
rules := []mcat.Rule{
|
||||
{Port: 1883, Protocol: "tcp", From: mcat.FromLocalNetwork, Because: []string{"mosquitto"}},
|
||||
{Port: 5432, Protocol: "tcp", From: mcat.FromMesh, Because: []string{"postgres"}},
|
||||
@@ -153,7 +153,7 @@ func TestALocalNetworkPortIsAdmittedFromItsNetworksAndTheMesh(t *testing.T) {
|
||||
|
||||
// **A fourth reach** (§4, changing ADR 0138 §4): `internal` with the local networks added to what the
|
||||
// filter opens — the internal name, not the public one.
|
||||
func TestTheLocalNetworkReachIsInternalWithTheLocalNetworkAdded(t *testing.T) {
|
||||
func testTheLocalNetworkReachIsInternalWithTheLocalNetworkAdded(t *testing.T) {
|
||||
public, internal := namesFor(t, aRoutedWeb(), reachSet(mcat.ReachLocalNetwork))
|
||||
if public != "" || internal != "app.anchor.internal" {
|
||||
t.Fatalf("names are %q and %q, want the internal name only", public, internal)
|
||||
@@ -172,7 +172,7 @@ func TestTheLocalNetworkReachIsInternalWithTheLocalNetworkAdded(t *testing.T) {
|
||||
|
||||
// Two modules wanting one port, one from the mesh and one from the local network, render one rule from
|
||||
// the local network: it covers the mesh, and anywhere covers it.
|
||||
func TestTheLocalNetworkSitsBetweenTheMeshAndAnywhere(t *testing.T) {
|
||||
func testTheLocalNetworkSitsBetweenTheMeshAndAnywhere(t *testing.T) {
|
||||
got := widest([]mcat.Rule{
|
||||
{Port: 53, Protocol: "udp", From: mcat.FromMesh, Because: []string{"a"}},
|
||||
{Port: 53, Protocol: "udp", From: mcat.FromLocalNetwork, Because: []string{"b"}},
|
||||
@@ -188,9 +188,18 @@ func TestTheLocalNetworkSitsBetweenTheMeshAndAnywhere(t *testing.T) {
|
||||
|
||||
// On an adopted node the opening is the private network's part only: the found firewall admits the
|
||||
// local network, and an opening that widened to everywhere would open the port to the internet.
|
||||
func TestAnAdoptedNodeOpensTheLocalNetworkPortToTheMeshOnly(t *testing.T) {
|
||||
func testAnAdoptedNodeOpensTheLocalNetworkPortToTheMeshOnly(t *testing.T) {
|
||||
out := Openings([]mcat.Rule{{Port: 1883, Protocol: "tcp", From: mcat.FromLocalNetwork}}, nil, nil)
|
||||
if len(out) != 1 || out[0]["from"] != mcat.OpeningFromMesh {
|
||||
t.Fatalf("openings %v", out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLocalnetwork runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestLocalnetwork(t *testing.T) {
|
||||
t.Run("OnlyAPrivateNetworkOnALinkFacingOutsideCounts", testOnlyAPrivateNetworkOnALinkFacingOutsideCounts)
|
||||
t.Run("ALocalNetworkPortIsAdmittedFromItsNetworksAndTheMesh", testALocalNetworkPortIsAdmittedFromItsNetworksAndTheMesh)
|
||||
t.Run("TheLocalNetworkReachIsInternalWithTheLocalNetworkAdded", testTheLocalNetworkReachIsInternalWithTheLocalNetworkAdded)
|
||||
t.Run("TheLocalNetworkSitsBetweenTheMeshAndAnywhere", testTheLocalNetworkSitsBetweenTheMeshAndAnywhere)
|
||||
t.Run("AnAdoptedNodeOpensTheLocalNetworkPortToTheMeshOnly", testAnAdoptedNodeOpensTheLocalNetworkPortToTheMeshOnly)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func authority() mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAModuleNamesTheMachineItWasAssignedTo(t *testing.T) {
|
||||
func testAModuleNamesTheMachineItWasAssignedTo(t *testing.T) {
|
||||
got, err := Resolve(shelf(authority()), []string{"authority"}, anchored(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -54,7 +54,7 @@ func TestAModuleNamesTheMachineItWasAssignedTo(t *testing.T) {
|
||||
|
||||
// A machine not on the private network has no such address, and a module asking to be reached at
|
||||
// one is named here rather than left to fail later as a certificate nobody can verify.
|
||||
func TestAnAddressAMachineDoesNotHaveIsRefused(t *testing.T) {
|
||||
func testAnAddressAMachineDoesNotHaveIsRefused(t *testing.T) {
|
||||
got, err := Resolve(shelf(authority()), []string{"authority"}, workstation(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -70,7 +70,7 @@ func TestAnAddressAMachineDoesNotHaveIsRefused(t *testing.T) {
|
||||
// the container runtime at itself, whose list of resolvers cannot be a name — says
|
||||
// ${machine:address}, and gets what the machine's name resolves to on the private network: the same
|
||||
// address every other machine's hosts file carries for it.
|
||||
func TestAModuleNamesTheAddressBehindItsMachinesName(t *testing.T) {
|
||||
func testAModuleNamesTheAddressBehindItsMachinesName(t *testing.T) {
|
||||
pointing := mcat.Manifest{Module: "pointing", Version: "1", Resources: []map[string]any{{
|
||||
"id": "runtime", "type": "file", "path": "/etc/runtime.json",
|
||||
"content": `{"dns":["${machine:address}"]}`,
|
||||
@@ -101,7 +101,7 @@ func TestAModuleNamesTheAddressBehindItsMachinesName(t *testing.T) {
|
||||
|
||||
// The mesh's private range is offered as ${machine:mesh-range}, so a module names it rather than
|
||||
// hardcoding a value it cannot know (novox/hq ADR 0112) — the fail2ban ignoreip is the case.
|
||||
func TestAModuleNamesTheMeshRange(t *testing.T) {
|
||||
func testAModuleNamesTheMeshRange(t *testing.T) {
|
||||
facts := machineFacts(mcat.Resolution{Node: "anchor", At: "anchor.internal"}, map[string]string{"anchor.internal": "10.10.0.1"}, "10.10.0.0/24")
|
||||
if facts["mesh-range"] != "10.10.0.0/24" {
|
||||
t.Fatalf("the mesh range is not a machine fact: %v", facts)
|
||||
@@ -120,3 +120,11 @@ func TestAModuleNamesTheMeshRange(t *testing.T) {
|
||||
t.Fatal("a mesh with no range still offered one")
|
||||
}
|
||||
}
|
||||
|
||||
// TestMachineIntoFiles runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestMachineIntoFiles(t *testing.T) {
|
||||
t.Run("AModuleNamesTheMachineItWasAssignedTo", testAModuleNamesTheMachineItWasAssignedTo)
|
||||
t.Run("AnAddressAMachineDoesNotHaveIsRefused", testAnAddressAMachineDoesNotHaveIsRefused)
|
||||
t.Run("AModuleNamesTheAddressBehindItsMachinesName", testAModuleNamesTheAddressBehindItsMachinesName)
|
||||
t.Run("AModuleNamesTheMeshRange", testAModuleNamesTheMeshRange)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func needy() mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAModulesOwnSecretLandsSealed(t *testing.T) {
|
||||
func testAModulesOwnSecretLandsSealed(t *testing.T) {
|
||||
got, err := Resolve(shelf(needy()), []string{"postgres"}, reachable(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -43,7 +43,7 @@ func TestAModulesOwnSecretLandsSealed(t *testing.T) {
|
||||
t.Fatalf("no secret was written: %v", out)
|
||||
}
|
||||
|
||||
func TestADeclaredNeedThatWasNotMadeIsRefused(t *testing.T) {
|
||||
func testADeclaredNeedThatWasNotMadeIsRefused(t *testing.T) {
|
||||
// Skipping it would start a database with no password it knows, which fails to authenticate
|
||||
// three layers from the machine reporting it.
|
||||
got, _ := Resolve(shelf(needy()), []string{"postgres"}, reachable(), mcat.World{})
|
||||
@@ -56,7 +56,7 @@ func TestADeclaredNeedThatWasNotMadeIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAModuleMayNeedSeveralThings(t *testing.T) {
|
||||
func testAModuleMayNeedSeveralThings(t *testing.T) {
|
||||
// A password and a token, say. Telling them apart is the module's business, not the mesh's.
|
||||
m := needy()
|
||||
m.OwnSecrets["replication"] = mcat.OwnSecret{Path: "/var/lib/mesh/postgres/replication"}
|
||||
@@ -77,3 +77,10 @@ func TestAModuleMayNeedSeveralThings(t *testing.T) {
|
||||
t.Fatalf("two needs did not land as two secrets: %v", seen)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNeeds runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestNeeds(t *testing.T) {
|
||||
t.Run("AModulesOwnSecretLandsSealed", testAModulesOwnSecretLandsSealed)
|
||||
t.Run("ADeclaredNeedThatWasNotMadeIsRefused", testADeclaredNeedThatWasNotMadeIsRefused)
|
||||
t.Run("AModuleMayNeedSeveralThings", testAModuleMayNeedSeveralThings)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func splitDNSLaptop() mcat.Node {
|
||||
|
||||
// Where a module holds node-resolver, the machine is composed one resolver file, the holder's, naming
|
||||
// the machine's own address; the uplink's holder composes everything else it declares, and not that file.
|
||||
func TestWhereTheResolverIsHeldItWritesTheFileAndTheUplinkStepsBack(t *testing.T) {
|
||||
func testWhereTheResolverIsHeldItWritesTheFileAndTheUplinkStepsBack(t *testing.T) {
|
||||
shelf := resolverShelf(t)
|
||||
shelf["local-resolver"] = localResolver()
|
||||
got, err := Resolve(shelf, []string{"dnsmasq", "systemd-networkd", "local-resolver"}, splitDNSLaptop(), mcat.World{})
|
||||
@@ -65,7 +65,7 @@ func TestWhereTheResolverIsHeldItWritesTheFileAndTheUplinkStepsBack(t *testing.T
|
||||
|
||||
// Where nobody holds it, nothing changes: the uplink's holder writes the file, listing the mesh's
|
||||
// resolvers (ADR 0223) — every machine but the one that requires split-dns.
|
||||
func TestWithoutTheResolverTheUplinkWritesTheFileAsBefore(t *testing.T) {
|
||||
func testWithoutTheResolverTheUplinkWritesTheFileAsBefore(t *testing.T) {
|
||||
got, err := Resolve(resolverShelf(t), []string{"dnsmasq", "systemd-networkd"}, splitDNSLaptop(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -86,7 +86,7 @@ func TestWithoutTheResolverTheUplinkWritesTheFileAsBefore(t *testing.T) {
|
||||
// Only the uplink's holder steps back. A third module rendering or declaring the file beside the
|
||||
// resolver's is two owners of one path, refused as before; and a module rendering it without holding
|
||||
// the seat is not the resolver, so the uplink's holder does not step back for it.
|
||||
func TestOnlyTheUplinkStepsBackForTheResolver(t *testing.T) {
|
||||
func testOnlyTheUplinkStepsBackForTheResolver(t *testing.T) {
|
||||
uplink := mcat.Manifest{Module: "uplink", Version: "1", Claims: []mcat.Claim{{Name: "node-uplink"}},
|
||||
Facts: map[string]mcat.RosterFile{"resolvers": {Path: mcat.ResolverFile, Template: "nameserver 10.42.0.1\n"}}}
|
||||
if p := checkResources([]mcat.Manifest{uplink, localResolver()}); len(p) != 0 {
|
||||
@@ -119,7 +119,7 @@ func TestOnlyTheUplinkStepsBackForTheResolver(t *testing.T) {
|
||||
// (its header is how the uplink's verb and the node-engine read a file as the mesh's), and provides
|
||||
// split-dns at the machine's reach — a requirement is answered only on the same machine and never pulls
|
||||
// the resolver in. Skipped while the catalogue has no holder.
|
||||
func TestTheCataloguesResolverHoldersWriteTheFileAndProvideSplitDNS(t *testing.T) {
|
||||
func testTheCataloguesResolverHoldersWriteTheFileAndProvideSplitDNS(t *testing.T) {
|
||||
held := 0
|
||||
for _, m := range theCatalogue(t) {
|
||||
if !holdsSeat(m, mcat.ResolverSeat) {
|
||||
@@ -148,7 +148,7 @@ func TestTheCataloguesResolverHoldersWriteTheFileAndProvideSplitDNS(t *testing.T
|
||||
// The catalogue's systemd-resolved, composed on a machine beside its uplink: the resolver file names the
|
||||
// machine's own private address alone, its kept copy is the same file, and resolved is given every mesh
|
||||
// resolver as its default route and the private address to listen on. Skipped without the catalogue.
|
||||
func TestTheCataloguesResolverComposesOnAMachine(t *testing.T) {
|
||||
func testTheCataloguesResolverComposesOnAMachine(t *testing.T) {
|
||||
shelf := resolverShelf(t)
|
||||
shelf["systemd-resolved"] = catalogueManifest(t, "systemd-resolved")
|
||||
// The options line is the catalogue's own template's, never a literal of it here (design 50 resolver-wait §3).
|
||||
@@ -192,3 +192,12 @@ func TestTheCataloguesResolverComposesOnAMachine(t *testing.T) {
|
||||
t.Errorf("the mesh's domain is rendered as %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNodeResolver runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestNodeResolver(t *testing.T) {
|
||||
t.Run("WhereTheResolverIsHeldItWritesTheFileAndTheUplinkStepsBack", testWhereTheResolverIsHeldItWritesTheFileAndTheUplinkStepsBack)
|
||||
t.Run("WithoutTheResolverTheUplinkWritesTheFileAsBefore", testWithoutTheResolverTheUplinkWritesTheFileAsBefore)
|
||||
t.Run("OnlyTheUplinkStepsBackForTheResolver", testOnlyTheUplinkStepsBackForTheResolver)
|
||||
t.Run("TheCataloguesResolverHoldersWriteTheFileAndProvideSplitDNS", testTheCataloguesResolverHoldersWriteTheFileAndProvideSplitDNS)
|
||||
t.Run("TheCataloguesResolverComposesOnAMachine", testTheCataloguesResolverComposesOnAMachine)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func optionalShelf() map[string]mcat.Manifest {
|
||||
)
|
||||
}
|
||||
|
||||
func TestAnOptionalRequirementWithNoProviderIsAbsentAndNothingIsInstalled(t *testing.T) {
|
||||
func testAnOptionalRequirementWithNoProviderIsAbsentAndNothingIsInstalled(t *testing.T) {
|
||||
// Exactly one catalogue module could answer each — the case where a hard requirement installs it.
|
||||
// Brokered (influxdb-api, from anywhere) and on this machine (shell); both passes.
|
||||
for _, world := range []mcat.World{{}, {Unchecked: true}} {
|
||||
@@ -40,7 +40,7 @@ func TestAnOptionalRequirementWithNoProviderIsAbsentAndNothingIsInstalled(t *tes
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnOptionalRequirementWithAProviderBindsAsAHardOne(t *testing.T) {
|
||||
func testAnOptionalRequirementWithAProviderBindsAsAHardOne(t *testing.T) {
|
||||
world := mcat.World{Offered: map[string][]mcat.Provider{"influxdb-api": {
|
||||
{Node: "anchor", At: "anchor.internal", Module: "influxdb", Serves: map[string]any{"port": 8086}}}}}
|
||||
got, err := Resolve(optionalShelf(), []string{"grafana", "zsh"}, reachable(), world)
|
||||
@@ -64,7 +64,7 @@ func TestAnOptionalRequirementWithAProviderBindsAsAHardOne(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneConsumersOptionalRequirementIsAnothersHardOne(t *testing.T) {
|
||||
func testOneConsumersOptionalRequirementIsAnothersHardOne(t *testing.T) {
|
||||
// telegraf wants influxdb-api hard: with nothing offering it, the assignment is refused as
|
||||
// before, naming what to assign — grafana's optional does not soften telegraf's.
|
||||
_, err := Resolve(optionalShelf(), []string{"grafana", "telegraf"}, reachable(), mcat.World{})
|
||||
@@ -91,7 +91,7 @@ func TestOneConsumersOptionalRequirementIsAnothersHardOne(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAHardRequirementWithNoProviderIsStillRefused(t *testing.T) {
|
||||
func testAHardRequirementWithNoProviderIsStillRefused(t *testing.T) {
|
||||
_, err := Resolve(optionalShelf(), []string{"telegraf"}, reachable(), mcat.World{})
|
||||
if err == nil || !strings.Contains(err.Error(), "influxdb") {
|
||||
t.Fatalf("got %v", err)
|
||||
@@ -124,7 +124,7 @@ func absentGrafana(t *testing.T, absent bool) mcat.Resolution {
|
||||
return r
|
||||
}
|
||||
|
||||
func TestAnAbsentRequirementIsComposedWithItsDefaultsAndWithoutItsFiles(t *testing.T) {
|
||||
func testAnAbsentRequirementIsComposedWithItsDefaultsAndWithoutItsFiles(t *testing.T) {
|
||||
out, err := Declaration(absentGrafana(t, true), mcat.Rendering{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -145,7 +145,7 @@ func TestAnAbsentRequirementIsComposedWithItsDefaultsAndWithoutItsFiles(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
func TestABoundOptionalRequirementIsComposedAsAHardOne(t *testing.T) {
|
||||
func testABoundOptionalRequirementIsComposedAsAHardOne(t *testing.T) {
|
||||
out, err := Declaration(absentGrafana(t, false), mcat.Rendering{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -166,3 +166,13 @@ func TestABoundOptionalRequirementIsComposedAsAHardOne(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestOptionalRequirements runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestOptionalRequirements(t *testing.T) {
|
||||
t.Run("AnOptionalRequirementWithNoProviderIsAbsentAndNothingIsInstalled", testAnOptionalRequirementWithNoProviderIsAbsentAndNothingIsInstalled)
|
||||
t.Run("AnOptionalRequirementWithAProviderBindsAsAHardOne", testAnOptionalRequirementWithAProviderBindsAsAHardOne)
|
||||
t.Run("OneConsumersOptionalRequirementIsAnothersHardOne", testOneConsumersOptionalRequirementIsAnothersHardOne)
|
||||
t.Run("AHardRequirementWithNoProviderIsStillRefused", testAHardRequirementWithNoProviderIsStillRefused)
|
||||
t.Run("AnAbsentRequirementIsComposedWithItsDefaultsAndWithoutItsFiles", testAnAbsentRequirementIsComposedWithItsDefaultsAndWithoutItsFiles)
|
||||
t.Run("ABoundOptionalRequirementIsComposedAsAHardOne", testABoundOptionalRequirementIsComposedAsAHardOne)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func resourceNamed(out []map[string]any, name string) map[string]any {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestAnOutsideSecretNotGivenIsNoFileAndAFileNamingItSaysEmpty(t *testing.T) {
|
||||
func testAnOutsideSecretNotGivenIsNoFileAndAFileNamingItSaysEmpty(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "server", Modules: []mcat.Manifest{outsideManifest(t)}}
|
||||
out, err := Declaration(r, mcat.Rendering{Needed: map[string]map[string]string{"assistant": {"password": "sealed-password"}}})
|
||||
if err != nil {
|
||||
@@ -70,7 +70,7 @@ func TestAnOutsideSecretNotGivenIsNoFileAndAFileNamingItSaysEmpty(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnOutsideSecretGivenIsPlacedAndFilled(t *testing.T) {
|
||||
func testAnOutsideSecretGivenIsPlacedAndFilled(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "server", Modules: []mcat.Manifest{outsideManifest(t)}}
|
||||
out, err := Declaration(r, mcat.Rendering{Needed: map[string]map[string]string{"assistant": {
|
||||
"password": "sealed-password", "vendor-key": "sealed-vendor-key"}}})
|
||||
@@ -95,10 +95,17 @@ func TestAnOutsideSecretGivenIsPlacedAndFilled(t *testing.T) {
|
||||
}
|
||||
|
||||
// A secret the mesh makes is still refused when it was not made: only an outside one is left out.
|
||||
func TestAnOwnSecretTheMeshMakesIsStillRefusedWhenNotMade(t *testing.T) {
|
||||
func testAnOwnSecretTheMeshMakesIsStillRefusedWhenNotMade(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "server", Modules: []mcat.Manifest{outsideManifest(t)}}
|
||||
_, err := Declaration(r, mcat.Rendering{})
|
||||
if nm, ok := err.(*NotMadeError); !ok || nm.Name != "password" {
|
||||
t.Fatalf("a secret the mesh makes, not made: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOutsideNotGiven runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestOutsideNotGiven(t *testing.T) {
|
||||
t.Run("AnOutsideSecretNotGivenIsNoFileAndAFileNamingItSaysEmpty", testAnOutsideSecretNotGivenIsNoFileAndAFileNamingItSaysEmpty)
|
||||
t.Run("AnOutsideSecretGivenIsPlacedAndFilled", testAnOutsideSecretGivenIsPlacedAndFilled)
|
||||
t.Run("AnOwnSecretTheMeshMakesIsStillRefusedWhenNotMade", testAnOwnSecretTheMeshMakesIsStillRefusedWhenNotMade)
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func fileAt(t *testing.T, out []map[string]any, path string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func TestAModuleIsToldTheNameItsProviderServes(t *testing.T) {
|
||||
func testAModuleIsToldTheNameItsProviderServes(t *testing.T) {
|
||||
got, err := Resolve(shelf(servingProxy(), selfAware("git")), []string{"traefik", "board"},
|
||||
onBoth("example.tld"), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -83,7 +83,7 @@ func TestAModuleIsToldTheNameItsProviderServes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheNameAModuleIsToldFollowsTheNodesDomain(t *testing.T) {
|
||||
func testTheNameAModuleIsToldFollowsTheNodesDomain(t *testing.T) {
|
||||
// The whole point: the same definition, two machines, two names — nothing edited.
|
||||
for _, domain := range []string{"example.tld", "other.example"} {
|
||||
got, err := Resolve(shelf(servingProxy(), selfAware("git")), []string{"traefik", "board"},
|
||||
@@ -98,7 +98,7 @@ func TestTheNameAModuleIsToldFollowsTheNodesDomain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAModuleWithNoPublicNameIsNotToldOne(t *testing.T) {
|
||||
func testAModuleWithNoPublicNameIsNotToldOne(t *testing.T) {
|
||||
// No public domain on the node: nothing composed, so no `name` — and a file asking for one is
|
||||
// refused rather than rendered with a placeholder or an empty host.
|
||||
m := selfAware("git")
|
||||
@@ -113,7 +113,7 @@ func TestAModuleWithNoPublicNameIsNotToldOne(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAModuleIsToldItsNameByANodeScopedProviderToo(t *testing.T) {
|
||||
func testAModuleIsToldItsNameByANodeScopedProviderToo(t *testing.T) {
|
||||
m := selfAware("git")
|
||||
m.Resources[0]["content"] = "root = https://${bound:reverse-proxy:name}/\n"
|
||||
got, err := Resolve(shelf(nodeProxy(), m), []string{"board"},
|
||||
@@ -126,3 +126,11 @@ func TestAModuleIsToldItsNameByANodeScopedProviderToo(t *testing.T) {
|
||||
t.Fatalf("a same-machine, node-scoped answer did not tell the module its name: %q", conf)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOwnName runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestOwnName(t *testing.T) {
|
||||
t.Run("AModuleIsToldTheNameItsProviderServes", testAModuleIsToldTheNameItsProviderServes)
|
||||
t.Run("TheNameAModuleIsToldFollowsTheNodesDomain", testTheNameAModuleIsToldFollowsTheNodesDomain)
|
||||
t.Run("AModuleWithNoPublicNameIsNotToldOne", testAModuleWithNoPublicNameIsNotToldOne)
|
||||
t.Run("AModuleIsToldItsNameByANodeScopedProviderToo", testAModuleIsToldItsNameByANodeScopedProviderToo)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func mailSenderManifest(t *testing.T, own string) mcat.Manifest {
|
||||
|
||||
// 1170/AC1: a family owned by the module's own account lands at 0600, owned by that account — and a module's
|
||||
// other own secrets (no per-secret owner declared) keep secrets-owner, unchanged.
|
||||
func TestAnOwnSecretsOwnerIsGivenToItsFiles(t *testing.T) {
|
||||
func testAnOwnSecretsOwnerIsGivenToItsFiles(t *testing.T) {
|
||||
// ADR 0680 §1, §4: the owner is the account the manifest names: one the module makes, the operator account
|
||||
// (`${machine:account}`, filled with the machine's account) or root.
|
||||
for _, c := range []struct{ name, owner, account, want string }{
|
||||
@@ -79,7 +79,7 @@ func TestAnOwnSecretsOwnerIsGivenToItsFiles(t *testing.T) {
|
||||
|
||||
// 1170/AC3: a manifest with no owner on any own secret composes exactly as it did before this clause existed:
|
||||
// every secret file belongs to the module's secrets-owner (or nothing, when that is absent too).
|
||||
func TestNoOwnerOnAnySecretComposesAsMainDoes(t *testing.T) {
|
||||
func testNoOwnerOnAnySecretComposesAsMainDoes(t *testing.T) {
|
||||
m := mailSenderManifest(t, "")
|
||||
r := mcat.Resolution{Node: "novox", Modules: []mcat.Manifest{m}}
|
||||
out, err := Declaration(r, mcat.Rendering{
|
||||
@@ -101,3 +101,9 @@ func TestNoOwnerOnAnySecretComposesAsMainDoes(t *testing.T) {
|
||||
t.Fatalf("the family member was not composed at all: %v", out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOwnSecretOwner runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestOwnSecretOwner(t *testing.T) {
|
||||
t.Run("AnOwnSecretsOwnerIsGivenToItsFiles", testAnOwnSecretsOwnerIsGivenToItsFiles)
|
||||
t.Run("NoOwnerOnAnySecretComposesAsMainDoes", testNoOwnerOnAnySecretComposesAsMainDoes)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func twoIssuersOnOneNode() map[string][]mcat.Provider {
|
||||
}}
|
||||
}
|
||||
|
||||
func TestTwoProvidersOnOneNodeAreRefusedWithBothNamed(t *testing.T) {
|
||||
func testTwoProvidersOnOneNodeAreRefusedWithBothNamed(t *testing.T) {
|
||||
// The refusal must name the pair, because a node alone cannot tell them apart.
|
||||
_, err := Resolve(issuerShelf(), []string{"route-proxy"}, reachable(), mcat.World{Offered: twoIssuersOnOneNode()})
|
||||
if err == nil {
|
||||
@@ -34,7 +34,7 @@ func TestTwoProvidersOnOneNodeAreRefusedWithBothNamed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPinNamesTheModule(t *testing.T) {
|
||||
func testAPinNamesTheModule(t *testing.T) {
|
||||
got, err := Resolve(issuerShelf(), []string{"route-proxy"}, reachable(), mcat.World{Offered: twoIssuersOnOneNode(),
|
||||
Pinned: map[string]mcat.Chosen{"acme-ca": {Node: "novox", Module: "public-acme"}}})
|
||||
if err != nil {
|
||||
@@ -45,7 +45,7 @@ func TestAPinNamesTheModule(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestARecordNamingOnlyTheNodeIsRefusedWhenThatNodeAnswersTwice(t *testing.T) {
|
||||
func testARecordNamingOnlyTheNodeIsRefusedWhenThatNodeAnswersTwice(t *testing.T) {
|
||||
// A pin from before the module was asked for. It once took the last one listed — a coin flip.
|
||||
_, err := Resolve(issuerShelf(), []string{"route-proxy"}, reachable(), mcat.World{Offered: twoIssuersOnOneNode(), Pinned: map[string]mcat.Chosen{"acme-ca": {Node: "novox"}}})
|
||||
if err == nil {
|
||||
@@ -56,14 +56,14 @@ func TestARecordNamingOnlyTheNodeIsRefusedWhenThatNodeAnswersTwice(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPinNamingAModuleThatDoesNotProvideItIsRefused(t *testing.T) {
|
||||
func testAPinNamingAModuleThatDoesNotProvideItIsRefused(t *testing.T) {
|
||||
_, err := Resolve(issuerShelf(), []string{"route-proxy"}, reachable(), mcat.World{Offered: twoIssuersOnOneNode(), Pinned: map[string]mcat.Chosen{"acme-ca": {Node: "novox", Module: "gitea"}}})
|
||||
if err == nil || !strings.Contains(err.Error(), "novox/gitea does not provide it") {
|
||||
t.Fatalf("a module that does not provide it was not refused by name: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoProvidersBesideTheConsumerAreRefusedUntilOneIsNamed(t *testing.T) {
|
||||
func testTwoProvidersBesideTheConsumerAreRefusedUntilOneIsNamed(t *testing.T) {
|
||||
// The same ambiguity on the consumer's own machine. This was settled by a map walk — random,
|
||||
// per plan — which is how novox's own proxy got its issuer.
|
||||
_, err := Resolve(issuerShelf(), []string{"route-proxy", "public-acme", "step-ca"}, reachable(), mcat.World{})
|
||||
@@ -75,7 +75,7 @@ func TestTwoProvidersBesideTheConsumerAreRefusedUntilOneIsNamed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPinSettlesTwoProvidersBesideTheConsumer(t *testing.T) {
|
||||
func testAPinSettlesTwoProvidersBesideTheConsumer(t *testing.T) {
|
||||
got, err := Resolve(issuerShelf(), []string{"route-proxy", "public-acme", "step-ca"}, reachable(), mcat.World{Pinned: map[string]mcat.Chosen{"acme-ca": {Node: "workstation", Module: "public-acme"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -94,7 +94,7 @@ func TestAPinSettlesTwoProvidersBesideTheConsumer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheFirstPassDoesNotRefuseTwoProvidersBesideTheConsumer(t *testing.T) {
|
||||
func testTheFirstPassDoesNotRefuseTwoProvidersBesideTheConsumer(t *testing.T) {
|
||||
// The first pass answers only what a node offers. Refused there, the node vanishes from every
|
||||
// other node's world — and the whole mesh loses its vault for an ambiguity one machine has to
|
||||
// settle. The second pass is where it is refused, and the test above proves it is.
|
||||
@@ -102,3 +102,14 @@ func TestTheFirstPassDoesNotRefuseTwoProvidersBesideTheConsumer(t *testing.T) {
|
||||
t.Fatalf("the first pass refused what only the second may: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPinNamesModule runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestPinNamesModule(t *testing.T) {
|
||||
t.Run("TwoProvidersOnOneNodeAreRefusedWithBothNamed", testTwoProvidersOnOneNodeAreRefusedWithBothNamed)
|
||||
t.Run("APinNamesTheModule", testAPinNamesTheModule)
|
||||
t.Run("ARecordNamingOnlyTheNodeIsRefusedWhenThatNodeAnswersTwice", testARecordNamingOnlyTheNodeIsRefusedWhenThatNodeAnswersTwice)
|
||||
t.Run("APinNamingAModuleThatDoesNotProvideItIsRefused", testAPinNamingAModuleThatDoesNotProvideItIsRefused)
|
||||
t.Run("TwoProvidersBesideTheConsumerAreRefusedUntilOneIsNamed", testTwoProvidersBesideTheConsumerAreRefusedUntilOneIsNamed)
|
||||
t.Run("APinSettlesTwoProvidersBesideTheConsumer", testAPinSettlesTwoProvidersBesideTheConsumer)
|
||||
t.Run("TheFirstPassDoesNotRefuseTwoProvidersBesideTheConsumer", testTheFirstPassDoesNotRefuseTwoProvidersBesideTheConsumer)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// the machine with nothing to rewrite, so without a way to ask, every process binds the number in
|
||||
// its own configuration and two modules declaring the same one collide — which is the whole
|
||||
// problem ADR 0038 exists to prevent, reintroduced by the resource kind that most needs it.
|
||||
func TestAModuleIsToldWhichPortItWasGiven(t *testing.T) {
|
||||
func testAModuleIsToldWhichPortItWasGiven(t *testing.T) {
|
||||
file := map[string]any{
|
||||
"type": "file", "id": "settings",
|
||||
"content": "LISTEN=${port:8080}\n",
|
||||
@@ -34,7 +34,7 @@ func TestAModuleIsToldWhichPortItWasGiven(t *testing.T) {
|
||||
|
||||
// With nothing assigned yet, it is told the port it asked about — so a mesh that has not made an
|
||||
// assignment still composes something coherent rather than writing a zero.
|
||||
func TestWithNoAssignmentAModuleIsToldWhatItAskedFor(t *testing.T) {
|
||||
func testWithNoAssignmentAModuleIsToldWhatItAskedFor(t *testing.T) {
|
||||
file := map[string]any{"type": "file", "content": "LISTEN=${port:8080}\n"}
|
||||
if err := portInto(file, "showcase", []mcat.Listening{{Port: 8080}}, mcat.Rendering{}); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -47,7 +47,7 @@ func TestWithNoAssignmentAModuleIsToldWhatItAskedFor(t *testing.T) {
|
||||
// **Asking about a port it never declared is refused**, and the refusal says what it did declare.
|
||||
// The module is asking about something the mesh has no opinion on, and answering would be a guess
|
||||
// written into a configuration file as a port number.
|
||||
func TestAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
func testAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
file := map[string]any{"type": "file", "content": "LISTEN=${port:9999}\n"}
|
||||
err := portInto(file, "showcase", []mcat.Listening{{Port: 8080}}, mcat.Rendering{})
|
||||
if err == nil {
|
||||
@@ -59,7 +59,7 @@ func TestAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
}
|
||||
|
||||
// And a file mentioning no port is left exactly as it was.
|
||||
func TestAFileWithNoPortIsUntouched(t *testing.T) {
|
||||
func testAFileWithNoPortIsUntouched(t *testing.T) {
|
||||
file := map[string]any{"type": "file", "content": "GREETING=hello\n"}
|
||||
if err := portInto(file, "showcase", nil, mcat.Rendering{}); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -76,7 +76,7 @@ func TestAFileWithNoPortIsUntouched(t *testing.T) {
|
||||
// caller: the caller dials the machine, so it must be given the machine's number — here one the
|
||||
// node was given rather than one the mesh assigned, which is the case that makes the literal wrong
|
||||
// even on a mesh that never allocates (ADR 0100).
|
||||
func TestAContainerIsToldWhichPortItWasGiven(t *testing.T) {
|
||||
func testAContainerIsToldWhichPortItWasGiven(t *testing.T) {
|
||||
sidecar := map[string]any{
|
||||
"type": "container", "id": "runtime", "name": "mesh-gitea",
|
||||
"env": map[string]any{
|
||||
@@ -106,7 +106,7 @@ func TestAContainerIsToldWhichPortItWasGiven(t *testing.T) {
|
||||
// around it is a shallow copy. Filled in place, the first node composed would write its own port
|
||||
// into the catalogue and every node composed after it would be told that one — a fault that is
|
||||
// invisible in a single composition and wrong in every mesh with two machines.
|
||||
func TestFillingAContainersEnvironmentLeavesTheManifestAlone(t *testing.T) {
|
||||
func testFillingAContainersEnvironmentLeavesTheManifestAlone(t *testing.T) {
|
||||
env := map[string]any{"MESH_GITEA_URL": "http://127.0.0.1:${port:3000}"}
|
||||
manifest := map[string]any{"type": "container", "id": "runtime", "name": "mesh-gitea", "env": env}
|
||||
|
||||
@@ -132,7 +132,7 @@ func TestFillingAContainersEnvironmentLeavesTheManifestAlone(t *testing.T) {
|
||||
|
||||
// Asking in an environment about a port it never declared is refused exactly as a file's is, and
|
||||
// the refusal names the container and the variable — there is no line number to go on.
|
||||
func TestAContainerAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
func testAContainerAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
sidecar := map[string]any{
|
||||
"type": "container", "id": "runtime", "name": "mesh-gitea",
|
||||
"env": map[string]any{"MESH_GITEA_URL": "http://127.0.0.1:${port:9999}"},
|
||||
@@ -150,7 +150,7 @@ func TestAContainerAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
|
||||
// And a container naming no port keeps the environment it was written with — the same map, so
|
||||
// nothing is copied and no other node's composition is disturbed.
|
||||
func TestAContainerWithNoPortPlaceholderKeepsItsEnvironment(t *testing.T) {
|
||||
func testAContainerWithNoPortPlaceholderKeepsItsEnvironment(t *testing.T) {
|
||||
env := map[string]any{"MESH_GITEA_URL": "http://gitea:3000", "PORT": 3000}
|
||||
sidecar := map[string]any{"type": "container", "name": "mesh-gitea", "env": env}
|
||||
if err := portInto(sidecar, "gitea", []mcat.Listening{{Port: 3000}}, mcat.Rendering{
|
||||
@@ -170,3 +170,15 @@ func TestAContainerWithNoPortPlaceholderKeepsItsEnvironment(t *testing.T) {
|
||||
t.Fatalf("a container that asked for nothing had its environment rebuilt: %v", sidecar["env"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestPortInto runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestPortInto(t *testing.T) {
|
||||
t.Run("AModuleIsToldWhichPortItWasGiven", testAModuleIsToldWhichPortItWasGiven)
|
||||
t.Run("WithNoAssignmentAModuleIsToldWhatItAskedFor", testWithNoAssignmentAModuleIsToldWhatItAskedFor)
|
||||
t.Run("AskingAboutAnUndeclaredPortIsRefused", testAskingAboutAnUndeclaredPortIsRefused)
|
||||
t.Run("AFileWithNoPortIsUntouched", testAFileWithNoPortIsUntouched)
|
||||
t.Run("AContainerIsToldWhichPortItWasGiven", testAContainerIsToldWhichPortItWasGiven)
|
||||
t.Run("FillingAContainersEnvironmentLeavesTheManifestAlone", testFillingAContainersEnvironmentLeavesTheManifestAlone)
|
||||
t.Run("AContainerAskingAboutAnUndeclaredPortIsRefused", testAContainerAskingAboutAnUndeclaredPortIsRefused)
|
||||
t.Run("AContainerWithNoPortPlaceholderKeepsItsEnvironment", testAContainerWithNoPortPlaceholderKeepsItsEnvironment)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func processModule(env map[string]any) mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAProcessIsToldItsPortAndItsPlaceInItsEnvironment(t *testing.T) {
|
||||
func testAProcessIsToldItsPortAndItsPlaceInItsEnvironment(t *testing.T) {
|
||||
env := map[string]any{
|
||||
"SHOWCASE_URL": "http://127.0.0.1:${port:8080}",
|
||||
"SHOWCASE_DATA": "${dir:data}/objects",
|
||||
@@ -62,7 +62,7 @@ func TestAProcessIsToldItsPortAndItsPlaceInItsEnvironment(t *testing.T) {
|
||||
|
||||
// An unknown reference in a process's environment is refused as a container's is, naming the
|
||||
// process and the variable — left alone, it would reach the machine as a literal.
|
||||
func TestAProcessAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
func testAProcessAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
env := map[string]any{"SHOWCASE_URL": "http://127.0.0.1:${port:9999}"}
|
||||
_, err := Declaration(mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{processModule(env)}}, mcat.Rendering{})
|
||||
if err == nil {
|
||||
@@ -80,3 +80,9 @@ func TestAProcessAskingAboutAnUndeclaredPortIsRefused(t *testing.T) {
|
||||
t.Fatalf("a process naming no directory of its module was not refused: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestProcessEnv runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestProcessEnv(t *testing.T) {
|
||||
t.Run("AProcessIsToldItsPortAndItsPlaceInItsEnvironment", testAProcessIsToldItsPortAndItsPlaceInItsEnvironment)
|
||||
t.Run("AProcessAskingAboutAnUndeclaredPortIsRefused", testAProcessAskingAboutAnUndeclaredPortIsRefused)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func twoMergeableFiles(app, sidecar []any) mcat.Manifest {
|
||||
}
|
||||
|
||||
// The indexer's judge's proofs, items 1 to 13 of its list.
|
||||
func TestTheJudgesProofsOfAComposition(t *testing.T) {
|
||||
func testTheJudgesProofsOfAComposition(t *testing.T) {
|
||||
runtimeWith := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}, "dash": {"token": "sealed-token"}}}
|
||||
processOf := func(out []map[string]any) map[string]any {
|
||||
@@ -350,7 +350,7 @@ func TestTheJudgesProofsOfAComposition(t *testing.T) {
|
||||
}
|
||||
|
||||
// route-proxy's proofs, items 1 to 3 of its list.
|
||||
func TestRouteProxysProofsOfAComposition(t *testing.T) {
|
||||
func testRouteProxysProofsOfAComposition(t *testing.T) {
|
||||
proxy := mcat.Manifest{Module: "route-proxy", Version: "1",
|
||||
Provides: []mcat.Offer{{Name: "route", Scope: mcat.ScopeMesh, AnsweredBy: mcat.AnsweredByHelper}}}
|
||||
world := mcat.World{Offered: map[string][]mcat.Provider{"route": {{Node: "anchor", At: "anchor.internal", Module: "route-proxy"}}}}
|
||||
@@ -474,3 +474,9 @@ func TestRouteProxysProofsOfAComposition(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestProofs runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestProofs(t *testing.T) {
|
||||
t.Run("TheJudgesProofsOfAComposition", testTheJudgesProofsOfAComposition)
|
||||
t.Run("RouteProxysProofsOfAComposition", testRouteProxysProofsOfAComposition)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func namesFor(t *testing.T, m mcat.Manifest, settings mcat.SettingsBy) (public,
|
||||
// A routed endpoint's port is how the proxy reaches it and nothing else (ADR 0045): a public service
|
||||
// listens from the mesh, only the proxy reaches it, and it is exposed by name. So on a routed
|
||||
// endpoint the reach asks for a name and the port keeps what the manifest said.
|
||||
func TestAnUnroutedEndpointsPortFollowsItsReach(t *testing.T) {
|
||||
func testAnUnroutedEndpointsPortFollowsItsReach(t *testing.T) {
|
||||
// The same module with its route taken away: now the port is the only way in, so reach governs it.
|
||||
bare := aRoutedWeb()
|
||||
bare.Contributes = nil
|
||||
@@ -81,7 +81,7 @@ func TestAnUnroutedEndpointsPortFollowsItsReach(t *testing.T) {
|
||||
//
|
||||
// A module whose routed name must be public and whose machine-side port must not be had no way to say
|
||||
// so while one value drove both. Under one value it could not be expressed; the port would reopen.
|
||||
func TestAPublicNameLeavesARoutedPortAsTheManifestSaid(t *testing.T) {
|
||||
func testAPublicNameLeavesARoutedPortAsTheManifestSaid(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{aRoutedWeb()},
|
||||
PublicDomain: "example.test", At: "anchor.internal"}
|
||||
rules, err := Rules(r, mcat.Rendering{Settings: reachSet(mcat.ReachPublic)})
|
||||
@@ -103,7 +103,7 @@ func TestAPublicNameLeavesARoutedPortAsTheManifestSaid(t *testing.T) {
|
||||
|
||||
// A reach for a port the module does not listen on reaches nothing, and is refused where it is
|
||||
// written rather than accepted and ignored.
|
||||
func TestAReachForAPortTheModuleDoesNotListenOnIsRefused(t *testing.T) {
|
||||
func testAReachForAPortTheModuleDoesNotListenOnIsRefused(t *testing.T) {
|
||||
_, err := Reaches(aRoutedWeb(), []mcat.Layer{{From: "node anchor",
|
||||
Placement: map[string]any{mcat.ReachSetting: map[string]any{"9999": mcat.ReachInternal}}}})
|
||||
if err == nil || !strings.Contains(err.Error(), "reaches nothing") {
|
||||
@@ -114,7 +114,7 @@ func TestAReachForAPortTheModuleDoesNotListenOnIsRefused(t *testing.T) {
|
||||
// A value that is not a reach is refused, and the refusal names the four so a reader is one edit from
|
||||
// right. "mesh" is the tempting wrong answer, because that is the filter's word for nearly the same
|
||||
// thing.
|
||||
func TestAValueThatIsNotAReachIsRefused(t *testing.T) {
|
||||
func testAValueThatIsNotAReachIsRefused(t *testing.T) {
|
||||
for _, wrong := range []string{"mesh", "anywhere", "private", "true"} {
|
||||
_, err := Reaches(aRoutedWeb(), []mcat.Layer{{From: "node anchor",
|
||||
Placement: map[string]any{mcat.ReachSetting: map[string]any{"3000": wrong}}}})
|
||||
@@ -127,7 +127,7 @@ func TestAValueThatIsNotAReachIsRefused(t *testing.T) {
|
||||
// **A port that says both reach and expose is refused.** They say the same thing in different words,
|
||||
// and accepting both would have the filter follow one while the names followed the other — the
|
||||
// disagreement ADR 0138 exists to remove, reintroduced by the migration away from the older word.
|
||||
func TestReachAndExposeForOnePortAreRefused(t *testing.T) {
|
||||
func testReachAndExposeForOnePortAreRefused(t *testing.T) {
|
||||
_, err := Reaches(aRoutedWeb(), []mcat.Layer{{From: "node anchor", Placement: map[string]any{mcat.ReachSetting: map[string]any{"3000": mcat.ReachInternal}, mcat.ExposeSetting: map[string]any{"3000": mcat.FromEverywhere}}}})
|
||||
if err == nil || !strings.Contains(err.Error(), "same thing in different") {
|
||||
t.Fatalf("a port set both ways was accepted: %v", err)
|
||||
@@ -136,7 +136,7 @@ func TestReachAndExposeForOnePortAreRefused(t *testing.T) {
|
||||
|
||||
// A path-level refusal carries no port: it is a rule about a name, not an endpoint, and it inherits
|
||||
// whatever that name turned out to be. Narrowing the endpoint must not silently drop it.
|
||||
func TestARuleWithNoPortIsLeftAlone(t *testing.T) {
|
||||
func testARuleWithNoPortIsLeftAlone(t *testing.T) {
|
||||
m := aRoutedWeb()
|
||||
m.ContributesMany = map[string]map[string]map[string]any{
|
||||
"route": {"refused": {"label": "app", "path": "/internal", "deny": true}},
|
||||
@@ -161,3 +161,13 @@ func TestARuleWithNoPortIsLeftAlone(t *testing.T) {
|
||||
t.Fatal("the path rule was dropped")
|
||||
}
|
||||
}
|
||||
|
||||
// TestReach runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestReach(t *testing.T) {
|
||||
t.Run("AnUnroutedEndpointsPortFollowsItsReach", testAnUnroutedEndpointsPortFollowsItsReach)
|
||||
t.Run("APublicNameLeavesARoutedPortAsTheManifestSaid", testAPublicNameLeavesARoutedPortAsTheManifestSaid)
|
||||
t.Run("AReachForAPortTheModuleDoesNotListenOnIsRefused", testAReachForAPortTheModuleDoesNotListenOnIsRefused)
|
||||
t.Run("AValueThatIsNotAReachIsRefused", testAValueThatIsNotAReachIsRefused)
|
||||
t.Run("ReachAndExposeForOnePortAreRefused", testReachAndExposeForOnePortAreRefused)
|
||||
t.Run("ARuleWithNoPortIsLeftAlone", testARuleWithNoPortIsLeftAlone)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// novox/hq ADR 0310 §5: the holder is told, by the composition, where its node keeps a secret — the directory
|
||||
// of every module's own secret, every credential file and grant directory, the vault's directories and the
|
||||
// place the operator-sealed secrets are kept — and no other module is told.
|
||||
func TestTheHolderOfNodeReadsIsToldWhereItsNodeKeepsASecret(t *testing.T) {
|
||||
func testTheHolderOfNodeReadsIsToldWhereItsNodeKeepsASecret(t *testing.T) {
|
||||
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}, "reads": {"broker": "own"}, "desk": {"broker": "own"}}}
|
||||
goRuntime := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
||||
@@ -67,7 +67,7 @@ func TestTheHolderOfNodeReadsIsToldWhereItsNodeKeepsASecret(t *testing.T) {
|
||||
|
||||
// The review of #257: a secret place the controller cannot resolve fails the composition, naming the module,
|
||||
// rather than leaving the list one place shorter.
|
||||
func TestASecretPlaceThatCannotBeResolvedFailsTheComposition(t *testing.T) {
|
||||
func testASecretPlaceThatCannotBeResolvedFailsTheComposition(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{
|
||||
{Module: "app", Version: "1", Keeps: "${dir:keep}/sealed"},
|
||||
}}
|
||||
@@ -79,3 +79,9 @@ func TestASecretPlaceThatCannotBeResolvedFailsTheComposition(t *testing.T) {
|
||||
t.Error("a relative place was dropped")
|
||||
}
|
||||
}
|
||||
|
||||
// TestReads runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestReads(t *testing.T) {
|
||||
t.Run("TheHolderOfNodeReadsIsToldWhereItsNodeKeepsASecret", testTheHolderOfNodeReadsIsToldWhereItsNodeKeepsASecret)
|
||||
t.Run("ASecretPlaceThatCannotBeResolvedFailsTheComposition", testASecretPlaceThatCannotBeResolvedFailsTheComposition)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func names(r mcat.Resolution) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
func TestARequirementWithOneAnswerIsTakenSilently(t *testing.T) {
|
||||
func testARequirementWithOneAnswerIsTakenSilently(t *testing.T) {
|
||||
// `install i3` should bring in xorg without asking anybody anything, because there was no
|
||||
// choice to make. This is what keeps the refusing rule from being tiresome.
|
||||
got, err := Resolve(shelf(
|
||||
@@ -58,7 +58,7 @@ func TestARequirementWithOneAnswerIsTakenSilently(t *testing.T) {
|
||||
// only optional consumers want is left absent (ADR 0330 §3); several answers are still the node's refusal, naming them (the
|
||||
// mesh does not pick: a default would be a choice made for somebody who finds out later); and a node whose every module is held,
|
||||
// or an assigned name nobody wants, is still refused.
|
||||
func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode(t *testing.T) {
|
||||
func testARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode(t *testing.T) {
|
||||
optional := mod("viewer", nil, []string{"codec"}, nil)
|
||||
optional.OptionalRequires = map[string]bool{"codec": true}
|
||||
hard := mod("player", nil, []string{"codec"}, nil)
|
||||
@@ -125,7 +125,7 @@ func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeveralModulesMayProvideTheSameThingAndCoexist(t *testing.T) {
|
||||
func testSeveralModulesMayProvideTheSameThingAndCoexist(t *testing.T) {
|
||||
// Shells. Nothing is claimed, so any number may be assigned — which is the case that made
|
||||
// "flavor" look necessary and turns out to need nothing at all.
|
||||
got, err := Resolve(shelf(
|
||||
@@ -142,7 +142,7 @@ func TestSeveralModulesMayProvideTheSameThingAndCoexist(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoModulesClaimingOneThingAreRefused(t *testing.T) {
|
||||
func testTwoModulesClaimingOneThingAreRefused(t *testing.T) {
|
||||
// xorg and wayland. Neither knows the other exists — the refusal comes from both claiming
|
||||
// the seat, which is what lets a third display server be added without editing either.
|
||||
_, err := Resolve(shelf(
|
||||
@@ -158,7 +158,7 @@ func TestTwoModulesClaimingOneThingAreRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAThirdModuleNeedsNoChangeToTheOthers(t *testing.T) {
|
||||
func testAThirdModuleNeedsNoChangeToTheOthers(t *testing.T) {
|
||||
// The property claims exist for. A third display server says what it claims and nothing else
|
||||
// in the catalogue is touched — where pairwise exclusion would need xorg and wayland edited
|
||||
// to know about it, and the edits would grow as the square of the count.
|
||||
@@ -177,7 +177,7 @@ func TestAThirdModuleNeedsNoChangeToTheOthers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestADirectlyAssignedModuleTheMachineCannotHostIsReportedNotRefused(t *testing.T) {
|
||||
func testADirectlyAssignedModuleTheMachineCannotHostIsReportedNotRefused(t *testing.T) {
|
||||
// A person put a display server on a seatless machine. The remedy differs from a missing module
|
||||
// and the message has to say which — nothing can be installed to give a server a seat. But it is
|
||||
// one module on the wrong machine, not a reason the whole node fails to resolve: it is kept out
|
||||
@@ -215,7 +215,7 @@ func TestADirectlyAssignedModuleTheMachineCannotHostIsReportedNotRefused(t *test
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnUnhostableModuleSomethingRequiresRefusesTheNode(t *testing.T) {
|
||||
func testAnUnhostableModuleSomethingRequiresRefusesTheNode(t *testing.T) {
|
||||
// The other side of the distinction. A module the machine cannot host that is *required* by
|
||||
// something running here makes the set incoherent: the requiring module cannot have its
|
||||
// requirement met on this machine, so it is refused rather than quietly declared without it.
|
||||
@@ -233,7 +233,7 @@ func TestAnUnhostableModuleSomethingRequiresRefusesTheNode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneUnhostableAssignmentDoesNotTakeDownTheHealthyModules(t *testing.T) {
|
||||
func testOneUnhostableAssignmentDoesNotTakeDownTheHealthyModules(t *testing.T) {
|
||||
// The bug the whole-mesh dry-run found: fail2ban declares a capability the host lacks, and its
|
||||
// one un-hostable assignment refused the entire node's resolution — so a push refused to send
|
||||
// the healthy modules beside it too. The healthy modules must still resolve and converge; the
|
||||
@@ -268,7 +268,7 @@ func TestOneUnhostableAssignmentDoesNotTakeDownTheHealthyModules(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAMeshWideClaimIsHeldByOneNode(t *testing.T) {
|
||||
func testAMeshWideClaimIsHeldByOneNode(t *testing.T) {
|
||||
// The hub, said as a claim rather than hard-coded. Another node already holds it, so this one
|
||||
// cannot.
|
||||
_, err := Resolve(shelf(mod("hub", nil, nil, nil, mcat.Claim{Name: "the-hub", Scope: mcat.ScopeMesh})),
|
||||
@@ -281,7 +281,7 @@ func TestAMeshWideClaimIsHeldByOneNode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAFoundationModuleCannotBeRaisedOnASecondNode(t *testing.T) {
|
||||
func testAFoundationModuleCannotBeRaisedOnASecondNode(t *testing.T) {
|
||||
// novox/hq 04-ISSUES/056. The store and broker are adopted in place on the control-node; each
|
||||
// foundation module claims a mesh-scoped seat named after its server — the same mechanism that
|
||||
// keeps one controller — so a second `assign` to another node is refused rather than silently
|
||||
@@ -303,7 +303,7 @@ func TestAFoundationModuleCannotBeRaisedOnASecondNode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestASiteClaimOnlyCollidesWithinThatSite(t *testing.T) {
|
||||
func testASiteClaimOnlyCollidesWithinThatSite(t *testing.T) {
|
||||
// A DHCP server per segment. Two of them is a fault at one site and perfectly ordinary
|
||||
// across two, and treating site as mesh would forbid the ordinary case.
|
||||
catalogue := shelf(mod("dhcp", nil, nil, nil, mcat.Claim{Name: "dhcp", Scope: mcat.ScopeSite}))
|
||||
@@ -319,7 +319,7 @@ func TestASiteClaimOnlyCollidesWithinThatSite(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoModulesWritingOneFileAreRefusedWithoutAnyClaim(t *testing.T) {
|
||||
func testTwoModulesWritingOneFileAreRefusedWithoutAnyClaim(t *testing.T) {
|
||||
// This conflict costs no manifest field: the mesh already holds every resource of every
|
||||
// module, so two declaring one path are visible without either knowing the other exists.
|
||||
a := mod("a", nil, nil, nil)
|
||||
@@ -336,7 +336,7 @@ func TestTwoModulesWritingOneFileAreRefusedWithoutAnyClaim(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceIdentitiesCarryTheirModule(t *testing.T) {
|
||||
func testResourceIdentitiesCarryTheirModule(t *testing.T) {
|
||||
// Two modules may reasonably both call something "config". Without the prefix the second
|
||||
// would silently replace the first, and the node would apply one of them and report success.
|
||||
a := mod("a", nil, nil, nil)
|
||||
@@ -361,7 +361,7 @@ func TestResourceIdentitiesCarryTheirModule(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhatAServiceReflectsIsQualifiedToo(t *testing.T) {
|
||||
func testWhatAServiceReflectsIsQualifiedToo(t *testing.T) {
|
||||
// Otherwise it names a resource that no longer exists under that identity, and the service
|
||||
// quietly stops being restarted when its own configuration changes.
|
||||
m := mod("thing", nil, nil, nil)
|
||||
@@ -385,7 +385,7 @@ func TestWhatAServiceReflectsIsQualifiedToo(t *testing.T) {
|
||||
t.Error("the service is missing from the declaration")
|
||||
}
|
||||
|
||||
func TestEveryReasonIsGivenAtOnce(t *testing.T) {
|
||||
func testEveryReasonIsGivenAtOnce(t *testing.T) {
|
||||
// Somebody resolving these fixes them in one pass or in three. Every reason that genuinely
|
||||
// refuses the set is collected, rather than only the first: a claim two modules both take, a
|
||||
// requirement nothing answers, and a requirement several answer without anybody choosing.
|
||||
@@ -406,7 +406,7 @@ func TestEveryReasonIsGivenAtOnce(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestACycleStopsRatherThanRunsAway(t *testing.T) {
|
||||
func testACycleStopsRatherThanRunsAway(t *testing.T) {
|
||||
// Two modules requiring each other is a mistake somebody makes, and it must produce an answer
|
||||
// rather than a stack overflow.
|
||||
got, err := Resolve(shelf(
|
||||
@@ -422,7 +422,7 @@ func TestACycleStopsRatherThanRunsAway(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChoosingOneSatisfiesTheRequirement(t *testing.T) {
|
||||
func testChoosingOneSatisfiesTheRequirement(t *testing.T) {
|
||||
// The other half of refusing. "Choose one and assign it" has to actually work, or the remedy
|
||||
// names three modules and then ignores the one you pick — which is how this read the first
|
||||
// time it was used on a real mesh.
|
||||
@@ -441,7 +441,7 @@ func TestChoosingOneSatisfiesTheRequirement(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChoosingSeveralIsStillFine(t *testing.T) {
|
||||
func testChoosingSeveralIsStillFine(t *testing.T) {
|
||||
// And the choice is not exclusive. Nothing is claimed, so a person may have all three and
|
||||
// the requirement is answered by whichever they picked.
|
||||
got, err := Resolve(shelf(
|
||||
@@ -459,7 +459,7 @@ func TestChoosingSeveralIsStillFine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestARequirementNamingAModuleMeansThatModule(t *testing.T) {
|
||||
func testARequirementNamingAModuleMeansThatModule(t *testing.T) {
|
||||
// i3 requires xorg and means xorg, not "anything calling itself a display server". Otherwise
|
||||
// assigning wayland would silently satisfy i3 and the machine would come up with a window
|
||||
// manager talking to nothing.
|
||||
@@ -495,7 +495,7 @@ func mustDeclare(t *testing.T, r mcat.Resolution) []map[string]any {
|
||||
//
|
||||
// It went unnoticed because everything proven until then was cross-machine, which is the
|
||||
// interesting case for a mesh and the rare one in practice.
|
||||
func TestSomethingAnsweredOnThisMachineIsStillANeed(t *testing.T) {
|
||||
func testSomethingAnsweredOnThisMachineIsStillANeed(t *testing.T) {
|
||||
provider := mcat.Manifest{
|
||||
Module: "postgres", Version: "1",
|
||||
Provides: mcat.FromAnywhere("postgres-database"),
|
||||
@@ -526,7 +526,7 @@ func TestSomethingAnsweredOnThisMachineIsStillANeed(t *testing.T) {
|
||||
}
|
||||
|
||||
// A name nothing grants is unchanged: answered here means answered, and nothing more is owed.
|
||||
func TestSomethingOrdinaryAnsweredHereNeedsNothing(t *testing.T) {
|
||||
func testSomethingOrdinaryAnsweredHereNeedsNothing(t *testing.T) {
|
||||
got, err := Resolve(shelf(
|
||||
mod("zsh", []string{"shell"}, nil, nil),
|
||||
mod("editor-user", nil, []string{"shell"}, nil),
|
||||
@@ -538,3 +538,28 @@ func TestSomethingOrdinaryAnsweredHereNeedsNothing(t *testing.T) {
|
||||
t.Fatalf("a shell answered on this machine produced %d need(s)", len(got.Needs))
|
||||
}
|
||||
}
|
||||
|
||||
// TestResolve runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestResolve(t *testing.T) {
|
||||
t.Run("ARequirementWithOneAnswerIsTakenSilently", testARequirementWithOneAnswerIsTakenSilently)
|
||||
t.Run("ARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode", testARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode)
|
||||
t.Run("SeveralModulesMayProvideTheSameThingAndCoexist", testSeveralModulesMayProvideTheSameThingAndCoexist)
|
||||
t.Run("TwoModulesClaimingOneThingAreRefused", testTwoModulesClaimingOneThingAreRefused)
|
||||
t.Run("AThirdModuleNeedsNoChangeToTheOthers", testAThirdModuleNeedsNoChangeToTheOthers)
|
||||
t.Run("ADirectlyAssignedModuleTheMachineCannotHostIsReportedNotRefused", testADirectlyAssignedModuleTheMachineCannotHostIsReportedNotRefused)
|
||||
t.Run("AnUnhostableModuleSomethingRequiresRefusesTheNode", testAnUnhostableModuleSomethingRequiresRefusesTheNode)
|
||||
t.Run("OneUnhostableAssignmentDoesNotTakeDownTheHealthyModules", testOneUnhostableAssignmentDoesNotTakeDownTheHealthyModules)
|
||||
t.Run("AMeshWideClaimIsHeldByOneNode", testAMeshWideClaimIsHeldByOneNode)
|
||||
t.Run("AFoundationModuleCannotBeRaisedOnASecondNode", testAFoundationModuleCannotBeRaisedOnASecondNode)
|
||||
t.Run("ASiteClaimOnlyCollidesWithinThatSite", testASiteClaimOnlyCollidesWithinThatSite)
|
||||
t.Run("TwoModulesWritingOneFileAreRefusedWithoutAnyClaim", testTwoModulesWritingOneFileAreRefusedWithoutAnyClaim)
|
||||
t.Run("ResourceIdentitiesCarryTheirModule", testResourceIdentitiesCarryTheirModule)
|
||||
t.Run("WhatAServiceReflectsIsQualifiedToo", testWhatAServiceReflectsIsQualifiedToo)
|
||||
t.Run("EveryReasonIsGivenAtOnce", testEveryReasonIsGivenAtOnce)
|
||||
t.Run("ACycleStopsRatherThanRunsAway", testACycleStopsRatherThanRunsAway)
|
||||
t.Run("ChoosingOneSatisfiesTheRequirement", testChoosingOneSatisfiesTheRequirement)
|
||||
t.Run("ChoosingSeveralIsStillFine", testChoosingSeveralIsStillFine)
|
||||
t.Run("ARequirementNamingAModuleMeansThatModule", testARequirementNamingAModuleMeansThatModule)
|
||||
t.Run("SomethingAnsweredOnThisMachineIsStillANeed", testSomethingAnsweredOnThisMachineIsStillANeed)
|
||||
t.Run("SomethingOrdinaryAnsweredHereNeedsNothing", testSomethingOrdinaryAnsweredHereNeedsNothing)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
func TestTheMeshsPlaceForDockerIsAccepted(t *testing.T) {
|
||||
func testTheMeshsPlaceForDockerIsAccepted(t *testing.T) {
|
||||
// The fix #205 needed: the mesh's own directory for the module, <root>/mesh/docker.
|
||||
m, err := decodeForTest([]byte(`{"module": "docker", "version": "1", "resources": [
|
||||
{"id": "state", "type": "directory", "place": "mesh"},
|
||||
@@ -19,7 +19,7 @@ func TestTheMeshsPlaceForDockerIsAccepted(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestComposingAMachineIsNeverStoppedByOneModulesPath(t *testing.T) {
|
||||
func testComposingAMachineIsNeverStoppedByOneModulesPath(t *testing.T) {
|
||||
// A module registered from outside the catalogue never passes the gate. Refusing its path while a machine's
|
||||
// declaration is composed would fail the whole declaration and freeze every module on that machine; the
|
||||
// node-engine fails only the one resource. So composition leaves it to the engine.
|
||||
@@ -30,3 +30,9 @@ func TestComposingAMachineIsNeverStoppedByOneModulesPath(t *testing.T) {
|
||||
t.Fatalf("the machine's declaration failed for one module's path: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestResolvedPath runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestResolvedPath(t *testing.T) {
|
||||
t.Run("TheMeshsPlaceForDockerIsAccepted", testTheMeshsPlaceForDockerIsAccepted)
|
||||
t.Run("ComposingAMachineIsNeverStoppedByOneModulesPath", testComposingAMachineIsNeverStoppedByOneModulesPath)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
func TestTheResolverConfigSeatIsGone(t *testing.T) {
|
||||
func testTheResolverConfigSeatIsGone(t *testing.T) {
|
||||
if _, known := mcat.SeatNamed("node-resolver-config"); known {
|
||||
t.Error("node-resolver-config is still in the mesh's set; the uplink's holder writes the resolver file")
|
||||
}
|
||||
@@ -19,7 +19,7 @@ func TestTheResolverConfigSeatIsGone(t *testing.T) {
|
||||
|
||||
// The catalogue as it is: nothing claims the retired seat, and every manager the mesh knows holds the
|
||||
// uplink and writes the resolver file; beside them only a holder of node-resolver does (ADR 0247).
|
||||
func TestTheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes(t *testing.T) {
|
||||
func testTheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes(t *testing.T) {
|
||||
cat := map[string]mcat.Manifest{}
|
||||
for _, m := range theCatalogue(t) {
|
||||
cat[m.Module] = m
|
||||
@@ -55,3 +55,9 @@ func TestTheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes(t *testing.T
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestResolverFileIsTheUplinks runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestResolverFileIsTheUplinks(t *testing.T) {
|
||||
t.Run("TheResolverConfigSeatIsGone", testTheResolverConfigSeatIsGone)
|
||||
t.Run("TheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes", testTheCataloguesUplinksWriteTheResolverFileAndNothingElseDoes)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ var twoMachines = map[string]string{"anchor.internal": "10.42.0.1", "laptop.inte
|
||||
// mesh's account of every machine as a wildcard, the suffix kept local, the daemon restarting on
|
||||
// that file, the machine pointed at the resolver by address, and the runtime given no resolver of
|
||||
// its own but kept running across a restart (ADR 0196).
|
||||
func TestTheResolverAndWhatAsksItComposeOnOneMachine(t *testing.T) {
|
||||
func testTheResolverAndWhatAsksItComposeOnOneMachine(t *testing.T) {
|
||||
got, err := Resolve(resolverShelf(t), []string{"dnsmasq", "systemd-networkd", "docker"}, mcat.Node{Name: "anchor", At: "anchor.internal", Capabilities: map[string]bool{
|
||||
"package-manager": true, "service-manager": true, "privileged": true,
|
||||
"uplink-systemd-networkd": true}}, mcat.World{})
|
||||
@@ -158,7 +158,7 @@ func TestTheResolverAndWhatAsksItComposeOnOneMachine(t *testing.T) {
|
||||
// Two modules deciding what a machine asks are refused on one machine, as before — now that the file
|
||||
// is the uplink's (novox/hq ADR 0223), by two things: a machine runs one network manager, and no other
|
||||
// module may write the resolver file beside the uplink's, as a file or as a rendered fact.
|
||||
func TestTwoThingsDecidingWhatAMachineAsksAreRefused(t *testing.T) {
|
||||
func testTwoThingsDecidingWhatAMachineAsksAreRefused(t *testing.T) {
|
||||
shelf := resolverShelf(t)
|
||||
shelf["networkmanager"] = catalogueManifest(t, "networkmanager")
|
||||
node := mcat.Node{Name: "anchor", At: "anchor.internal", Capabilities: map[string]bool{
|
||||
@@ -189,7 +189,7 @@ func TestTwoThingsDecidingWhatAMachineAsksAreRefused(t *testing.T) {
|
||||
// A machine that is not on the private network has no address for the runtime to be pointed at.
|
||||
// Refused where the module and the machine are both named, rather than a placeholder written into
|
||||
// the runtime's file and read as an address.
|
||||
func TestTheResolverOnAMachineOffTheNetworkIsRefused(t *testing.T) {
|
||||
func testTheResolverOnAMachineOffTheNetworkIsRefused(t *testing.T) {
|
||||
got, err := Resolve(resolverShelf(t), []string{"dnsmasq"}, mcat.Node{Name: "anchor"}, mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -230,3 +230,10 @@ func daemonKeysDeclared(t *testing.T) map[string]bool {
|
||||
t.Fatal("the docker module declares no daemon.json")
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestResolverManifests runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestResolverManifests(t *testing.T) {
|
||||
t.Run("TheResolverAndWhatAsksItComposeOnOneMachine", testTheResolverAndWhatAsksItComposeOnOneMachine)
|
||||
t.Run("TwoThingsDecidingWhatAMachineAsksAreRefused", testTwoThingsDecidingWhatAMachineAsksAreRefused)
|
||||
t.Run("TheResolverOnAMachineOffTheNetworkIsRefused", testTheResolverOnAMachineOffTheNetworkIsRefused)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func withDomain(domain string) mcat.Node {
|
||||
return n
|
||||
}
|
||||
|
||||
func TestALabelComposesWithTheNodesPublicDomain(t *testing.T) {
|
||||
func testALabelComposesWithTheNodesPublicDomain(t *testing.T) {
|
||||
got, err := Resolve(shelf(proxy(), labelled("board", "git", 8080)),
|
||||
[]string{"board"}, withDomain("example.tld"), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -42,7 +42,7 @@ func TestALabelComposesWithTheNodesPublicDomain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheApexLabelComposesToTheBareDomain(t *testing.T) {
|
||||
func testTheApexLabelComposesToTheBareDomain(t *testing.T) {
|
||||
got, err := Resolve(shelf(proxy(), labelled("board", "@", 4000)),
|
||||
[]string{"board"}, withDomain("example.tld"), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -58,7 +58,7 @@ func TestTheApexLabelComposesToTheBareDomain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneNodeSettingMovesTheCatalogueBetweenDomains(t *testing.T) {
|
||||
func testOneNodeSettingMovesTheCatalogueBetweenDomains(t *testing.T) {
|
||||
// The ADR's name-agnostic check: the same catalogue resolves against two different public
|
||||
// domains by changing one node setting and nothing else.
|
||||
one, err := Resolve(shelf(proxy(), labelled("board", "git", 8080)),
|
||||
@@ -87,7 +87,7 @@ func TestOneNodeSettingMovesTheCatalogueBetweenDomains(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestALegacyFullNameContributionPassesThroughUnchanged(t *testing.T) {
|
||||
func testALegacyFullNameContributionPassesThroughUnchanged(t *testing.T) {
|
||||
// Backward compatibility: a contribution that still carries a full `name` and no `label` is
|
||||
// granted that name as-is, even on a node that has a public domain. This is what lets the
|
||||
// catalogue migrate one module at a time while the running mesh keeps working.
|
||||
@@ -108,7 +108,7 @@ func TestALegacyFullNameContributionPassesThroughUnchanged(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestALabelWithNoPublicDomainComposesNothing(t *testing.T) {
|
||||
func testALabelWithNoPublicDomainComposesNothing(t *testing.T) {
|
||||
// A routed module on a node with no public domain has nothing to join its label to. It composes
|
||||
// no name — which reads downstream exactly as a route that named no host, the same as before
|
||||
// this existed — rather than an fabricated `git.` with a dangling dot.
|
||||
@@ -134,7 +134,7 @@ func withPrivateAddress(at string) mcat.Node {
|
||||
return n
|
||||
}
|
||||
|
||||
func TestALabelComposesWithTheNodesPrivateAddressToo(t *testing.T) {
|
||||
func testALabelComposesWithTheNodesPrivateAddressToo(t *testing.T) {
|
||||
// A predecessor proxy answered a route on both a public and a private-network hostname for the
|
||||
// same convenience the mesh restores here: reaching a service over the VPN without a public TLS
|
||||
// round trip. Composed independently of the public name, from the node's own `At`.
|
||||
@@ -149,7 +149,7 @@ func TestALabelComposesWithTheNodesPrivateAddressToo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestThePublicAndInternalNamesComposeIndependently(t *testing.T) {
|
||||
func testThePublicAndInternalNamesComposeIndependently(t *testing.T) {
|
||||
// A node with both a public domain and a private address gets both names from one label; a
|
||||
// node with only one of the two gets only the matching one — neither composition depends on
|
||||
// the other being possible.
|
||||
@@ -180,7 +180,7 @@ func TestThePublicAndInternalNamesComposeIndependently(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheApexLabelComposesToTheBarePrivateAddress(t *testing.T) {
|
||||
func testTheApexLabelComposesToTheBarePrivateAddress(t *testing.T) {
|
||||
got, err := Resolve(shelf(proxy(), labelled("board", "@", 4000)),
|
||||
[]string{"board"}, withPrivateAddress("anchor.internal"), mcat.World{})
|
||||
if err != nil {
|
||||
@@ -196,7 +196,7 @@ func TestTheApexLabelComposesToTheBarePrivateAddress(t *testing.T) {
|
||||
// machine's roster mapped to the node that serves it, beside the `<node>.internal` names, and the
|
||||
// machine's resolver answers it to every container. Nothing is written into the container itself —
|
||||
// a routed name that moved would otherwise be wrong inside every container until each was recreated.
|
||||
func TestARoutedNameResolvesToTheServingNode(t *testing.T) {
|
||||
func testARoutedNameResolvesToTheServingNode(t *testing.T) {
|
||||
names := map[string]string{
|
||||
"anchor.internal": "10.42.0.1",
|
||||
"git.example.tld": "10.42.0.1",
|
||||
@@ -228,7 +228,7 @@ func TestARoutedNameResolvesToTheServingNode(t *testing.T) {
|
||||
// be the one whose proxy answers it. Composed under the consumer's own name, a route served from
|
||||
// another machine got an internal name that resolved to a machine with nothing listening, while the
|
||||
// public name — published at the serving node's address — worked.
|
||||
func TestARoutesInternalNameIsComposedUnderTheNodeThatServesIt(t *testing.T) {
|
||||
func testARoutesInternalNameIsComposedUnderTheNodeThatServesIt(t *testing.T) {
|
||||
hub := proxy()
|
||||
hub.Provides = mcat.FromAnywhere("reverse-proxy")
|
||||
got, err := Resolve(shelf(hub, labelled("board", "git", 8080)), []string{"board"},
|
||||
@@ -248,3 +248,17 @@ func TestARoutesInternalNameIsComposedUnderTheNodeThatServesIt(t *testing.T) {
|
||||
t.Fatalf("the internal name does not say where the request arrives: %v", values)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRouting runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestRouting(t *testing.T) {
|
||||
t.Run("ALabelComposesWithTheNodesPublicDomain", testALabelComposesWithTheNodesPublicDomain)
|
||||
t.Run("TheApexLabelComposesToTheBareDomain", testTheApexLabelComposesToTheBareDomain)
|
||||
t.Run("OneNodeSettingMovesTheCatalogueBetweenDomains", testOneNodeSettingMovesTheCatalogueBetweenDomains)
|
||||
t.Run("ALegacyFullNameContributionPassesThroughUnchanged", testALegacyFullNameContributionPassesThroughUnchanged)
|
||||
t.Run("ALabelWithNoPublicDomainComposesNothing", testALabelWithNoPublicDomainComposesNothing)
|
||||
t.Run("ALabelComposesWithTheNodesPrivateAddressToo", testALabelComposesWithTheNodesPrivateAddressToo)
|
||||
t.Run("ThePublicAndInternalNamesComposeIndependently", testThePublicAndInternalNamesComposeIndependently)
|
||||
t.Run("TheApexLabelComposesToTheBarePrivateAddress", testTheApexLabelComposesToTheBarePrivateAddress)
|
||||
t.Run("ARoutedNameResolvesToTheServingNode", testARoutedNameResolvesToTheServingNode)
|
||||
t.Run("ARoutesInternalNameIsComposedUnderTheNodeThatServesIt", testARoutesInternalNameIsComposedUnderTheNodeThatServesIt)
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func theRuntime(t *testing.T) mcat.Manifest {
|
||||
return resolved
|
||||
}
|
||||
|
||||
func TestEveryToolsBundleIsDeliveredWhereTheRuntimeRuns(t *testing.T) {
|
||||
func testEveryToolsBundleIsDeliveredWhereTheRuntimeRuns(t *testing.T) {
|
||||
store := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}}}
|
||||
nftables := aToolsModule(t, "nftables", "tools/index.js")
|
||||
@@ -111,7 +111,7 @@ func ids(out []map[string]any) []string {
|
||||
|
||||
// One process per machine runs the runtime from its own bundle, told what it serves and from where,
|
||||
// where its credential is, and who the operator is — restarted when any of that changes.
|
||||
func TestTheMachineRunsOneRuntimeLoadingEveryDeliveredBundle(t *testing.T) {
|
||||
func testTheMachineRunsOneRuntimeLoadingEveryDeliveredBundle(t *testing.T) {
|
||||
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}}}
|
||||
nftables := aToolsModule(t, "nftables", "tools/index.js")
|
||||
@@ -239,7 +239,7 @@ func TestTheMachineRunsOneRuntimeLoadingEveryDeliveredBundle(t *testing.T) {
|
||||
|
||||
// novox/hq ADR 0193: the runtime is told the launcher a build wrote, and the entrypoint itself for a
|
||||
// build from before launchers — so the move needs no flag day.
|
||||
func TestTheRuntimeStartsTheLauncherWhereTheBuildWroteOne(t *testing.T) {
|
||||
func testTheRuntimeStartsTheLauncherWhereTheBuildWroteOne(t *testing.T) {
|
||||
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}}}
|
||||
launched := mcat.Manifest{Module: "dash", Version: "1", Tools: []string{"status"},
|
||||
@@ -264,7 +264,7 @@ func TestTheRuntimeStartsTheLauncherWhereTheBuildWroteOne(t *testing.T) {
|
||||
}
|
||||
|
||||
// novox/hq ADR 0193: a runtime compiled to a binary runs itself from its own unpacked bundle.
|
||||
func TestARuntimeCompiledToABinaryRunsItself(t *testing.T) {
|
||||
func testARuntimeCompiledToABinaryRunsItself(t *testing.T) {
|
||||
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}}}
|
||||
goRuntime := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
||||
@@ -293,7 +293,7 @@ func TestARuntimeCompiledToABinaryRunsItself(t *testing.T) {
|
||||
// novox/hq ADR 0259 §8: a module of its own account is served by a runtime of its own — the machine's
|
||||
// runtime program, as that account, on that module's own credential — and never by the machine's runtime,
|
||||
// which runs as the operator's account and is given none of its words.
|
||||
func TestAModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn(t *testing.T) {
|
||||
func testAModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn(t *testing.T) {
|
||||
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}, "telegram": {"broker": "own"}}}
|
||||
goRuntime := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
||||
@@ -395,7 +395,7 @@ func TestAModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn(t *testing.T) {
|
||||
|
||||
// The review of 2026-10-09 (L4): a module of its own account never runs as the node's operator account, nor
|
||||
// as the account agents run as there — either would hand what it holds back to the accounts it is kept from.
|
||||
func TestAModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount(t *testing.T) {
|
||||
func testAModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount(t *testing.T) {
|
||||
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}, "telegram": {"broker": "own"}}}
|
||||
goRuntime := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
||||
@@ -421,7 +421,7 @@ func TestAModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount(t *testi
|
||||
|
||||
// Issue 723: the vault runs as its own account, so what the mesh writes for it — the export it keeps, the grant
|
||||
// files it holds for its consumers, and what its words name — belongs to that account, never the operator's.
|
||||
func TestWhatAModuleOfItsOwnAccountReadsIsItsAccounts(t *testing.T) {
|
||||
func testWhatAModuleOfItsOwnAccountReadsIsItsAccounts(t *testing.T) {
|
||||
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
||||
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}, "vault": {"broker": "own"}},
|
||||
Kept: &mcat.KeptExport{Export: 1, OperatorKey: "k"},
|
||||
@@ -474,3 +474,14 @@ func TestWhatAModuleOfItsOwnAccountReadsIsItsAccounts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestRuntime runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestRuntime(t *testing.T) {
|
||||
t.Run("EveryToolsBundleIsDeliveredWhereTheRuntimeRuns", testEveryToolsBundleIsDeliveredWhereTheRuntimeRuns)
|
||||
t.Run("TheMachineRunsOneRuntimeLoadingEveryDeliveredBundle", testTheMachineRunsOneRuntimeLoadingEveryDeliveredBundle)
|
||||
t.Run("TheRuntimeStartsTheLauncherWhereTheBuildWroteOne", testTheRuntimeStartsTheLauncherWhereTheBuildWroteOne)
|
||||
t.Run("ARuntimeCompiledToABinaryRunsItself", testARuntimeCompiledToABinaryRunsItself)
|
||||
t.Run("AModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn", testAModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn)
|
||||
t.Run("AModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount", testAModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount)
|
||||
t.Run("WhatAModuleOfItsOwnAccountReadsIsItsAccounts", testWhatAModuleOfItsOwnAccountReadsIsItsAccounts)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func hotkeysHolder() mcat.Manifest {
|
||||
}}
|
||||
}
|
||||
|
||||
func TestAContributionReachesTheHoldersFileInModuleOrderNamedByModule(t *testing.T) {
|
||||
func testAContributionReachesTheHoldersFileInModuleOrderNamedByModule(t *testing.T) {
|
||||
laptop := mcat.Manifest{Module: "laptop", Contributions: []mcat.SeatContribution{
|
||||
{Seat: mcat.HotkeysSeat, Kind: "trigger", Content: "KEY_PROG1 1 play ${machine:account-home}"},
|
||||
{Seat: mcat.HotkeysSeat, Kind: "trigger", Content: "KEY_F21 1 touchpad\n"},
|
||||
@@ -48,7 +48,7 @@ func TestAContributionReachesTheHoldersFileInModuleOrderNamedByModule(t *testing
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoContributionPlacesNothing(t *testing.T) {
|
||||
func testNoContributionPlacesNothing(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "laptop", Account: "op", Modules: []mcat.Manifest{hotkeysHolder()}}
|
||||
out, err := Declaration(r, mcat.Rendering{})
|
||||
if err != nil {
|
||||
@@ -60,3 +60,9 @@ func TestNoContributionPlacesNothing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestSeatContributions runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSeatContributions(t *testing.T) {
|
||||
t.Run("AContributionReachesTheHoldersFileInModuleOrderNamedByModule", testAContributionReachesTheHoldersFileInModuleOrderNamedByModule)
|
||||
t.Run("NoContributionPlacesNothing", testNoContributionPlacesNothing)
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func composedFile(t *testing.T, r mcat.Resolution, id string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func TestResolveCarriesTheMachinesCapabilities(t *testing.T) {
|
||||
func testResolveCarriesTheMachinesCapabilities(t *testing.T) {
|
||||
node := workstation()
|
||||
node.Capabilities["battery"] = true
|
||||
r, err := Resolve(shelf(mcat.Manifest{Module: "a"}), []string{"a"}, node, mcat.World{})
|
||||
@@ -67,7 +67,7 @@ func TestResolveCarriesTheMachinesCapabilities(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPieceTheHolderCannotRenderIsLeftOutAndNamedNotTheMachine(t *testing.T) {
|
||||
func testAPieceTheHolderCannotRenderIsLeftOutAndNamedNotTheMachine(t *testing.T) {
|
||||
// A shows the shape gained after the holder's template was written: built here, past the check.
|
||||
power := mcat.Manifest{Module: "power", Contributions: []mcat.SeatContribution{
|
||||
block(`{"bar":"bottom","place":"status","shows":"gpu"}`),
|
||||
@@ -89,7 +89,7 @@ func TestAPieceTheHolderCannotRenderIsLeftOutAndNamedNotTheMachine(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnOfferedBlockMakesNoDependencyOnTheBar(t *testing.T) {
|
||||
func testAnOfferedBlockMakesNoDependencyOnTheBar(t *testing.T) {
|
||||
power := mcat.Manifest{Module: "power", Contributions: []mcat.SeatContribution{
|
||||
block(`{"bar":"bottom","place":"status","shows":"battery"}`),
|
||||
{Seat: mcat.HotkeysSeat, Kind: "trigger", Content: "x"},
|
||||
@@ -106,3 +106,10 @@ func TestAnOfferedBlockMakesNoDependencyOnTheBar(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSeatData runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSeatData(t *testing.T) {
|
||||
t.Run("ResolveCarriesTheMachinesCapabilities", testResolveCarriesTheMachinesCapabilities)
|
||||
t.Run("APieceTheHolderCannotRenderIsLeftOutAndNamedNotTheMachine", testAPieceTheHolderCannotRenderIsLeftOutAndNamedNotTheMachine)
|
||||
t.Run("AnOfferedBlockMakesNoDependencyOnTheBar", testAnOfferedBlockMakesNoDependencyOnTheBar)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func coreThree() []mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestADependencyIsDerivedFromEachResourceTypeThatAppliesThroughASeat(t *testing.T) {
|
||||
func testADependencyIsDerivedFromEachResourceTypeThatAppliesThroughASeat(t *testing.T) {
|
||||
cases := map[string][]string{
|
||||
"service": {mcat.ServiceManagerSeat},
|
||||
"package": {mcat.PackageManagerSeat},
|
||||
@@ -65,7 +65,7 @@ func TestADependencyIsDerivedFromEachResourceTypeThatAppliesThroughASeat(t *test
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusIsToldOfAnUnmetDependencyAndTheNodeStillResolves(t *testing.T) {
|
||||
func testStatusIsToldOfAnUnmetDependencyAndTheNodeStillResolves(t *testing.T) {
|
||||
// Before the switch (the state the mesh ran in until every node held the three seats).
|
||||
enforceSeatDependencies = false
|
||||
defer func() { enforceSeatDependencies = true }()
|
||||
@@ -81,7 +81,7 @@ func TestStatusIsToldOfAnUnmetDependencyAndTheNodeStillResolves(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithTheSwitchFlippedAnUnmetDependencyRefusesTheNode(t *testing.T) {
|
||||
func testWithTheSwitchFlippedAnUnmetDependencyRefusesTheNode(t *testing.T) {
|
||||
enforceSeatDependencies = true
|
||||
defer func() { enforceSeatDependencies = true }()
|
||||
web := withResources(mod("web", nil, nil, nil), res("container", "web"))
|
||||
@@ -96,7 +96,7 @@ func TestWithTheSwitchFlippedAnUnmetDependencyRefusesTheNode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheFoundationHostIsTheEntryThatClaimsTheNodeEngineSeat(t *testing.T) {
|
||||
func testTheFoundationHostIsTheEntryThatClaimsTheNodeEngineSeat(t *testing.T) {
|
||||
svc := res("service", "x")
|
||||
// Whatever its name, the entry claiming the seat is the foundation's: nothing to depend on.
|
||||
engine := withResources(mod("the-engine", nil, nil, nil, mcat.Claim{Name: "node-engine"}), svc)
|
||||
@@ -109,3 +109,11 @@ func TestTheFoundationHostIsTheEntryThatClaimsTheNodeEngineSeat(t *testing.T) {
|
||||
t.Errorf("a module merely named mesh-host depends on %v, want the service manager seat", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSeatDependencies runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSeatDependencies(t *testing.T) {
|
||||
t.Run("ADependencyIsDerivedFromEachResourceTypeThatAppliesThroughASeat", testADependencyIsDerivedFromEachResourceTypeThatAppliesThroughASeat)
|
||||
t.Run("StatusIsToldOfAnUnmetDependencyAndTheNodeStillResolves", testStatusIsToldOfAnUnmetDependencyAndTheNodeStillResolves)
|
||||
t.Run("WithTheSwitchFlippedAnUnmetDependencyRefusesTheNode", testWithTheSwitchFlippedAnUnmetDependencyRefusesTheNode)
|
||||
t.Run("TheFoundationHostIsTheEntryThatClaimsTheNodeEngineSeat", testTheFoundationHostIsTheEntryThatClaimsTheNodeEngineSeat)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
func TestASeatPlaceholderAnswersWhereThisMachinePutTheHolder(t *testing.T) {
|
||||
func testASeatPlaceholderAnswersWhereThisMachinePutTheHolder(t *testing.T) {
|
||||
control := map[string]any{
|
||||
"type": "container", "id": "server", "name": "mesh-controller",
|
||||
"env": map[string]any{
|
||||
@@ -39,7 +39,7 @@ func TestASeatPlaceholderAnswersWhereThisMachinePutTheHolder(t *testing.T) {
|
||||
// with nothing, so the port genesis wrote into the connection string stands. Not the software's
|
||||
// own port: on a node given a port at genesis before the store's module exists, that would
|
||||
// override the right number with the catalogue's.
|
||||
func TestASeatTheMeshCannotPlaceAnswersWithNothing(t *testing.T) {
|
||||
func testASeatTheMeshCannotPlaceAnswersWithNothing(t *testing.T) {
|
||||
control := map[string]any{
|
||||
"type": "container", "id": "server", "name": "mesh-controller",
|
||||
"env": map[string]any{"MESH_STORE_INVENTORY_PORT": "${seat:mesh-store:5432}"},
|
||||
@@ -59,14 +59,14 @@ func TestASeatTheMeshCannotPlaceAnswersWithNothing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestASeatPlaceholderNamingNoPortIsRefused(t *testing.T) {
|
||||
func testASeatPlaceholderNamingNoPortIsRefused(t *testing.T) {
|
||||
file := map[string]any{"type": "file", "content": "${seat:mesh-store:99999}"}
|
||||
if err := seatInto(file, "x", mcat.Rendering{}); err == nil {
|
||||
t.Fatal("99999 was accepted as a port")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillingASeatLeavesTheManifestAlone(t *testing.T) {
|
||||
func testFillingASeatLeavesTheManifestAlone(t *testing.T) {
|
||||
env := map[string]any{"MESH_STORE_INVENTORY_PORT": "${seat:mesh-store:5432}"}
|
||||
manifest := map[string]any{"type": "container", "id": "server", "env": env}
|
||||
for _, at := range []int{6852, 5432} {
|
||||
@@ -91,7 +91,7 @@ func runtimeTrust() map[string]any {
|
||||
}
|
||||
}
|
||||
|
||||
func TestASeatsReachIsWhereThisMachineReachesItsHolder(t *testing.T) {
|
||||
func testASeatsReachIsWhereThisMachineReachesItsHolder(t *testing.T) {
|
||||
file := runtimeTrust()
|
||||
with := mcat.Rendering{SeatReach: map[string]string{"mesh-artifact-store": "anchor.internal:5100"}}
|
||||
if err := seatInto(file, "docker", with); err != nil {
|
||||
@@ -128,7 +128,7 @@ func TestASeatsReachIsWhereThisMachineReachesItsHolder(t *testing.T) {
|
||||
|
||||
// With no holder reachable, the runtime is not told to trust "": the member is dropped, and the
|
||||
// list with it when nothing else is in it.
|
||||
func TestAnUnansweredReachAddsNothingToAList(t *testing.T) {
|
||||
func testAnUnansweredReachAddsNothingToAList(t *testing.T) {
|
||||
file := runtimeTrust()
|
||||
if err := seatInto(file, "docker", mcat.Rendering{}); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -147,7 +147,7 @@ func TestAnUnansweredReachAddsNothingToAList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAReachTheMeshDoesNotAnswerIsRefused(t *testing.T) {
|
||||
func testAReachTheMeshDoesNotAnswerIsRefused(t *testing.T) {
|
||||
file := map[string]any{"type": "file", "content": "${seat:mesh-store:reach}"}
|
||||
err := seatInto(file, "x", mcat.Rendering{SeatReach: map[string]string{"mesh-store": "anchor.internal:5432"}})
|
||||
if err == nil || !strings.Contains(err.Error(), "mesh-artifact-store") {
|
||||
@@ -156,7 +156,7 @@ func TestAReachTheMeshDoesNotAnswerIsRefused(t *testing.T) {
|
||||
}
|
||||
|
||||
// Through the whole composition, as the container runtime's module declares it.
|
||||
func TestTheRuntimesTrustIsComposedFromTheSeatsReach(t *testing.T) {
|
||||
func testTheRuntimesTrustIsComposedFromTheSeatsReach(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{{
|
||||
Module: "docker", Resources: []map[string]any{runtimeTrust()},
|
||||
}}}
|
||||
@@ -174,3 +174,15 @@ func TestTheRuntimesTrustIsComposedFromTheSeatsReach(t *testing.T) {
|
||||
t.Fatalf("the runtime's file says %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSeatInto runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSeatInto(t *testing.T) {
|
||||
t.Run("ASeatPlaceholderAnswersWhereThisMachinePutTheHolder", testASeatPlaceholderAnswersWhereThisMachinePutTheHolder)
|
||||
t.Run("ASeatTheMeshCannotPlaceAnswersWithNothing", testASeatTheMeshCannotPlaceAnswersWithNothing)
|
||||
t.Run("ASeatPlaceholderNamingNoPortIsRefused", testASeatPlaceholderNamingNoPortIsRefused)
|
||||
t.Run("FillingASeatLeavesTheManifestAlone", testFillingASeatLeavesTheManifestAlone)
|
||||
t.Run("ASeatsReachIsWhereThisMachineReachesItsHolder", testASeatsReachIsWhereThisMachineReachesItsHolder)
|
||||
t.Run("AnUnansweredReachAddsNothingToAList", testAnUnansweredReachAddsNothingToAList)
|
||||
t.Run("AReachTheMeshDoesNotAnswerIsRefused", testAReachTheMeshDoesNotAnswerIsRefused)
|
||||
t.Run("TheRuntimesTrustIsComposedFromTheSeatsReach", testTheRuntimesTrustIsComposedFromTheSeatsReach)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func (writesHosts) Resources(string) ([]map[string]any, bool, error) {
|
||||
}
|
||||
|
||||
// The controller is bound too: what it generates for a machine on a seat's path is refused at composition.
|
||||
func TestAGeneratedResourceOnASeatsPathIsRefused(t *testing.T) {
|
||||
func testAGeneratedResourceOnASeatsPathIsRefused(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "workstation", Modules: []mcat.Manifest{
|
||||
{Module: "mesh-names", Computed: "mesh-names"},
|
||||
}}
|
||||
@@ -53,7 +53,7 @@ func TestAGeneratedResourceOnASeatsPathIsRefused(t *testing.T) {
|
||||
// The stepping back comes from the seat, and is of a rendered file only: an uplink holder declaring the
|
||||
// resolver file as a resource beside a node-resolver holder is two writers of one path, refused when the
|
||||
// machine is resolved — never composed twice — as before the seat named its paths.
|
||||
func TestAnUplinkDeclaringTheResolverFileAsAResourceIsRefusedBesideTheResolver(t *testing.T) {
|
||||
func testAnUplinkDeclaringTheResolverFileAsAResourceIsRefusedBesideTheResolver(t *testing.T) {
|
||||
shelf := resolverShelf(t)
|
||||
uplink := shelf["systemd-networkd"]
|
||||
uplink.Facts = nil
|
||||
@@ -74,3 +74,9 @@ func TestAnUplinkDeclaringTheResolverFileAsAResourceIsRefusedBesideTheResolver(t
|
||||
t.Errorf("the uplink's holder renders %v beside the resolver", got.Facts)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSeatPaths runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSeatPaths(t *testing.T) {
|
||||
t.Run("AGeneratedResourceOnASeatsPathIsRefused", testAGeneratedResourceOnASeatsPathIsRefused)
|
||||
t.Run("AnUplinkDeclaringTheResolverFileAsAResourceIsRefusedBesideTheResolver", testAnUplinkDeclaringTheResolverFileAsAResourceIsRefusedBesideTheResolver)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func giteaHoldsTheSeat() []mcat.Held {
|
||||
return []mcat.Held{{Claim: "npm-package-registry", Scope: mcat.ScopeMesh, Node: "anchor", Module: "gitea"}}
|
||||
}
|
||||
|
||||
func TestTheSeatsHolderAnswersWhenSeveralProvide(t *testing.T) {
|
||||
func testTheSeatsHolderAnswersWhenSeveralProvide(t *testing.T) {
|
||||
// The whole point: a second registry beside the holder harms nothing, and nobody pins.
|
||||
got, err := Resolve(registryShelf(), []string{"builder"}, reachable(), mcat.World{Offered: twoRegistries(), Held: giteaHoldsTheSeat()})
|
||||
if err != nil {
|
||||
@@ -41,7 +41,7 @@ func TestTheSeatsHolderAnswersWhenSeveralProvide(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPinStillWinsOverTheSeat(t *testing.T) {
|
||||
func testAPinStillWinsOverTheSeat(t *testing.T) {
|
||||
// A consumer coupled to one provider's contents has said so, and the seat does not overrule it.
|
||||
got, err := Resolve(registryShelf(), []string{"builder"}, reachable(), mcat.World{Offered: twoRegistries(), Held: giteaHoldsTheSeat(),
|
||||
Pinned: map[string]mcat.Chosen{"npm-package-registry": {Node: "archive", Module: "verdaccio"}}})
|
||||
@@ -53,7 +53,7 @@ func TestAPinStillWinsOverTheSeat(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithTheSeatUnheldSeveralProvidersAreStillRefused(t *testing.T) {
|
||||
func testWithTheSeatUnheldSeveralProvidersAreStillRefused(t *testing.T) {
|
||||
// No seat held is no choice made, and ADR 0009's rule stands: never guessed.
|
||||
_, err := Resolve(registryShelf(), []string{"builder"}, reachable(), mcat.World{Offered: twoRegistries()})
|
||||
if err == nil {
|
||||
@@ -64,7 +64,7 @@ func TestWithTheSeatUnheldSeveralProvidersAreStillRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheHolderIsTheModuleNotTheMachine(t *testing.T) {
|
||||
func testTheHolderIsTheModuleNotTheMachine(t *testing.T) {
|
||||
// Two modules on one machine could provide the same thing; only the one holding the seat
|
||||
// answers. A holder matched by node alone would send consumers to whichever came first.
|
||||
providers := []mcat.Provider{
|
||||
@@ -165,3 +165,11 @@ func verbCopies(t *testing.T, name string, src any) []string {
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
// TestSeats runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSeats(t *testing.T) {
|
||||
t.Run("TheSeatsHolderAnswersWhenSeveralProvide", testTheSeatsHolderAnswersWhenSeveralProvide)
|
||||
t.Run("APinStillWinsOverTheSeat", testAPinStillWinsOverTheSeat)
|
||||
t.Run("WithTheSeatUnheldSeveralProvidersAreStillRefused", testWithTheSeatUnheldSeveralProvidersAreStillRefused)
|
||||
t.Run("TheHolderIsTheModuleNotTheMachine", testTheHolderIsTheModuleNotTheMachine)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// issue 206): the build machine kept an hour-old credential open because its manifest restarted it
|
||||
// on its environment file alone. Composed, so a manifest need not say it; a scheduled process is
|
||||
// left alone, because the host refuses a restart-on for one and it reads the file afresh each run.
|
||||
func TestAContainerReadingAnOwnSecretIsRestartedWhenItChanges(t *testing.T) {
|
||||
func testAContainerReadingAnOwnSecretIsRestartedWhenItChanges(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "agent", Version: "1",
|
||||
OwnSecrets: mcat.OwnSecrets{"broker": {Path: "/var/lib/mesh/agent/broker"}},
|
||||
Resources: []map[string]any{
|
||||
@@ -55,7 +55,7 @@ func TestAContainerReadingAnOwnSecretIsRestartedWhenItChanges(t *testing.T) {
|
||||
// A member of a secret family is an own secret too (novox/hq issue 405, ADR 0283 decision 6): a container that
|
||||
// reads a member given is restarted when it changes, as for a secret declared by name. A member not given is no
|
||||
// file, so nothing is restarted on it.
|
||||
func TestAContainerReadingAFamilyMemberIsRestartedWhenItChanges(t *testing.T) {
|
||||
func testAContainerReadingAFamilyMemberIsRestartedWhenItChanges(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "mounts", Version: "1",
|
||||
OwnSecrets: mcat.OwnSecrets{"smb-password-*": {Path: "/var/lib/mesh/mounts/smb-password-*.secret", IssuedBy: mcat.IssuedOutside}},
|
||||
Resources: []map[string]any{
|
||||
@@ -88,3 +88,9 @@ func TestAContainerReadingAFamilyMemberIsRestartedWhenItChanges(t *testing.T) {
|
||||
t.Fatalf("a container reading a member not given was given a restart-on naming nothing: %v", by["mounts.library"]["restart-on"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestSecretRestart runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSecretRestart(t *testing.T) {
|
||||
t.Run("AContainerReadingAnOwnSecretIsRestartedWhenItChanges", testAContainerReadingAnOwnSecretIsRestartedWhenItChanges)
|
||||
t.Run("AContainerReadingAFamilyMemberIsRestartedWhenItChanges", testAContainerReadingAFamilyMemberIsRestartedWhenItChanges)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func fileNamed(out []map[string]any, id string) map[string]any {
|
||||
|
||||
// A module's own credential, put into a file it wrote: the value sealed to the node, or, in a composition asked ahead of
|
||||
// the send or for a plan alone, the stand-in its own file has (issue 774: baserow's config.json refused ace's plans).
|
||||
func TestAFileGetsTheSecretItsContentAsksFor(t *testing.T) {
|
||||
func testAFileGetsTheSecretItsContentAsksFor(t *testing.T) {
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
with mcat.Rendering
|
||||
@@ -57,7 +57,7 @@ func TestAFileGetsTheSecretItsContentAsksFor(t *testing.T) {
|
||||
|
||||
// The gap this exists for: a granted credential arrives as a bare password, and the program that
|
||||
// needs it reads KEY=value.
|
||||
func TestAGrantedCredentialCanBeShapedIntoAnEnvFile(t *testing.T) {
|
||||
func testAGrantedCredentialCanBeShapedIntoAnEnvFile(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "anchor",
|
||||
Modules: []mcat.Manifest{{
|
||||
@@ -87,7 +87,7 @@ func TestAGrantedCredentialCanBeShapedIntoAnEnvFile(t *testing.T) {
|
||||
// ${secret:…} file — not whichever need happened to come last. This is the placeholder-path twin of
|
||||
// the guard novox/hq 04-ISSUES/022 put on the secrets:-map path; without it, a node with baserow and
|
||||
// letta both consuming postgres gave baserow letta's password and authentication failed.
|
||||
func TestTwoConsumersOfOneProvisionEachGetTheirOwnInAPlaceholderFile(t *testing.T) {
|
||||
func testTwoConsumersOfOneProvisionEachGetTheirOwnInAPlaceholderFile(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "anchor",
|
||||
Modules: []mcat.Manifest{
|
||||
@@ -130,7 +130,7 @@ func TestTwoConsumersOfOneProvisionEachGetTheirOwnInAPlaceholderFile(t *testing.
|
||||
}
|
||||
|
||||
// A name nothing declared is a typo, and it is refused here rather than on the machine.
|
||||
func TestAFileNamingASecretTheModuleDoesNotHaveIsRefused(t *testing.T) {
|
||||
func testAFileNamingASecretTheModuleDoesNotHaveIsRefused(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{{
|
||||
Module: "gitea",
|
||||
OwnSecrets: mcat.OwnSecrets{"admin": {Path: "/var/lib/gitea/admin.env"}},
|
||||
@@ -152,7 +152,7 @@ func TestAFileNamingASecretTheModuleDoesNotHaveIsRefused(t *testing.T) {
|
||||
}
|
||||
|
||||
// One module may not read another's credential by guessing its name.
|
||||
func TestAFileCannotNameAnotherModulesSecret(t *testing.T) {
|
||||
func testAFileCannotNameAnotherModulesSecret(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{
|
||||
{Module: "postgres", OwnSecrets: mcat.OwnSecrets{"superuser": {Path: "/var/lib/postgres/su.env"}}},
|
||||
{Module: "gitea", Resources: []map[string]any{{
|
||||
@@ -174,7 +174,7 @@ func TestAFileCannotNameAnotherModulesSecret(t *testing.T) {
|
||||
// attribute inside a JSON file in a home directory, not from an environment variable. The module
|
||||
// ships an empty document, a setting says which attribute, and the credential never passes
|
||||
// through the mesh in the open.
|
||||
func TestASettingThatCarriesAPlaceholderIsStillFilled(t *testing.T) {
|
||||
func testASettingThatCarriesAPlaceholderIsStillFilled(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "workstation", Modules: []mcat.Manifest{{
|
||||
Module: "chat",
|
||||
OwnSecrets: mcat.OwnSecrets{"api-token": {Path: "/home/operator/.config/chat/token"}},
|
||||
@@ -205,7 +205,7 @@ func TestASettingThatCarriesAPlaceholderIsStillFilled(t *testing.T) {
|
||||
}
|
||||
|
||||
// An own secret and a requirement of the same name would make ${secret:x} mean either.
|
||||
func TestANameMeaningTwoThingsIsRefused(t *testing.T) {
|
||||
func testANameMeaningTwoThingsIsRefused(t *testing.T) {
|
||||
r := mcat.Resolution{
|
||||
Node: "anchor",
|
||||
Modules: []mcat.Manifest{{
|
||||
@@ -225,7 +225,7 @@ func TestANameMeaningTwoThingsIsRefused(t *testing.T) {
|
||||
|
||||
// A file with no placeholder is not given a secrets map. The host refuses a secret its content
|
||||
// never asks for, so an empty map added helpfully would break every file that has none.
|
||||
func TestAFileWithNoPlaceholderIsLeftAlone(t *testing.T) {
|
||||
func testAFileWithNoPlaceholderIsLeftAlone(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{{
|
||||
Module: "gitea",
|
||||
OwnSecrets: mcat.OwnSecrets{"admin": {Path: "/var/lib/gitea/admin.env"}},
|
||||
@@ -243,3 +243,15 @@ func TestAFileWithNoPlaceholderIsLeftAlone(t *testing.T) {
|
||||
t.Error("a file that asks for nothing was given a secrets map, which the host refuses")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSecretsIntoFiles runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSecretsIntoFiles(t *testing.T) {
|
||||
t.Run("AFileGetsTheSecretItsContentAsksFor", testAFileGetsTheSecretItsContentAsksFor)
|
||||
t.Run("AGrantedCredentialCanBeShapedIntoAnEnvFile", testAGrantedCredentialCanBeShapedIntoAnEnvFile)
|
||||
t.Run("TwoConsumersOfOneProvisionEachGetTheirOwnInAPlaceholderFile", testTwoConsumersOfOneProvisionEachGetTheirOwnInAPlaceholderFile)
|
||||
t.Run("AFileNamingASecretTheModuleDoesNotHaveIsRefused", testAFileNamingASecretTheModuleDoesNotHaveIsRefused)
|
||||
t.Run("AFileCannotNameAnotherModulesSecret", testAFileCannotNameAnotherModulesSecret)
|
||||
t.Run("ASettingThatCarriesAPlaceholderIsStillFilled", testASettingThatCarriesAPlaceholderIsStillFilled)
|
||||
t.Run("ANameMeaningTwoThingsIsRefused", testANameMeaningTwoThingsIsRefused)
|
||||
t.Run("AFileWithNoPlaceholderIsLeftAlone", testAFileWithNoPlaceholderIsLeftAlone)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func aForgeManifest(t *testing.T) mcat.Manifest {
|
||||
return m
|
||||
}
|
||||
|
||||
func TestAProviderServesItsOwnComposedName(t *testing.T) {
|
||||
func testAProviderServesItsOwnComposedName(t *testing.T) {
|
||||
m := aForgeManifest(t)
|
||||
r := mcat.Resolution{Node: "home", PublicDomain: "example.org"}
|
||||
got, said, err := ServedOwnNames(r, m, "npm-package-registry", m.Serves["npm-package-registry"], nil)
|
||||
@@ -42,7 +42,7 @@ func TestAProviderServesItsOwnComposedName(t *testing.T) {
|
||||
}
|
||||
|
||||
// On the provider's own machine the consumer is served the same name (ADR 0346 §2).
|
||||
func TestAConsumerBesideTheProviderIsServedItsName(t *testing.T) {
|
||||
func testAConsumerBesideTheProviderIsServedItsName(t *testing.T) {
|
||||
m := aForgeManifest(t)
|
||||
consumer := mcat.Manifest{Module: "lab", Version: "1", Requires: []string{"npm-package-registry"},
|
||||
Binds: map[string]string{"npm-package-registry": "/var/lib/lab/package-registry.json"}}
|
||||
@@ -103,7 +103,7 @@ func TestAConsumerBesideTheProviderIsServedItsName(t *testing.T) {
|
||||
|
||||
// From another machine, the provider's served values carry what that machine composed, and a key it
|
||||
// left out is said on the consumer's need (ADR 0346 §2, §3).
|
||||
func TestAConsumerElsewhereIsToldWhatTheProviderLeftOut(t *testing.T) {
|
||||
func testAConsumerElsewhereIsToldWhatTheProviderLeftOut(t *testing.T) {
|
||||
consumer := mcat.Manifest{Module: "lab", Version: "1", Requires: []string{"npm-package-registry"},
|
||||
Binds: map[string]string{"npm-package-registry": "/var/lib/lab/package-registry.json"}}
|
||||
node := workstation()
|
||||
@@ -128,7 +128,7 @@ func TestAConsumerElsewhereIsToldWhatTheProviderLeftOut(t *testing.T) {
|
||||
|
||||
// The provider's contributions file carries no own name on a consumer's entry (ADR 0346 §4): only what
|
||||
// is derived for that consumer is there (ADR 0202 §5), and the provider reads its own names in its files.
|
||||
func TestAProvidersOwnNameIsNotOnItsConsumersEntry(t *testing.T) {
|
||||
func testAProvidersOwnNameIsNotOnItsConsumersEntry(t *testing.T) {
|
||||
m := aForgeManifest(t)
|
||||
r := mcat.Resolution{Node: "home", PublicDomain: "example.org", Modules: []mcat.Manifest{m}}
|
||||
derived, err := resolutionDerivedFor(r, "npm-package-registry", "lab_home", "lab", "", nil)
|
||||
@@ -139,3 +139,11 @@ func TestAProvidersOwnNameIsNotOnItsConsumersEntry(t *testing.T) {
|
||||
t.Fatalf("a consumer's entry carries only what was derived for it: %v", derived)
|
||||
}
|
||||
}
|
||||
|
||||
// TestServedOwnNames runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestServedOwnNames(t *testing.T) {
|
||||
t.Run("AProviderServesItsOwnComposedName", testAProviderServesItsOwnComposedName)
|
||||
t.Run("AConsumerBesideTheProviderIsServedItsName", testAConsumerBesideTheProviderIsServedItsName)
|
||||
t.Run("AConsumerElsewhereIsToldWhatTheProviderLeftOut", testAConsumerElsewhereIsToldWhatTheProviderLeftOut)
|
||||
t.Run("AProvidersOwnNameIsNotOnItsConsumersEntry", testAProvidersOwnNameIsNotOnItsConsumersEntry)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func notifier() mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnUnsetPreferenceTakesItsDefault(t *testing.T) {
|
||||
func testAnUnsetPreferenceTakesItsDefault(t *testing.T) {
|
||||
t.Run("the node over the mesh over the default", theNodeOverTheMeshOverTheDefault)
|
||||
m := notifier()
|
||||
for _, layers := range [][]mcat.Layer{nil, {{From: mcat.MeshWideLayer, Values: map[string]any{}}}} {
|
||||
@@ -63,7 +63,7 @@ func theNodeOverTheMeshOverTheDefault(t *testing.T) {
|
||||
|
||||
// Composed for a machine, the way a push writes it: the default reaches the file, and the node's
|
||||
// layer overrides it.
|
||||
func TestAComposedMachineGetsTheDefaultAndTheNodesValue(t *testing.T) {
|
||||
func testAComposedMachineGetsTheDefaultAndTheNodesValue(t *testing.T) {
|
||||
r := anAdoptedAnchor()
|
||||
n := notifier()
|
||||
n.Resources = append(n.Resources, map[string]any{"id": "daemon", "type": "process", "name": "notifier",
|
||||
@@ -101,7 +101,7 @@ func TestAComposedMachineGetsTheDefaultAndTheNodesValue(t *testing.T) {
|
||||
}
|
||||
|
||||
// A default fills ${setting:…} only: it never becomes a key of a mergeable file (issue 168).
|
||||
func TestADefaultIsNotMergedIntoAJSONFile(t *testing.T) {
|
||||
func testADefaultIsNotMergedIntoAJSONFile(t *testing.T) {
|
||||
m := notifier()
|
||||
m.Resources = append(m.Resources, map[string]any{"id": "other", "type": "file", "path": "/x/other.json",
|
||||
"merge": mcat.MergeJSON, "content": `{"keep": 1}`})
|
||||
@@ -115,7 +115,7 @@ func TestADefaultIsNotMergedIntoAJSONFile(t *testing.T) {
|
||||
}
|
||||
|
||||
// A value that is the operator's has no default: no layer setting it is refused by name, as before.
|
||||
func TestAnOperatorsValueWithoutADefaultIsStillRefused(t *testing.T) {
|
||||
func testAnOperatorsValueWithoutADefaultIsStillRefused(t *testing.T) {
|
||||
m := notifier()
|
||||
m.Resources[0]["content"] = "font = Inter ${setting:font-size}\nwidth = ${setting:width}\nfrom = ${setting:domain}\n"
|
||||
err := JudgeSettings(m, nil, false)
|
||||
@@ -127,7 +127,7 @@ func TestAnOperatorsValueWithoutADefaultIsStillRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEveryValueSaysWhereItCameFrom(t *testing.T) {
|
||||
func testEveryValueSaysWhereItCameFrom(t *testing.T) {
|
||||
m := notifier()
|
||||
m.Resources[0]["content"] = m.Resources[0]["content"].(string) + "x = ${setting:position}\n"
|
||||
got := Effective(m, []mcat.Layer{
|
||||
@@ -154,7 +154,7 @@ func TestEveryValueSaysWhereItCameFrom(t *testing.T) {
|
||||
|
||||
// A node may be called `default`. Its layer is a node's like any other: it overrides the module's
|
||||
// default, it merges into a mergeable file, and it is named among what is set.
|
||||
func TestANodeCalledDefaultIsANodesLayer(t *testing.T) {
|
||||
func testANodeCalledDefaultIsANodesLayer(t *testing.T) {
|
||||
m := notifier()
|
||||
node := []mcat.Layer{{From: mcat.DefaultLayer, Values: map[string]any{"font-size": float64(13)}}}
|
||||
file := map[string]any{"type": "file", "content": m.Resources[0]["content"]}
|
||||
@@ -178,7 +178,7 @@ func TestANodeCalledDefaultIsANodesLayer(t *testing.T) {
|
||||
|
||||
// A default fills ${setting:…} in what a module contributes and serves, and never replaces a value a
|
||||
// contribution states itself.
|
||||
func TestADefaultFillsAContributionAndAServedFactButNotALiteral(t *testing.T) {
|
||||
func testADefaultFillsAContributionAndAServedFactButNotALiteral(t *testing.T) {
|
||||
m := notifier()
|
||||
m.Settings["site-title"] = mcat.SettingDeclaration{Kind: mcat.KindPreference, Default: "Notes", Why: "x"}
|
||||
contribution := map[string]any{"title": "${setting:site-title}", "width": "fixed", "port": float64(8080)}
|
||||
@@ -201,3 +201,14 @@ func TestADefaultFillsAContributionAndAServedFactButNotALiteral(t *testing.T) {
|
||||
t.Fatal("a served fact without the defaults was filled")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSettingDefaults runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSettingDefaults(t *testing.T) {
|
||||
t.Run("AnUnsetPreferenceTakesItsDefault", testAnUnsetPreferenceTakesItsDefault)
|
||||
t.Run("AComposedMachineGetsTheDefaultAndTheNodesValue", testAComposedMachineGetsTheDefaultAndTheNodesValue)
|
||||
t.Run("ADefaultIsNotMergedIntoAJSONFile", testADefaultIsNotMergedIntoAJSONFile)
|
||||
t.Run("AnOperatorsValueWithoutADefaultIsStillRefused", testAnOperatorsValueWithoutADefaultIsStillRefused)
|
||||
t.Run("EveryValueSaysWhereItCameFrom", testEveryValueSaysWhereItCameFrom)
|
||||
t.Run("ANodeCalledDefaultIsANodesLayer", testANodeCalledDefaultIsANodesLayer)
|
||||
t.Run("ADefaultFillsAContributionAndAServedFactButNotALiteral", testADefaultFillsAContributionAndAServedFactButNotALiteral)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func copied(r map[string]any) map[string]any {
|
||||
|
||||
// The node's identity reaches the directory's owner, the node's layer over the mesh's, a number given
|
||||
// as a string or as a JSON number alike.
|
||||
func TestASettingOwnsADirectory(t *testing.T) {
|
||||
func testASettingOwnsADirectory(t *testing.T) {
|
||||
m := recycler()
|
||||
layers := []mcat.Layer{
|
||||
{From: "the mesh", Values: map[string]any{"puid": "1000", "pgid": "1000"}},
|
||||
@@ -50,7 +50,7 @@ func TestASettingOwnsADirectory(t *testing.T) {
|
||||
|
||||
// Composed for a machine, the way a push writes it: the directory reaches the node-engine owned by the
|
||||
// number the node's settings name, never by the placeholder.
|
||||
func TestAComposedMachineGetsTheOwnerTheSettingNames(t *testing.T) {
|
||||
func testAComposedMachineGetsTheOwnerTheSettingNames(t *testing.T) {
|
||||
r := anAdoptedAnchor()
|
||||
r.Modules = append(r.Modules, recycler())
|
||||
with := anchorRendering(false)
|
||||
@@ -70,7 +70,7 @@ func TestAComposedMachineGetsTheOwnerTheSettingNames(t *testing.T) {
|
||||
|
||||
// Only a whole number owns a directory: an account's name, text, a sign, a fraction or a value past the
|
||||
// kernel's ids is refused by name, and the directory is left as it was. So is a key nothing sets.
|
||||
func TestAnOwnerSettingThatIsNoNumberIsRefused(t *testing.T) {
|
||||
func testAnOwnerSettingThatIsNoNumberIsRefused(t *testing.T) {
|
||||
m := recycler()
|
||||
for _, bad := range []any{"abc", "root", "", "-1", "+5", "1000:1000", "10 00", "1000\nx", float64(1.5),
|
||||
float64(-3), "4294967295", "99999999999", true} {
|
||||
@@ -95,7 +95,7 @@ func TestAnOwnerSettingThatIsNoNumberIsRefused(t *testing.T) {
|
||||
|
||||
// An owner is written as the number parsed: "0001" and "00" reach the node-engine as 1 and 0, never as text.
|
||||
// Uid 0 is allowed, because a key an owner asks for is the terminal's alone.
|
||||
func TestAnOwnerSettingIsWrittenAsTheNumber(t *testing.T) {
|
||||
func testAnOwnerSettingIsWrittenAsTheNumber(t *testing.T) {
|
||||
m := recycler()
|
||||
r := copied(m.Resources[0])
|
||||
if err := settingInto(r, []mcat.Layer{{From: "ace", Values: map[string]any{"puid": "0001", "pgid": "00"}}}, m.Module); err != nil {
|
||||
@@ -105,3 +105,11 @@ func TestAnOwnerSettingIsWrittenAsTheNumber(t *testing.T) {
|
||||
t.Fatalf("owned by %q, not 1:0", r["owner"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestSettingInOwner runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSettingInOwner(t *testing.T) {
|
||||
t.Run("ASettingOwnsADirectory", testASettingOwnsADirectory)
|
||||
t.Run("AComposedMachineGetsTheOwnerTheSettingNames", testAComposedMachineGetsTheOwnerTheSettingNames)
|
||||
t.Run("AnOwnerSettingThatIsNoNumberIsRefused", testAnOwnerSettingThatIsNoNumberIsRefused)
|
||||
t.Run("AnOwnerSettingIsWrittenAsTheNumber", testAnOwnerSettingIsWrittenAsTheNumber)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func scrubber() mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestASettingNamesAServicesUnit(t *testing.T) {
|
||||
func testASettingNamesAServicesUnit(t *testing.T) {
|
||||
m := scrubber()
|
||||
layers := WithDefaults(m, []mcat.Layer{{From: "ace", Values: map[string]any{"scrub-pool": "storage", "scrub-cadence": "monthly"}}})
|
||||
for i, want := range []string{"zfs-scrub-weekly@storage.timer", "zfs-scrub-monthly@storage.timer"} {
|
||||
@@ -42,7 +42,7 @@ func TestASettingNamesAServicesUnit(t *testing.T) {
|
||||
|
||||
// Composed for a machine, the way a push writes it: the operator's pool and cadence reach the units' names
|
||||
// and the file.
|
||||
func TestAComposedMachineGetsTheUnitTheSettingNames(t *testing.T) {
|
||||
func testAComposedMachineGetsTheUnitTheSettingNames(t *testing.T) {
|
||||
r := anAdoptedAnchor()
|
||||
r.Modules = append(r.Modules, scrubber())
|
||||
with := anchorRendering(false)
|
||||
@@ -69,7 +69,7 @@ func TestAComposedMachineGetsTheUnitTheSettingNames(t *testing.T) {
|
||||
|
||||
// A value that would not make a unit's name is refused by name, never written: a space, a slash, a
|
||||
// newline that would begin a directive, or a second suffix.
|
||||
func TestASettingThatMakesNoUnitNameIsRefused(t *testing.T) {
|
||||
func testASettingThatMakesNoUnitNameIsRefused(t *testing.T) {
|
||||
m := scrubber()
|
||||
for _, bad := range []string{"", "stor age", "a/b", "storage\nExecStart=/bin/sh", "a@b", "$(x)", "*", `a\\x2d`} {
|
||||
r := map[string]any{}
|
||||
@@ -93,7 +93,7 @@ func TestASettingThatMakesNoUnitNameIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnInstanceValueMayNotLeadWithADashNorBeLong(t *testing.T) {
|
||||
func testAnInstanceValueMayNotLeadWithADashNorBeLong(t *testing.T) {
|
||||
m := scrubber()
|
||||
for _, bad := range []string{"-storage", "--help", strings.Repeat("a", 65)} {
|
||||
r := map[string]any{}
|
||||
@@ -113,3 +113,11 @@ func TestAnInstanceValueMayNotLeadWithADashNorBeLong(t *testing.T) {
|
||||
t.Errorf("64 characters: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSettingInUnit runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSettingInUnit(t *testing.T) {
|
||||
t.Run("ASettingNamesAServicesUnit", testASettingNamesAServicesUnit)
|
||||
t.Run("AComposedMachineGetsTheUnitTheSettingNames", testAComposedMachineGetsTheUnitTheSettingNames)
|
||||
t.Run("ASettingThatMakesNoUnitNameIsRefused", testASettingThatMakesNoUnitNameIsRefused)
|
||||
t.Run("AnInstanceValueMayNotLeadWithADashNorBeLong", testAnInstanceValueMayNotLeadWithADashNorBeLong)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// ADR 0155), and a value nothing set is refused by name; and a resource under `if-config` is declared only while a
|
||||
// config value holds (design 42 zfs-owns-zfs §2, ADR 0679 §16 (b)). One table of the two, each row its layers, what it
|
||||
// does to a resource and what comes of it.
|
||||
func TestAConfigValueReachesAResourceAndDecidesWhetherItIsDeclared(t *testing.T) {
|
||||
func testAConfigValueReachesAResourceAndDecidesWhetherItIsDeclared(t *testing.T) {
|
||||
filled := func(content string) func([]mcat.Layer) (string, error) {
|
||||
return func(layers []mcat.Layer) (string, error) {
|
||||
file := map[string]any{"id": "env", "type": "file", "path": "/x/mail.env", "content": content}
|
||||
@@ -120,7 +120,7 @@ var errKeyKept = errors.New("the if-config key was kept in a declared resource")
|
||||
|
||||
// The composition takes a resource out while its condition does not hold, and a value going from set to unset takes it
|
||||
// out of the next composition, which the node-engine removes as it removes any resource that left (design 42 §2).
|
||||
func TestAConfigConditionedResourceIsComposedWhileItsValueHolds(t *testing.T) {
|
||||
func testAConfigConditionedResourceIsComposedWhileItsValueHolds(t *testing.T) {
|
||||
m := mustParse(t, `{"module":"zfs","version":"1","config":{"zed":{"type":"string","default":"off"},"mods":{"type":"list"}},"resources":[
|
||||
{"id":"opts","type":"file","path":"/etc/modprobe.d/zfs.conf","content":"${config-lines:mods:options zfs }\n${config-json}\n"},
|
||||
{"id":"conf","type":"file","path":"/etc/zfs/mesh.conf","content":"x\n"},
|
||||
@@ -149,3 +149,9 @@ func TestAConfigConditionedResourceIsComposedWhileItsValueHolds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestSettingInto runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSettingInto(t *testing.T) {
|
||||
t.Run("AConfigValueReachesAResourceAndDecidesWhetherItIsDeclared", testAConfigValueReachesAResourceAndDecidesWhetherItIsDeclared)
|
||||
t.Run("AConfigConditionedResourceIsComposedWhileItsValueHolds", testAConfigConditionedResourceIsComposedWhileItsValueHolds)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func file(content string, protected ...string) map[string]any {
|
||||
return r
|
||||
}
|
||||
|
||||
func TestAProtectedKeyIsRefusedNotIgnored(t *testing.T) {
|
||||
func testAProtectedKeyIsRefusedNotIgnored(t *testing.T) {
|
||||
// A setting quietly dropped is somebody believing they changed something. Refusing says so
|
||||
// while they are looking at it.
|
||||
_, err := ApplySettings(file(`{"socket":"/run/thing.sock","log":"info"}`, "socket"),
|
||||
@@ -33,7 +33,7 @@ func TestAProtectedKeyIsRefusedNotIgnored(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheSameSettingsAlwaysProduceTheSameBytes(t *testing.T) {
|
||||
func testTheSameSettingsAlwaysProduceTheSameBytes(t *testing.T) {
|
||||
// A file whose lines move for no reason makes every reconcile look like a change, and a
|
||||
// service reflecting it would restart for ever.
|
||||
//
|
||||
@@ -59,7 +59,7 @@ func TestTheSameSettingsAlwaysProduceTheSameBytes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAFileThatDoesNotMergeIsLeftAlone(t *testing.T) {
|
||||
func testAFileThatDoesNotMergeIsLeftAlone(t *testing.T) {
|
||||
plain := map[string]any{"id": "conf", "type": "file", "path": "/etc/thing",
|
||||
"content": "not structured at all\n"}
|
||||
out, err := ApplySettings(plain, []mcat.Layer{{From: "node", Values: map[string]any{"x": 1}}})
|
||||
@@ -71,7 +71,7 @@ func TestAFileThatDoesNotMergeIsLeftAlone(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentThatIsNotJSONIsRefusedWhereSomebodyIsLooking(t *testing.T) {
|
||||
func testContentThatIsNotJSONIsRefusedWhereSomebodyIsLooking(t *testing.T) {
|
||||
// Rather than on the machine, at apply time, as a file the program cannot read.
|
||||
_, err := ApplySettings(file(`this is not json`), nil)
|
||||
if err == nil {
|
||||
@@ -81,7 +81,7 @@ func TestContentThatIsNotJSONIsRefusedWhereSomebodyIsLooking(t *testing.T) {
|
||||
|
||||
// No layer replaces a value the vault fills, at any depth (novox/hq issue 610): searxng's server.secret_key
|
||||
// sits under `server`, a key its file takes, and a layer reaching it was let through by a top-level-only check.
|
||||
func TestNoLayerReplacesAVaultSecretAtAnyDepth(t *testing.T) {
|
||||
func testNoLayerReplacesAVaultSecretAtAnyDepth(t *testing.T) {
|
||||
file := map[string]any{"id": "settings", "type": "file", "merge": mcat.MergeJSON,
|
||||
"content": `{"server": {"secret_key": "${secret:secret}", "port": 8080}, "ui": {"theme": "simple"}, "token": "${secret:token}"}`}
|
||||
layer := func(values map[string]any) []mcat.Layer { return []mcat.Layer{{From: "anchor", Values: values}} }
|
||||
@@ -104,3 +104,12 @@ func TestNoLayerReplacesAVaultSecretAtAnyDepth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestSettings runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSettings(t *testing.T) {
|
||||
t.Run("AProtectedKeyIsRefusedNotIgnored", testAProtectedKeyIsRefusedNotIgnored)
|
||||
t.Run("TheSameSettingsAlwaysProduceTheSameBytes", testTheSameSettingsAlwaysProduceTheSameBytes)
|
||||
t.Run("AFileThatDoesNotMergeIsLeftAlone", testAFileThatDoesNotMergeIsLeftAlone)
|
||||
t.Run("ContentThatIsNotJSONIsRefusedWhereSomebodyIsLooking", testContentThatIsNotJSONIsRefusedWhereSomebodyIsLooking)
|
||||
t.Run("NoLayerReplacesAVaultSecretAtAnyDepth", testNoLayerReplacesAVaultSecretAtAnyDepth)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func minimalRouteProxy() mcat.Manifest {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAModuleWithTwoRoutesGivesTheProviderTwoContributions(t *testing.T) {
|
||||
func testAModuleWithTwoRoutesGivesTheProviderTwoContributions(t *testing.T) {
|
||||
minio, err := decodeForTest([]byte(twoRoutes))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -62,7 +62,7 @@ func TestAModuleWithTwoRoutesGivesTheProviderTwoContributions(t *testing.T) {
|
||||
|
||||
// A module with the ordinary, single-contribution shape resolves exactly as it did before —
|
||||
// ContributesMany being empty must change nothing about it.
|
||||
func TestASingleRouteStillResolvesTheOrdinaryWay(t *testing.T) {
|
||||
func testASingleRouteStillResolvesTheOrdinaryWay(t *testing.T) {
|
||||
got, err := Resolve(shelf(proxy(), published("board", "board", 8080)), []string{"board"}, workstation(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -80,7 +80,7 @@ func TestASingleRouteStillResolvesTheOrdinaryWay(t *testing.T) {
|
||||
// grant and collide with that same contribution's own entry from contributions(), which is
|
||||
// exactly the duplicate a live plan against minio surfaced (files-api appearing once with a
|
||||
// credential, once without, while files got neither).
|
||||
func TestContributionsFromHasNoSingleValueWhenAModuleContributesSeveralTimes(t *testing.T) {
|
||||
func testContributionsFromHasNoSingleValueWhenAModuleContributesSeveralTimes(t *testing.T) {
|
||||
minio, err := decodeForTest([]byte(twoRoutes))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -102,7 +102,7 @@ func TestContributionsFromHasNoSingleValueWhenAModuleContributesSeveralTimes(t *
|
||||
}
|
||||
|
||||
// The ordinary, single-contribution case is unchanged: exactly one match still settles to it.
|
||||
func TestContributionsFromReturnsTheOneValueForAnOrdinaryContribution(t *testing.T) {
|
||||
func testContributionsFromReturnsTheOneValueForAnOrdinaryContribution(t *testing.T) {
|
||||
got, err := Resolve(shelf(proxy(), published("board", "board", 8080)), []string{"board"}, workstation(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -115,3 +115,11 @@ func TestContributionsFromReturnsTheOneValueForAnOrdinaryContribution(t *testing
|
||||
t.Fatalf("the ordinary single contribution should still settle to its own value: %+v", values)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSeveralContributions runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSeveralContributions(t *testing.T) {
|
||||
t.Run("AModuleWithTwoRoutesGivesTheProviderTwoContributions", testAModuleWithTwoRoutesGivesTheProviderTwoContributions)
|
||||
t.Run("ASingleRouteStillResolvesTheOrdinaryWay", testASingleRouteStillResolvesTheOrdinaryWay)
|
||||
t.Run("ContributionsFromHasNoSingleValueWhenAModuleContributesSeveralTimes", testContributionsFromHasNoSingleValueWhenAModuleContributesSeveralTimes)
|
||||
t.Run("ContributionsFromReturnsTheOneValueForAnOrdinaryContribution", testContributionsFromReturnsTheOneValueForAnOrdinaryContribution)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func vaultAndCA() map[string]mcat.Manifest {
|
||||
return shelf(vault, cache, ca)
|
||||
}
|
||||
|
||||
func TestEachLocalNameIsANeedAFileAndAHolderOfItsOwn(t *testing.T) {
|
||||
func testEachLocalNameIsANeedAFileAndAHolderOfItsOwn(t *testing.T) {
|
||||
got, err := Resolve(vaultAndCA(), []string{"mesh-vault", "cache", "ca"}, workstation(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -62,7 +62,7 @@ func TestEachLocalNameIsANeedAFileAndAHolderOfItsOwn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAProviderSeesEachLocalNameAsAHolderOfItsOwn(t *testing.T) {
|
||||
func testAProviderSeesEachLocalNameAsAHolderOfItsOwn(t *testing.T) {
|
||||
r := mcat.Resolution{Modules: []mcat.Manifest{vaultAndCA()["mesh-vault"]}}
|
||||
got, err := resolutionContributions(r, mcat.SettingsBy{}, []mcat.Grant{
|
||||
{Provision: "secret", Consumer: "workstation", From: "ca", Local: "root-key", Sealed: "x"},
|
||||
@@ -85,7 +85,7 @@ func TestAProviderSeesEachLocalNameAsAHolderOfItsOwn(t *testing.T) {
|
||||
|
||||
// And on the provider's machine, two files with two ids — the lab's first run had the declaration
|
||||
// refused for two resources with one identity.
|
||||
func TestAProviderKeepsOneFilePerHolder(t *testing.T) {
|
||||
func testAProviderKeepsOneFilePerHolder(t *testing.T) {
|
||||
got, err := Resolve(vaultAndCA(), []string{"mesh-vault", "cache", "ca"}, workstation(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -110,7 +110,7 @@ func TestAProviderKeepsOneFilePerHolder(t *testing.T) {
|
||||
|
||||
// One file under a local name is still a local name (review C1): the need carries it, the file
|
||||
// is written, and ${secret:<name>} is filled.
|
||||
func TestOneLocalNameIsStillALocalName(t *testing.T) {
|
||||
func testOneLocalNameIsStillALocalName(t *testing.T) {
|
||||
only, _ := decodeForTest([]byte(`{"module":"one","version":"1","requires":["secret"],
|
||||
"secrets":{"secret":{"only":"/var/lib/one/only"}}}`))
|
||||
vault := vaultAndCA()["mesh-vault"]
|
||||
@@ -142,3 +142,11 @@ func TestOneLocalNameIsStillALocalName(t *testing.T) {
|
||||
t.Fatal("the file under the one local name was not written")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSeveralSecrets runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSeveralSecrets(t *testing.T) {
|
||||
t.Run("EachLocalNameIsANeedAFileAndAHolderOfItsOwn", testEachLocalNameIsANeedAFileAndAHolderOfItsOwn)
|
||||
t.Run("AProviderSeesEachLocalNameAsAHolderOfItsOwn", testAProviderSeesEachLocalNameAsAHolderOfItsOwn)
|
||||
t.Run("AProviderKeepsOneFilePerHolder", testAProviderKeepsOneFilePerHolder)
|
||||
t.Run("OneLocalNameIsStillALocalName", testOneLocalNameIsStillALocalName)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func userResource(fields map[string]any) map[string]any {
|
||||
return r
|
||||
}
|
||||
|
||||
func TestAShellAndAGroupOnOneAccountFromTwoModulesResolve(t *testing.T) {
|
||||
func testAShellAndAGroupOnOneAccountFromTwoModulesResolve(t *testing.T) {
|
||||
zsh := mcat.Manifest{Module: "zsh", Resources: []map[string]any{userResource(map[string]any{"shell": "/usr/bin/zsh"})}}
|
||||
docker := mcat.Manifest{Module: "docker", Resources: []map[string]any{userResource(map[string]any{"groups": []any{"docker"}})}}
|
||||
other := mcat.Manifest{Module: "media", Resources: []map[string]any{userResource(map[string]any{"groups": []any{"video"}})}}
|
||||
@@ -27,7 +27,7 @@ func TestAShellAndAGroupOnOneAccountFromTwoModulesResolve(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoModulesSettingOneAccountsShellOrHomeAreRefused(t *testing.T) {
|
||||
func testTwoModulesSettingOneAccountsShellOrHomeAreRefused(t *testing.T) {
|
||||
for _, field := range []string{"shell", "home"} {
|
||||
a := mcat.Manifest{Module: "zsh", Resources: []map[string]any{userResource(map[string]any{field: "/one"})}}
|
||||
b := mcat.Manifest{Module: "fish", Resources: []map[string]any{userResource(map[string]any{field: "/two", "groups": []any{"x"}})}}
|
||||
@@ -41,7 +41,7 @@ func TestTwoModulesSettingOneAccountsShellOrHomeAreRefused(t *testing.T) {
|
||||
|
||||
// An account a module declares only to put in a group is applied where it is written, after the package
|
||||
// that makes the group (novox/hq ADR 0252); one that says how it logs in still goes first (issue 213).
|
||||
func TestAnAccountOnlyGivenGroupsKeepsItsWrittenPlace(t *testing.T) {
|
||||
func testAnAccountOnlyGivenGroupsKeepsItsWrittenPlace(t *testing.T) {
|
||||
compose := func(raw string) []map[string]any {
|
||||
t.Helper()
|
||||
m, err := decodeForTest([]byte(raw))
|
||||
@@ -69,3 +69,10 @@ func TestAnAccountOnlyGivenGroupsKeepsItsWrittenPlace(t *testing.T) {
|
||||
t.Fatalf("an account with a shell is no longer first (%d, package %d): %v", acct, pkg, out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSharedAccount runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestSharedAccount(t *testing.T) {
|
||||
t.Run("AShellAndAGroupOnOneAccountFromTwoModulesResolve", testAShellAndAGroupOnOneAccountFromTwoModulesResolve)
|
||||
t.Run("TwoModulesSettingOneAccountsShellOrHomeAreRefused", testTwoModulesSettingOneAccountsShellOrHomeAreRefused)
|
||||
t.Run("AnAccountOnlyGivenGroupsKeepsItsWrittenPlace", testAnAccountOnlyGivenGroupsKeepsItsWrittenPlace)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// A line break, a carriage return or a NUL in any string of any setting is refused, at any depth, keys too —
|
||||
// where a layer is judged, which is both where it is kept and where it is composed (novox/hq issue 339).
|
||||
func TestASettingHoldsOneLine(t *testing.T) {
|
||||
func testASettingHoldsOneLine(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "mailu"}
|
||||
for _, v := range []any{"a\nDEBUG=1", "a\rb", "a\x00b", []any{"ok", "x\ny"},
|
||||
map[string]any{"k": []any{"ok", map[string]any{"deep": "x\ny"}}}, map[string]any{"k\nx": "v"}} {
|
||||
@@ -30,7 +30,7 @@ func TestASettingHoldsOneLine(t *testing.T) {
|
||||
// Lines are allowed in one setting only: step-ca's `root`, as certificates that encoding/pem decodes and
|
||||
// x509.ParseCertificate parses (novox/hq issue 339). Any other module or key, another label, or a block that is
|
||||
// not a certificate is refused like any other line break.
|
||||
func TestOnlyTheAuthoritysRootMayHoldLines(t *testing.T) {
|
||||
func testOnlyTheAuthoritysRootMayHoldLines(t *testing.T) {
|
||||
ca := mcat.Manifest{Module: "step-ca"}
|
||||
judge := func(m mcat.Manifest, key, v string) error {
|
||||
return JudgeSettings(m, []mcat.Layer{{From: "anchor", Values: map[string]any{key: v}}}, false)
|
||||
@@ -66,7 +66,7 @@ func TestOnlyTheAuthoritysRootMayHoldLines(t *testing.T) {
|
||||
|
||||
// Every character a reader takes as the end of a line is refused, not only \n and \r: vertical tab, form feed,
|
||||
// NEL and the Unicode line and paragraph separators (novox/hq issue 339).
|
||||
func TestEveryLineEndIsRefused(t *testing.T) {
|
||||
func testEveryLineEndIsRefused(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "mailu"}
|
||||
for _, v := range []string{"a\vb", "a\fb", "a\u0085b", "a\u2028b", "a\u2029b"} {
|
||||
if err := JudgeSettings(m, []mcat.Layer{{From: "home", Values: map[string]any{"v": v}}}, false); err == nil ||
|
||||
@@ -75,3 +75,10 @@ func TestEveryLineEndIsRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestTerminalSettings runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestTerminalSettings(t *testing.T) {
|
||||
t.Run("ASettingHoldsOneLine", testASettingHoldsOneLine)
|
||||
t.Run("OnlyTheAuthoritysRootMayHoldLines", testOnlyTheAuthoritysRootMayHoldLines)
|
||||
t.Run("EveryLineEndIsRefused", testEveryLineEndIsRefused)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func toolchainShelf(t *testing.T) map[string]mcat.Manifest {
|
||||
return m
|
||||
}
|
||||
|
||||
func TestAModuleNeedingAToolchainIsRefusedOnANodeWithoutIt(t *testing.T) {
|
||||
func testAModuleNeedingAToolchainIsRefusedOnANodeWithoutIt(t *testing.T) {
|
||||
for _, c := range []struct{ module, provision string }{
|
||||
{"mesh-build-go", "go-toolchain"},
|
||||
{"mesh-build-node", "node-toolchain"},
|
||||
@@ -53,7 +53,7 @@ func TestAModuleNeedingAToolchainIsRefusedOnANodeWithoutIt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAModuleNeedingAToolchainComposesOnANodeWithIt(t *testing.T) {
|
||||
func testAModuleNeedingAToolchainComposesOnANodeWithIt(t *testing.T) {
|
||||
for _, c := range []struct{ module, owner string }{
|
||||
{"mesh-build-go", "go"},
|
||||
{"mesh-build-node", "nodejs"},
|
||||
@@ -76,3 +76,9 @@ func TestAModuleNeedingAToolchainComposesOnANodeWithIt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestToolchainManifests runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestToolchainManifests(t *testing.T) {
|
||||
t.Run("AModuleNeedingAToolchainIsRefusedOnANodeWithoutIt", testAModuleNeedingAToolchainIsRefusedOnANodeWithoutIt)
|
||||
t.Run("AModuleNeedingAToolchainComposesOnANodeWithIt", testAModuleNeedingAToolchainComposesOnANodeWithIt)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func threeConsumers() map[string]mcat.Manifest {
|
||||
)
|
||||
}
|
||||
|
||||
func TestEveryConsumerOnANodeGetsItsOwnCredential(t *testing.T) {
|
||||
func testEveryConsumerOnANodeGetsItsOwnCredential(t *testing.T) {
|
||||
got, err := Resolve(threeConsumers(), []string{"gitea", "keycloak", "umami"},
|
||||
reachable(), mcat.World{Offered: onNetwork("anchor")})
|
||||
if err != nil {
|
||||
@@ -44,7 +44,7 @@ func TestEveryConsumerOnANodeGetsItsOwnCredential(t *testing.T) {
|
||||
// Each consumer's own credential reaches its own file. Matching on the provision alone, every
|
||||
// consumer took whichever need was last — a module handed somebody else's password, which is a
|
||||
// valid credential and therefore fails in a way that looks like a configuration error.
|
||||
func TestEachConsumerGetsItsOwnCredentialAndNotAnothersFile(t *testing.T) {
|
||||
func testEachConsumerGetsItsOwnCredentialAndNotAnothersFile(t *testing.T) {
|
||||
got, err := Resolve(threeConsumers(), []string{"gitea", "keycloak", "umami"},
|
||||
reachable(), mcat.World{Offered: onNetwork("anchor")})
|
||||
if err != nil {
|
||||
@@ -75,7 +75,7 @@ func TestEachConsumerGetsItsOwnCredentialAndNotAnothersFile(t *testing.T) {
|
||||
}
|
||||
|
||||
// The provider is told about all three, separately, and names each grant after the module.
|
||||
func TestAProviderIsToldAboutEveryConsumerOnOneMachine(t *testing.T) {
|
||||
func testAProviderIsToldAboutEveryConsumerOnOneMachine(t *testing.T) {
|
||||
provider, err := Resolve(shelf(mcat.Manifest{
|
||||
Module: "postgres", Version: "1", Provides: mcat.FromAnywhere("postgres-database"),
|
||||
Grants: map[string]string{"postgres-database": "/var/lib/postgres/grants"},
|
||||
@@ -126,3 +126,10 @@ func TestAProviderIsToldAboutEveryConsumerOnOneMachine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestTwoConsumers runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestTwoConsumers(t *testing.T) {
|
||||
t.Run("EveryConsumerOnANodeGetsItsOwnCredential", testEveryConsumerOnANodeGetsItsOwnCredential)
|
||||
t.Run("EachConsumerGetsItsOwnCredentialAndNotAnothersFile", testEachConsumerGetsItsOwnCredentialAndNotAnothersFile)
|
||||
t.Run("AProviderIsToldAboutEveryConsumerOnOneMachine", testAProviderIsToldAboutEveryConsumerOnOneMachine)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func worldWithout(node string) mcat.World {
|
||||
|
||||
// The requirement stays with what writes the file (ADR 0223 part 1): a machine is refused when nothing
|
||||
// in the mesh resolves, rather than given a file listing nothing.
|
||||
func TestEveryUplinkRequiresTheMeshsResolver(t *testing.T) {
|
||||
func testEveryUplinkRequiresTheMeshsResolver(t *testing.T) {
|
||||
for _, uplink := range uplinks {
|
||||
found := false
|
||||
for _, r := range catalogueManifest(t, uplink).Requires {
|
||||
@@ -79,7 +79,7 @@ func TestEveryUplinkRequiresTheMeshsResolver(t *testing.T) {
|
||||
}
|
||||
|
||||
// A holder answers its own requirement, even though the other holder sorts first (issue 258 kept).
|
||||
func TestAHolderAnswersItsOwnRequirement(t *testing.T) {
|
||||
func testAHolderAnswersItsOwnRequirement(t *testing.T) {
|
||||
got, err := Resolve(twoResolverShelf(t), []string{"dnsmasq", "networkmanager"},
|
||||
managing("home"), worldWithout("home"))
|
||||
if err != nil {
|
||||
@@ -94,7 +94,7 @@ func TestAHolderAnswersItsOwnRequirement(t *testing.T) {
|
||||
|
||||
// A seat held once is still held once: a second claimant on another machine is refused while
|
||||
// nothing is on record, and a store recording two holders of it is refused, naming the seat.
|
||||
func TestASingleHolderMeshSeatStillRefusesASecondHolder(t *testing.T) {
|
||||
func testASingleHolderMeshSeatStillRefusesASecondHolder(t *testing.T) {
|
||||
store := shelf(mod("postgres", nil, nil, nil, mcat.Claim{Name: "mesh-store", Scope: mcat.ScopeMesh}))
|
||||
other := mcat.Held{Claim: "mesh-store", Scope: mcat.ScopeMesh, Node: "anchor", Module: "postgres"}
|
||||
if _, err := Resolve(store, []string{"postgres"}, workstation(), mcat.World{Held: []mcat.Held{other}}); err == nil ||
|
||||
@@ -110,7 +110,7 @@ func TestASingleHolderMeshSeatStillRefusesASecondHolder(t *testing.T) {
|
||||
|
||||
// Replicated is not "whoever is assigned": two claimants with nothing on record are refused, as for
|
||||
// any mesh seat, and each holder is added by an act.
|
||||
func TestTwoUnrecordedClaimantsOfTheReplicatedSeatAreRefused(t *testing.T) {
|
||||
func testTwoUnrecordedClaimantsOfTheReplicatedSeatAreRefused(t *testing.T) {
|
||||
w := worldWithout("home")
|
||||
w.Holdings = nil
|
||||
_, err := Resolve(twoResolverShelf(t), []string{"dnsmasq"}, mcat.Node{Name: "home", At: "home.internal"}, w)
|
||||
@@ -120,7 +120,7 @@ func TestTwoUnrecordedClaimantsOfTheReplicatedSeatAreRefused(t *testing.T) {
|
||||
}
|
||||
|
||||
// Every consumer is bound to the same holder whatever order the mesh resolved its machines in.
|
||||
func TestTheFirstHolderIsTheFirstProvider(t *testing.T) {
|
||||
func testTheFirstHolderIsTheFirstProvider(t *testing.T) {
|
||||
providers := []mcat.Provider{{Node: "anchor", Module: "dnsmasq"}, {Node: "home", Module: "dnsmasq"}}
|
||||
for _, held := range [][]mcat.Held{bothResolvers, {bothResolvers[1], bothResolvers[0]}} {
|
||||
if p, ok := HolderAmong("wildcard-resolution", providers, held); !ok || p.Node != "anchor" {
|
||||
@@ -132,7 +132,7 @@ func TestTheFirstHolderIsTheFirstProvider(t *testing.T) {
|
||||
// One host record per machine, beside its wildcard (novox/hq issue 262): a name with a host record
|
||||
// says it exists and has no IPv6 address, where the wildcard alone said there is no such name, and
|
||||
// musl reads that as final.
|
||||
func TestTheResolverHasOneHostRecordPerMachine(t *testing.T) {
|
||||
func testTheResolverHasOneHostRecordPerMachine(t *testing.T) {
|
||||
got, err := Resolve(twoResolverShelf(t), []string{"dnsmasq"}, mcat.Node{Name: "anchor", At: "anchor.internal"}, mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -158,3 +158,13 @@ func TestTheResolverHasOneHostRecordPerMachine(t *testing.T) {
|
||||
t.Errorf("%d host records for %d machines:\n%s", len(records), len(resolverMachines), content)
|
||||
}
|
||||
}
|
||||
|
||||
// TestTwoResolvers runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestTwoResolvers(t *testing.T) {
|
||||
t.Run("EveryUplinkRequiresTheMeshsResolver", testEveryUplinkRequiresTheMeshsResolver)
|
||||
t.Run("AHolderAnswersItsOwnRequirement", testAHolderAnswersItsOwnRequirement)
|
||||
t.Run("ASingleHolderMeshSeatStillRefusesASecondHolder", testASingleHolderMeshSeatStillRefusesASecondHolder)
|
||||
t.Run("TwoUnrecordedClaimantsOfTheReplicatedSeatAreRefused", testTwoUnrecordedClaimantsOfTheReplicatedSeatAreRefused)
|
||||
t.Run("TheFirstHolderIsTheFirstProvider", testTheFirstHolderIsTheFirstProvider)
|
||||
t.Run("TheResolverHasOneHostRecordPerMachine", testTheResolverHasOneHostRecordPerMachine)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ const shellsOperators = "${PORT:-8080} ${SHELL:-/bin/sh} ${SECRET:?unset} ${dir:
|
||||
// Composition refuses the same placeholders in the same words — a manifest the store already holds
|
||||
// was never parsed by this binary — and a namespace the mesh knows, written in a field its pass does
|
||||
// not read, is refused there too, because it would reach the machine as the same literal text.
|
||||
func TestAMisspelledPlaceholderIsRefusedAtComposition(t *testing.T) {
|
||||
func testAMisspelledPlaceholderIsRefusedAtComposition(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
field string
|
||||
r map[string]any
|
||||
@@ -75,7 +75,7 @@ func contentOf(t *testing.T, out []map[string]any, id string) string {
|
||||
// ${setting:…}, and a JSON setting `${level:upper}` merged into a mergeable file, reach the machine as
|
||||
// set — software that templates its own configuration (Log4j's `${env:…}`, Spring's `${timeout:30}`)
|
||||
// is configured exactly this way.
|
||||
func TestAValueHoldingAPlaceholderShapeComposesUnchanged(t *testing.T) {
|
||||
func testAValueHoldingAPlaceholderShapeComposesUnchanged(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "templater", Version: "1", Resources: []map[string]any{
|
||||
{"id": "conf", "type": "file", "path": "/etc/templater.conf", "content": "template=${setting:template}\n"},
|
||||
{"id": "json", "type": "file", "path": "/etc/templater.json", "merge": mcat.MergeJSON, "content": `{"fmt":"plain"}`},
|
||||
@@ -97,7 +97,7 @@ func TestAValueHoldingAPlaceholderShapeComposesUnchanged(t *testing.T) {
|
||||
|
||||
// Contributed shell code is the shell's, and no pass reads it (novox/hq ADR 0204): zsh's own
|
||||
// `${path:t}` is namespace-shaped, and reaches the holder's file untouched.
|
||||
func TestContributedShellCodeIsNotSwept(t *testing.T) {
|
||||
func testContributedShellCodeIsNotSwept(t *testing.T) {
|
||||
modules := []mcat.Manifest{zshHolder(), {Module: "modifier", Shell: []mcat.ShellCode{
|
||||
{For: "zsh", Slot: "normal", Code: "echo ${path:t} ${shel:zsh:first}"},
|
||||
}}}
|
||||
@@ -109,3 +109,10 @@ func TestContributedShellCodeIsNotSwept(t *testing.T) {
|
||||
t.Fatalf("the contributed code did not reach the holder's file as written: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestUnconsumedPlaceholder runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestUnconsumedPlaceholder(t *testing.T) {
|
||||
t.Run("AMisspelledPlaceholderIsRefusedAtComposition", testAMisspelledPlaceholderIsRefusedAtComposition)
|
||||
t.Run("AValueHoldingAPlaceholderShapeComposesUnchanged", testAValueHoldingAPlaceholderShapeComposesUnchanged)
|
||||
t.Run("ContributedShellCodeIsNotSwept", testContributedShellCodeIsNotSwept)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// The zone is the operator's (a setting) and the port is where this machine publishes the listen —
|
||||
// neither is the definition's to state.
|
||||
func TestAZoneIsPlacedFromTheNodesSettingAndPublishedPort(t *testing.T) {
|
||||
func testAZoneIsPlacedFromTheNodesSettingAndPublishedPort(t *testing.T) {
|
||||
m := mcat.Manifest{Module: "lab", Zone: &mcat.Zone{Name: "${setting:zone}", Listen: "dns"},
|
||||
Listens: []mcat.Listening{{Name: "dns", Port: 5353, From: mcat.FromMesh}}}
|
||||
z, err := ZoneOn(m, []mcat.Layer{{From: "node", Values: map[string]any{"zone": "Incus."}}},
|
||||
@@ -26,7 +26,7 @@ func TestAZoneIsPlacedFromTheNodesSettingAndPublishedPort(t *testing.T) {
|
||||
}
|
||||
|
||||
// One module answers a zone, and none may shadow the mesh's names or a public domain.
|
||||
func TestTheMeshRefusesAZoneTwiceOrOneThatShadows(t *testing.T) {
|
||||
func testTheMeshRefusesAZoneTwiceOrOneThatShadows(t *testing.T) {
|
||||
one := mcat.ZoneAt{Zone: "incus", Node: "workstation", Module: "lab", Address: "10.77.0.3", Port: 53}
|
||||
if p := ZonesProblems([]mcat.ZoneAt{one}, "internal", []string{"example.tld"}); len(p) != 0 {
|
||||
t.Fatalf("one ordinary zone was refused: %v", p)
|
||||
@@ -45,3 +45,9 @@ func TestTheMeshRefusesAZoneTwiceOrOneThatShadows(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestZones runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestZones(t *testing.T) {
|
||||
t.Run("AZoneIsPlacedFromTheNodesSettingAndPublishedPort", testAZoneIsPlacedFromTheNodesSettingAndPublishedPort)
|
||||
t.Run("TheMeshRefusesAZoneTwiceOrOneThatShadows", testTheMeshRefusesAZoneTwiceOrOneThatShadows)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func theStoreMesh(t *testing.T) Input {
|
||||
// 1362/AC7 and AC4 (bindings_integration_test.go): a consumer of a provision that keeps its data stays beside its data, one that
|
||||
// does not follows the seat; the laptop's store taken away, the consumer bound there on record is refused, not moved to the
|
||||
// anchor's empty one; a person's pin moves it.
|
||||
func TestAConsumerStaysBesideItsDataUntilAPersonPinsIt(t *testing.T) {
|
||||
func testAConsumerStaysBesideItsDataUntilAPersonPinsIt(t *testing.T) {
|
||||
in := theStoreMesh(t)
|
||||
got, err := Resolve(in, "laptop")
|
||||
if err != nil {
|
||||
@@ -99,7 +99,7 @@ func TestAConsumerStaysBesideItsDataUntilAPersonPinsIt(t *testing.T) {
|
||||
|
||||
// 1362/AC4: a data-keeping consumer bound on record to a provider elsewhere is kept on that provider, and the resolution says
|
||||
// so (Resolution.Kept) when the mesh would answer it otherwise.
|
||||
func TestADataKeepingConsumerBoundElsewhereIsKeptThereAndSaid(t *testing.T) {
|
||||
func testADataKeepingConsumerBoundElsewhereIsKeptThereAndSaid(t *testing.T) {
|
||||
in := theStoreMesh(t)
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
laptop.Assigned = []string{overlay.Name, "resolver", "network", "board"} // no store of its own
|
||||
@@ -153,7 +153,7 @@ func theFilesNeed(t *testing.T, got Resolved) catalogue.Needed {
|
||||
|
||||
// 1362/AC1: a pair credential the Input names as existing with no value, and one it names not at all, are composed with a
|
||||
// stand-in and named foreseen, and nothing is made; one with a value is composed with it and foreseen is empty.
|
||||
func TestAPairCredentialNotHeldIsComposedWithAStandInAndNamedForeseen(t *testing.T) {
|
||||
func testAPairCredentialNotHeldIsComposedWithAStandInAndNamedForeseen(t *testing.T) {
|
||||
mk := func() Input { return theObjectsMesh(t, objects()) }
|
||||
for name, creds := range map[string][]Credential{
|
||||
"no entry": nil,
|
||||
@@ -192,7 +192,7 @@ func TestAPairCredentialNotHeldIsComposedWithAStandInAndNamedForeseen(t *testing
|
||||
|
||||
// 1362/AC2: a credential only a person gives and nobody has is not given and not made: the consumer still resolves without it
|
||||
// (novox/hq ADR 0337 clause 4), said with the controller's words; one given is composed with it.
|
||||
func TestACredentialOnlyAPersonGivesIsNotMadeAndTheConsumerStillResolves(t *testing.T) {
|
||||
func testACredentialOnlyAPersonGivesIsNotMadeAndTheConsumerStillResolves(t *testing.T) {
|
||||
for name, creds := range map[string][]Credential{
|
||||
"no entry": nil,
|
||||
"to be made (never, for one issued outside)": {{Provision: "s3-bucket", Consumer: "laptop", ConsumerModule: "files", Provider: "anchor", State: CredentialWouldMake}},
|
||||
@@ -227,7 +227,7 @@ func TestACredentialOnlyAPersonGivesIsNotMadeAndTheConsumerStillResolves(t *test
|
||||
// 1362/AC3, issue 1966: a fault of one module's own, a credential the send would refuse (a given value sealed to a key a machine no
|
||||
// longer has) or a second claimant of a seat held once, costs that module and not the machine: it is held with the send's words, its
|
||||
// declaration says it left out, and every other module of the machine composes. Not a node whose set does not compose.
|
||||
func TestAModuleWhoseCredentialOrClaimFailsIsHeldAndTheMachineComposes(t *testing.T) {
|
||||
func testAModuleWhoseCredentialOrClaimFailsIsHeldAndTheMachineComposes(t *testing.T) {
|
||||
why := "files's \"s3-bucket\" credential from anchor was accepted from a person, and a sealing key at one end has changed since. " +
|
||||
"The mesh cannot re-seal a value it does not hold: accept it again with `secret accept laptop files s3-bucket --provider anchor`"
|
||||
for _, c := range []struct{ name, module, said string }{
|
||||
@@ -261,7 +261,7 @@ func TestAModuleWhoseCredentialOrClaimFailsIsHeldAndTheMachineComposes(t *testin
|
||||
|
||||
// A record-answered need is filled with the licence key sealed to this holder, and the manager holder is handed the manager node's
|
||||
// public sealing key (novox/hq ADR 0050) and no other.
|
||||
func TestARecordAnsweredNeedGetsItsKeyAndTheManagerItsPublicKey(t *testing.T) {
|
||||
func testARecordAnsweredNeedGetsItsKeyAndTheManagerItsPublicKey(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["assistant"] = catalogue.Manifest{Module: "assistant", Version: "1", Requires: []string{LicenceProvision}}
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
@@ -293,7 +293,7 @@ func TestARecordAnsweredNeedGetsItsKeyAndTheManagerItsPublicKey(t *testing.T) {
|
||||
}
|
||||
|
||||
// 1362/AC5: a node whose own set does not compose returns an error callers can tell from an unreadable Input.
|
||||
func TestANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput(t *testing.T) {
|
||||
func testANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Requires: []string{"two-give-this"}}
|
||||
in.Catalogue["giver-a"] = catalogue.Manifest{Module: "giver-a", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||
@@ -320,7 +320,7 @@ func TestANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput(t *testi
|
||||
}
|
||||
|
||||
// 1362/AC6: settings are returned for every resolved module that has layers in the Input, including one pulled in by another.
|
||||
func TestSettingsAreReturnedForEveryResolvedModuleIncludingOneThatWasPulledIn(t *testing.T) {
|
||||
func testSettingsAreReturnedForEveryResolvedModuleIncludingOneThatWasPulledIn(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["lib"] = catalogue.Manifest{Module: "lib", Version: "1", Provides: catalogue.Offers("blob")}
|
||||
in.Catalogue["app"] = catalogue.Manifest{Module: "app", Version: "1", Requires: []string{"blob"}}
|
||||
@@ -355,7 +355,7 @@ func TestSettingsAreReturnedForEveryResolvedModuleIncludingOneThatWasPulledIn(t
|
||||
|
||||
// Round 1, finding 3: a licence key the Input does not carry (Keys not given) is composed with a stand-in and named foreseen, so the
|
||||
// node still composes; Keys given that lack the holder is the mesh holding none, and the need stays empty.
|
||||
func TestALicenceKeyTheInputDoesNotCarryIsAStandInAndNamedForeseen(t *testing.T) {
|
||||
func testALicenceKeyTheInputDoesNotCarryIsAStandInAndNamedForeseen(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["assistant"] = catalogue.Manifest{Module: "assistant", Version: "1", Requires: []string{LicenceProvision}}
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
@@ -388,7 +388,7 @@ func TestALicenceKeyTheInputDoesNotCarryIsAStandInAndNamedForeseen(t *testing.T)
|
||||
|
||||
// A consumer not handed of a provision whose provider's offer says the helper answers it has that provision in a plan of
|
||||
// its own (issue 774: grafana's route): the composition marks the need answered by the helper, and the plan keys it.
|
||||
func TestANeedAnsweredByTheHelperIsInTheConsumersPlan(t *testing.T) {
|
||||
func testANeedAnsweredByTheHelperIsInTheConsumersPlan(t *testing.T) {
|
||||
in := theStoreMesh(t)
|
||||
store := in.Catalogue["store"]
|
||||
store.Provides = []catalogue.Offer{{Name: "postgres-database", Scope: catalogue.ScopeMesh, AnsweredBy: catalogue.AnsweredByHelper}}
|
||||
@@ -413,3 +413,17 @@ func TestANeedAnsweredByTheHelperIsInTheConsumersPlan(t *testing.T) {
|
||||
t.Fatalf("board's plan is %+v", c.Plans["board"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestResolve runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestResolve(t *testing.T) {
|
||||
t.Run("AConsumerStaysBesideItsDataUntilAPersonPinsIt", testAConsumerStaysBesideItsDataUntilAPersonPinsIt)
|
||||
t.Run("ADataKeepingConsumerBoundElsewhereIsKeptThereAndSaid", testADataKeepingConsumerBoundElsewhereIsKeptThereAndSaid)
|
||||
t.Run("APairCredentialNotHeldIsComposedWithAStandInAndNamedForeseen", testAPairCredentialNotHeldIsComposedWithAStandInAndNamedForeseen)
|
||||
t.Run("ACredentialOnlyAPersonGivesIsNotMadeAndTheConsumerStillResolves", testACredentialOnlyAPersonGivesIsNotMadeAndTheConsumerStillResolves)
|
||||
t.Run("AModuleWhoseCredentialOrClaimFailsIsHeldAndTheMachineComposes", testAModuleWhoseCredentialOrClaimFailsIsHeldAndTheMachineComposes)
|
||||
t.Run("ARecordAnsweredNeedGetsItsKeyAndTheManagerItsPublicKey", testARecordAnsweredNeedGetsItsKeyAndTheManagerItsPublicKey)
|
||||
t.Run("ANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput", testANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput)
|
||||
t.Run("SettingsAreReturnedForEveryResolvedModuleIncludingOneThatWasPulledIn", testSettingsAreReturnedForEveryResolvedModuleIncludingOneThatWasPulledIn)
|
||||
t.Run("ALicenceKeyTheInputDoesNotCarryIsAStandInAndNamedForeseen", testALicenceKeyTheInputDoesNotCarryIsAStandInAndNamedForeseen)
|
||||
t.Run("ANeedAnsweredByTheHelperIsInTheConsumersPlan", testANeedAnsweredByTheHelperIsInTheConsumersPlan)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func providers(w catalogue.World, provision string) []string {
|
||||
|
||||
// 1361/AC1: three nodes each offering a provision; the rest of the mesh, for one of them, offers every other node's and none of its
|
||||
// own, and holds what they hold.
|
||||
func TestTheRestOfTheMeshOffersEveryOtherNodesProvisionsAndNoneOfTheExcluded(t *testing.T) {
|
||||
func testTheRestOfTheMeshOffersEveryOtherNodesProvisionsAndNoneOfTheExcluded(t *testing.T) {
|
||||
in := threeNodes(t)
|
||||
w, passes, left, err := TheRestOfTheMesh(in, "laptop")
|
||||
if err != nil || len(left) != 0 || len(passes.Passes) != 0 {
|
||||
@@ -87,7 +87,7 @@ func TestTheRestOfTheMeshOffersEveryOtherNodesProvisionsAndNoneOfTheExcluded(t *
|
||||
}
|
||||
|
||||
// 1361/AC2: a node whose assigned set does not resolve is left out and named with today's reason, and the others still offer.
|
||||
func TestANodeWhoseSetDoesNotResolveIsLeftOutAndTheOthersStillOffer(t *testing.T) {
|
||||
func testANodeWhoseSetDoesNotResolveIsLeftOutAndTheOthersStillOffer(t *testing.T) {
|
||||
in := threeNodes(t)
|
||||
rivalOne := catalogue.Manifest{Module: "rival-one", Version: "1", Resources: []map[string]any{{"id": "r", "type": "directory", "path": "/var/lib/the-same", "mode": "0700"}}}
|
||||
rivalTwo := catalogue.Manifest{Module: "rival-two", Version: "1", Resources: []map[string]any{{"id": "r", "type": "directory", "path": "/var/lib/the-same", "mode": "0700"}}}
|
||||
@@ -125,7 +125,7 @@ func TestANodeWhoseSetDoesNotResolveIsLeftOutAndTheOthersStillOffer(t *testing.T
|
||||
// 1361/AC3 and AC4 (mesh-controller seat_pass_test.go TestACompositionPassesTheSeatAndWritesOneHandActByTheController, in
|
||||
// the part that is not a write): a seat held once whose holder on record is assigned nowhere and one claimant: the seat
|
||||
// passes to that claimant in the World, and is returned as a pass; Input's holdings are unchanged.
|
||||
func TestASeatWhoseHolderIsAssignedNowhereGoesToItsOnlyClaimant(t *testing.T) {
|
||||
func testASeatWhoseHolderIsAssignedNowhereGoesToItsOnlyClaimant(t *testing.T) {
|
||||
withSeat(t)
|
||||
mk := func() Input {
|
||||
return Input{
|
||||
@@ -159,7 +159,7 @@ func TestASeatWhoseHolderIsAssignedNowhereGoesToItsOnlyClaimant(t *testing.T) {
|
||||
// 1317/AC2 (seat_pass_test.go TestACompositionWithTwoClaimantsRecordsNoneAndSaysSo): two claimants, no pass, the refusal said with
|
||||
// both and the remedy. 1317/AC3 and AC4 (TestACompositionChangesNothingWhileTheHolderIsAssignedOrNobodyClaims): nothing changes while
|
||||
// the holder is assigned, nor with no claimant.
|
||||
func TestNoSeatIsPassedForTwoClaimantsAnAssignedHolderOrNoClaimant(t *testing.T) {
|
||||
func testNoSeatIsPassedForTwoClaimantsAnAssignedHolderOrNoClaimant(t *testing.T) {
|
||||
withSeat(t)
|
||||
held := []catalogue.Held{{Claim: "mesh-broker", Scope: catalogue.ScopeMesh, Node: "novox", Module: "old-broker"}}
|
||||
shelf := map[string]catalogue.Manifest{"gate": aBrokerClaiming("gate"), "other": aBrokerClaiming("other"), "old-broker": aBrokerClaiming("old-broker")}
|
||||
@@ -180,7 +180,7 @@ func TestNoSeatIsPassedForTwoClaimantsAnAssignedHolderOrNoClaimant(t *testing.T)
|
||||
}
|
||||
|
||||
// seat_pass_test.go TestAHolderAssignedButNotOnTheShelfIsNotTakenForGone.
|
||||
func TestAHolderAssignedButNotOnTheShelfIsNotTakenForGone(t *testing.T) {
|
||||
func testAHolderAssignedButNotOnTheShelfIsNotTakenForGone(t *testing.T) {
|
||||
withSeat(t)
|
||||
as := (&composer{}).assignmentsOf(map[string][]string{"novox": {"gate", "old-broker"}})
|
||||
passes, _ := catalogue.SeatsToPassOn(
|
||||
@@ -215,7 +215,7 @@ func TestAHolderAssignedButNotOnTheShelfIsNotTakenForGone(t *testing.T) {
|
||||
|
||||
// The not-resolving node of a view with a holder on record: holdings reach the first pass (novox/hq ADR 0131), so a node running
|
||||
// the next holder beside the current one is not refused as a second holder.
|
||||
func TestAHolderOnRecordSettlesTheSeatInTheRestOfTheMesh(t *testing.T) {
|
||||
func testAHolderOnRecordSettlesTheSeatInTheRestOfTheMesh(t *testing.T) {
|
||||
withSeat(t)
|
||||
in := Input{
|
||||
Catalogue: map[string]catalogue.Manifest{"old-broker": aBrokerClaiming("old-broker"), "gate": aBrokerClaiming("gate")},
|
||||
@@ -238,7 +238,7 @@ func TestAHolderOnRecordSettlesTheSeatInTheRestOfTheMesh(t *testing.T) {
|
||||
|
||||
// Each machine is resolved in the second pass with its own pins, as its plan is (novox/hq issue 188): a pin to a provider that
|
||||
// does not answer is its own refusal, so the machine is left out for it; the same machine without the pin is not.
|
||||
func TestEachNodeIsResolvedWithItsOwnPinsInTheRestOfTheMesh(t *testing.T) {
|
||||
func testEachNodeIsResolvedWithItsOwnPinsInTheRestOfTheMesh(t *testing.T) {
|
||||
in := threeNodes(t)
|
||||
in.Nodes = append(in.Nodes, Node{Name: "newt", Place: Place{Site: "there", Address: "10.77.0.4"}, Assigned: []string{overlay.Name, "files"}, Capabilities: map[string]bool{}})
|
||||
_, _, left, err := TheRestOfTheMesh(in, "")
|
||||
@@ -254,7 +254,7 @@ func TestEachNodeIsResolvedWithItsOwnPinsInTheRestOfTheMesh(t *testing.T) {
|
||||
|
||||
// ADR 0660: a holder on record that is still assigned, whose manifest no longer claims the seat, has left it; the seat is
|
||||
// composed with the one claimant, the pass is returned and said, and Input's holdings (the record) are not written.
|
||||
func TestAHolderWhoseManifestDroppedTheSeatGoesToItsOnlyClaimant(t *testing.T) {
|
||||
func testAHolderWhoseManifestDroppedTheSeatGoesToItsOnlyClaimant(t *testing.T) {
|
||||
withSeat(t)
|
||||
mk := func(claimants ...string) Input {
|
||||
cat := map[string]catalogue.Manifest{"old-broker": {Module: "old-broker"}}
|
||||
@@ -301,3 +301,15 @@ func TestAHolderWhoseManifestDroppedTheSeatGoesToItsOnlyClaimant(t *testing.T) {
|
||||
t.Fatalf("the answer does not say the pass: %v %q", err, said)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRest runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
||||
func TestRest(t *testing.T) {
|
||||
t.Run("TheRestOfTheMeshOffersEveryOtherNodesProvisionsAndNoneOfTheExcluded", testTheRestOfTheMeshOffersEveryOtherNodesProvisionsAndNoneOfTheExcluded)
|
||||
t.Run("ANodeWhoseSetDoesNotResolveIsLeftOutAndTheOthersStillOffer", testANodeWhoseSetDoesNotResolveIsLeftOutAndTheOthersStillOffer)
|
||||
t.Run("ASeatWhoseHolderIsAssignedNowhereGoesToItsOnlyClaimant", testASeatWhoseHolderIsAssignedNowhereGoesToItsOnlyClaimant)
|
||||
t.Run("NoSeatIsPassedForTwoClaimantsAnAssignedHolderOrNoClaimant", testNoSeatIsPassedForTwoClaimantsAnAssignedHolderOrNoClaimant)
|
||||
t.Run("AHolderAssignedButNotOnTheShelfIsNotTakenForGone", testAHolderAssignedButNotOnTheShelfIsNotTakenForGone)
|
||||
t.Run("AHolderOnRecordSettlesTheSeatInTheRestOfTheMesh", testAHolderOnRecordSettlesTheSeatInTheRestOfTheMesh)
|
||||
t.Run("EachNodeIsResolvedWithItsOwnPinsInTheRestOfTheMesh", testEachNodeIsResolvedWithItsOwnPinsInTheRestOfTheMesh)
|
||||
t.Run("AHolderWhoseManifestDroppedTheSeatGoesToItsOnlyClaimant", testAHolderWhoseManifestDroppedTheSeatGoesToItsOnlyClaimant)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user