package resolution import ( "testing" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) // The runtime-health is composed onto .own-runtime, in the words the node-engine takes; to an engine // that does not read health it is not sent, as for every resource. func TestARuntimeHealthIsComposedOntoTheModulesOwnRuntime(t *testing.T) { goRuntime := mcat.Manifest{Module: mcat.RuntimeModule, Version: "1", OwnSecrets: mcat.OwnSecrets{"broker": {Path: "/var/lib/mesh/" + mcat.RuntimeModule + "/broker"}}, Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "runtime", Kind: mcat.ArtifactBundle, Language: "go", System: "arch", From: "cmd/node-tools"}}}} goRuntime, err := goRuntime.Resolve([]mcat.Built{{Name: "runtime", Kind: mcat.ArtifactBundle, Reference: mcat.ArtifactStoreScheme + mcat.RuntimeModule + "/runtime/blobs/" + bundleDigest, Digest: bundleDigest}}) if err != nil { t.Fatal(err) } keeper := aToolsModule(t, "keeper", "tools/index.js") keeper.Tools = []string{"keeper_health"} keeper.RunsAs, keeper.SecretsOwner = "keeper", "keeper" keeper.OwnSecrets = mcat.OwnSecrets{"broker": {Path: "/var/lib/keeper/broker"}} keeper.RuntimeHealth = map[string]any{"kind": "tool", "tool": "keeper_health", "interval": "60s", "timeout": "10s", "looks": 2.0} for _, reads := range []bool{true, false} { with := mcat.Rendering{ArtifactStore: "anchor.internal:5101", ReadsHealth: reads, Needed: map[string]map[string]string{mcat.RuntimeModule: {"broker": "sealed"}, "keeper": {"broker": "own"}}} out, err := Declaration(mcat.Resolution{Node: "anchor", Account: "ops", Modules: []mcat.Manifest{keeper, goRuntime}}, with) if err != nil { t.Fatal(err) } own := fileNamed(out, "keeper."+mcat.OwnRuntimeID()) if own == nil { t.Fatalf("no own runtime: %v", ids(out)) } h, has := own[mcat.HealthField].(map[string]any) if !reads { if has { t.Errorf("health sent to an engine that does not read it: %v", h) } continue } if !has || h["kind"] != "tool" || h["tool"] != "keeper_health" || h["interval"] != "1m0s" || h["timeout"] != "10s" || h["looks"] != 2 || h["grace"] != "1m0s" { t.Errorf("its own runtime's health: %v", own[mcat.HealthField]) } if machine := fileNamed(out, mcat.RuntimeModule+"."+RuntimeProcessID()); machine[mcat.HealthField] != nil { t.Errorf("the machine's runtime was given the module's health: %v", machine[mcat.HealthField]) } } // The catalogue's own manifest is not written into. if _, ok := keeper.RuntimeHealth.(map[string]any)["grace"]; ok { t.Error("composing wrote the defaults into the catalogue's manifest") } }