selfcompose: the manifest of the build a module runs here is answered in one place; every step reads it there (A-484)
Entry of the running build, else the composition this node runs of it, else the module's trunk manifest through the seat mesh-catalog's verb module; said once per module and source; words naming the three where none answers. Read there: a held module's offer (frombus Scope.RunningManifest), FormChanges (A-483), the store holder and the stand of a running module without an entry (A-461d, A-480a), and the tool composition. Builds: design 47 G A-484, A-480, A-480a, A-483, A-461d, A-482
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package selfcompose
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"github.com/novox/mesh-host/internal/compositions"
|
||||
)
|
||||
|
||||
// A-484: the manifest of the build a module runs here is answered in one place, from the entry of the running build, else the
|
||||
// composition this node runs of it, else the module's trunk manifest; it says its source once per module and source, and where
|
||||
// none answers its words name the three.
|
||||
func TestTheManifestOfTheRunningBuildIsReadInOnePlace(t *testing.T) {
|
||||
running := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||
other := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||
body := `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}`
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
entry string // the entry held, by fingerprint ("running", "other") or none
|
||||
composition string // the composition this node runs: its build ("running", "other") or none
|
||||
data bool
|
||||
trunk bool
|
||||
wantSource string
|
||||
wantKnown bool
|
||||
}{
|
||||
{"its entry answers first", "running", "running", false, true, SourceEntry, true},
|
||||
{"the entry of the composition's build is the running build's", "other", "other", true, true, SourceEntry, true},
|
||||
{"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, SourceTrunk, true},
|
||||
{"a composition and no trunk answer: its build and its data alone", "", "running", true, false, SourceComposition, false},
|
||||
{"the trunk alone", "", "", false, true, SourceTrunk, true},
|
||||
{"none answers", "", "", false, false, "", false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
env := newFakeBus().env()
|
||||
env.Node = "n1"
|
||||
var said []string
|
||||
env.Say = func(s string) { said = append(said, s) }
|
||||
if tc.composition != "" {
|
||||
fp := map[string]string{"running": running, "other": other}[tc.composition]
|
||||
env.Running = func() []compositions.Composed {
|
||||
return []compositions.Composed{{Node: "n1", Module: "xorg", FP: fp, Data: tc.data}}
|
||||
}
|
||||
}
|
||||
c := New(env)
|
||||
c.mu.Lock()
|
||||
c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "xorg"}}}
|
||||
c.heard = map[string]map[string]heardRun{"n1": {"xorg": {fingerprint: running}}}
|
||||
if tc.trunk {
|
||||
var man map[string]any
|
||||
_ = json.Unmarshal([]byte(body), &man)
|
||||
c.trunkBuilds = map[string]trunkBuild{"xorg": {running: running, fp: other, manifest: man}}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
if tc.entry != "" {
|
||||
c.holdEntry(t, "xorg", map[string]string{"running": running, "other": other}[tc.entry], body)
|
||||
}
|
||||
a := c.runningManifest("n1", "xorg", "")
|
||||
again := c.runningManifest("n1", "xorg", "")
|
||||
if a.Source != tc.wantSource || a.Known != tc.wantKnown || (a.Known && len(a.Manifest.Provides) != 1) {
|
||||
t.Fatalf("answered %q (known %v, provides %d), want %q (known %v)", a.Source, a.Known, len(a.Manifest.Provides), tc.wantSource, tc.wantKnown)
|
||||
}
|
||||
if tc.wantSource != "" && (len(said) != 1 || again.Said != "" || !strings.Contains(said[0], tc.wantSource)) {
|
||||
t.Errorf("said %q (and %q again), want its source once", said, again.Said)
|
||||
}
|
||||
if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry {
|
||||
t.Errorf("the composition's data = %v, want %v", a.Data, tc.data)
|
||||
}
|
||||
if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceComposition) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) {
|
||||
t.Errorf("the words of an answer that reads no manifest are %q, want the three sources named", a.Why)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user