package ownmanifest import ( "os" "path/filepath" "strings" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" "github.com/novox/mesh-controller/internal/beside" ) // Moved from internal/catalogue (issue 1381) with the tests below; each helper is the one the old package's tests // shared, over the SDK's exported API. var bundleDigest = "sha256:" + strings.Repeat("b", 64) func fileNamed(out []map[string]any, id string) map[string]any { for _, r := range out { if r["id"] == id { return r } } return nil } func shelf(ms ...catalogue.Manifest) map[string]catalogue.Manifest { out := map[string]catalogue.Manifest{} for _, m := range ms { out[m.Module] = m } return out } func reachable() catalogue.Node { return catalogue.Node{Name: "workstation", Site: "house", At: "workstation.internal", Capabilities: map[string]bool{"seat": true, "container-runtime": true}} } func names(r catalogue.Resolution) []string { var out []string for _, m := range r.Modules { out = append(out, m.Module) } return out } func boundFrom(t *testing.T, r catalogue.Resolution, consumer, provision string) catalogue.Needed { t.Helper() for _, n := range r.Needs { if n.For == consumer && n.Name == provision { return n } } t.Fatalf("no binding of %s for %s: %+v", consumer, provision, r.Needs) return catalogue.Needed{} } // moduleTree is where a module is read from: this repository's own modules/ when it lives whole here // (novox/hq ADR 0420 §1, issue 1019: build-agent and route-proxy), with this repository as the tree root; // otherwise the catalogue beside, with the catalogue as the root. func moduleTree(t *testing.T, module string) (root, dir string) { t.Helper() own := filepath.Join("..", "..", "modules", module) if _, err := os.Stat(filepath.Join(own, "module.json")); err == nil { return filepath.Join("..", ".."), own } return beside.Dir(t, "mesh-catalog"), filepath.Join(beside.Catalogue(t), module) } func catalogueManifest(t *testing.T, module string) catalogue.Manifest { t.Helper() root, dir := moduleTree(t, module) m, err := catalogue.ReadTreeManifest(root, dir) if err != nil { t.Fatalf("%s does not parse:\n%v", module, err) } return m } // catalogueResolved is a catalogue module as the mesh holds it once built: the manifest as written, resolved against // what the build produced besides the archive its templates are packed into (novox/hq ADR 0349 §2). func catalogueResolved(t *testing.T, module string, built ...catalogue.Built) catalogue.Manifest { t.Helper() root, dir := moduleTree(t, module) m, err := catalogue.ReadTreeManifestWritten(root, dir) if err != nil { t.Fatalf("%s does not parse:\n%v", module, err) } if name := catalogue.TemplatesArtifact(m); name != "" { read, err := catalogue.ReadTemplates(m, dir) if err != nil { t.Fatalf("%s: %v", module, err) } // By the path inside the archive, as the build reads it back, not by the path in the module's directory. texts := map[string]string{} for path, text := range read { texts[strings.TrimPrefix(path, m.TemplatesDir()+"/")] = text } built = append(built, catalogue.Built{Name: name, Kind: catalogue.ArtifactArchive, Reference: catalogue.ArtifactStoreScheme + module + "/" + name + "/blobs/" + bundleDigest, Digest: bundleDigest, Texts: texts}) } held, err := m.Resolve(built) if err != nil { t.Fatalf("%s does not resolve against its own build: %v", module, err) } return held }