Feature 57 (config and provisioning): release the catalogue, the reviewed release branch merged with main, on top of main
This commit is contained in:
@@ -16,7 +16,7 @@ type manifest struct {
|
||||
Invokes []string `json:"invokes"`
|
||||
Claims []map[string]any `json:"claims"`
|
||||
State []map[string]any `json:"state"`
|
||||
Settings map[string]map[string]any `json:"settings"`
|
||||
Config map[string]map[string]any `json:"config"`
|
||||
OwnSecrets map[string]map[string]string `json:"own-secrets"`
|
||||
Resources []map[string]any `json:"resources"`
|
||||
}
|
||||
@@ -31,7 +31,15 @@ func readManifest(t *testing.T) (manifest, string) {
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return m, string(raw)
|
||||
// And the text of each file it places, kept in files/ as its template (novox/hq ADR 0349 §2): what the
|
||||
// machine is given is judged as a whole.
|
||||
text := string(raw)
|
||||
for _, r := range m.Resources {
|
||||
if _, has := r["template"]; has {
|
||||
text += templateText(t, r)
|
||||
}
|
||||
}
|
||||
return m, text
|
||||
}
|
||||
|
||||
// The tools the bundle serves are the manifest's tools and the seat's verbs, each saying whether it reads
|
||||
@@ -91,13 +99,14 @@ func TestTheManifestNamesWhatTheBundleServesAndWhatItNeeds(t *testing.T) {
|
||||
if got := PasswordFile("${dir:state}", "games"); got != strings.Replace(sec["path"], "*", "games", 1) {
|
||||
t.Errorf("the process reads %s, the mesh places %s", got, sec["path"])
|
||||
}
|
||||
if _, has := m.Settings["smb-users"]; has || len(m.Settings) != 2 {
|
||||
t.Errorf("an SMB source's username is in its entry of sources, not a setting of its own: %v", m.Settings)
|
||||
if _, has := m.Config["smb-users"]; has || len(m.Config) != 2 {
|
||||
t.Errorf("an SMB source's username is in its entry of sources, not a config value of its own: %v", m.Config)
|
||||
}
|
||||
for _, key := range []string{"shares", "sources"} {
|
||||
s := m.Settings[key]
|
||||
if s["kind"] != "preference" || s["default"] != None || s["why"] == "" || !strings.Contains(raw, "${setting:"+key+"}") {
|
||||
t.Errorf("setting %s: %v", key, s)
|
||||
s := m.Config[key]
|
||||
if s["type"] != "string" || s["default"] != None || s["description"] == "" || s["trusted"] != true ||
|
||||
!strings.Contains(raw, "${config:"+key+"}") {
|
||||
t.Errorf("config value %s: %v", key, s)
|
||||
}
|
||||
}
|
||||
// A machine's or a person's name, as a word: "novox/hq" names the record, not the machine.
|
||||
@@ -137,7 +146,7 @@ func TestTheProcessesAreRootAndJudgedByTheirUnitAndTheHealthTool(t *testing.T) {
|
||||
if byID["config"]["path"] != ConfigFile {
|
||||
t.Errorf("the config file is %v, the code reads %s", byID["config"]["path"], ConfigFile)
|
||||
}
|
||||
content, _ := byID["config"]["content"].(string)
|
||||
content := templateText(t, byID["config"])
|
||||
cfg := ParseConfig(content)
|
||||
if len(cfg.Problems) != 0 && !strings.Contains(strings.Join(cfg.Problems, " "), "${") {
|
||||
t.Errorf("the config's template reads: %v", cfg.Problems)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The module's directory, where its manifest and its files/ are.
|
||||
const moduleDir = "../.."
|
||||
|
||||
// templateText is the text a file resource places on the machine: its template's, in the module's files/
|
||||
// (novox/hq ADR 0349 §2). A resource that names no template, or a template that is not there, fails the test.
|
||||
func templateText(t *testing.T, r map[string]any) string {
|
||||
t.Helper()
|
||||
name, _ := r["template"].(string)
|
||||
if name == "" {
|
||||
t.Fatalf("resource %v names no template", r["id"])
|
||||
}
|
||||
raw, err := os.ReadFile(filepath.Join(moduleDir, filepath.FromSlash(name)))
|
||||
if err != nil {
|
||||
t.Fatalf("resource %v names %s: %v", r["id"], name, err)
|
||||
}
|
||||
return string(raw)
|
||||
}
|
||||
|
||||
// No file resource carries its text inline: each names its template in files/, and the build packs files/
|
||||
// into the one archive the controller reads the templates back from (novox/hq ADR 0349 §2).
|
||||
func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
|
||||
raw, err := os.ReadFile(filepath.Join(moduleDir, "module.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var m struct {
|
||||
Resources []map[string]any `json:"resources"`
|
||||
Build struct {
|
||||
Artifacts []map[string]any `json:"artifacts"`
|
||||
} `json:"build"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, r := range m.Resources {
|
||||
if _, inline := r["content"]; inline {
|
||||
t.Errorf("resource %v keeps its text inline: keep it in files/ and name it as the template", r["id"])
|
||||
}
|
||||
if r["type"] == "file" {
|
||||
templateText(t, r)
|
||||
}
|
||||
}
|
||||
packs := 0
|
||||
for _, a := range m.Build.Artifacts {
|
||||
if a["kind"] == "archive" && a["from"] == "files" {
|
||||
packs++
|
||||
if a["name"] != "files" {
|
||||
t.Errorf("the templates archive is named %v, not files", a["name"])
|
||||
}
|
||||
}
|
||||
}
|
||||
if packs != 1 {
|
||||
t.Errorf("the build packs files/ into %d archives, not one", packs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user