Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)
This commit is contained in:
@@ -119,7 +119,7 @@ func TestItInstallsTheServerItsStartAndTheToolsItsVerbsRun(t *testing.T) {
|
||||
|
||||
func TestTheResourcesFileHoldsTheDefaultsAndTheThreeSlots(t *testing.T) {
|
||||
r := readManifest(t).resource(t, "xresources")
|
||||
c := r["content"].(string)
|
||||
c := templateText(t, r)
|
||||
if r["path"] != "${machine:account-home}/.config/xorg/xresources" || r["into"] != nil {
|
||||
t.Fatalf("an owned file: %v", r)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func TestTheSessionStartIsABlockAtTheStartInTheOrderTheDecisionGives(t *testing.
|
||||
if r["path"] != "${machine:account-home}/.xinitrc" || r["into"] != "block" || r["at"] != "start" {
|
||||
t.Fatalf("%v", r)
|
||||
}
|
||||
c := r["content"].(string)
|
||||
c := templateText(t, r)
|
||||
order := []string{
|
||||
". \"${machine:account-home}/.config/mesh/environment.sh\"",
|
||||
"dbus-update-activation-environment --systemd $mesh_words",
|
||||
@@ -205,7 +205,7 @@ func TestTheBlockRunsTheEnvironmentTheImportTheResourcesTheSlotsAndEndsInTheSess
|
||||
for _, prog := range []string{"dbus-update-activation-environment", "xrdb", "autorandr", "the-session"} {
|
||||
os.WriteFile(filepath.Join(bin, prog), []byte("#!/bin/sh\necho \""+prog+" $*\" >> \""+log+"\"\n"), 0o755)
|
||||
}
|
||||
block := render(readManifest(t).resource(t, "xinitrc")["content"].(string), home, map[string]string{
|
||||
block := render(templateText(t, readManifest(t).resource(t, "xinitrc")), home, map[string]string{
|
||||
"normal": "echo normal >> \"" + log + "\"",
|
||||
"last": "exec the-session",
|
||||
})
|
||||
@@ -237,7 +237,8 @@ func TestTheBlockRunsTheEnvironmentTheImportTheResourcesTheSlotsAndEndsInTheSess
|
||||
|
||||
func TestTheBundleIsGoBuiltForArch(t *testing.T) {
|
||||
a := readManifest(t).Build.Artifacts
|
||||
if len(a) != 1 || a[0]["language"] != "go" || a[0]["system"] != "arch" || a[0]["from"] != "cmd/xorg" || a[0]["binary"] != "xorg" {
|
||||
// The bundle, and beside it the archive the build packs the templates in files/ into (novox/hq ADR 0349 §2).
|
||||
if len(a) != 2 || a[1]["name"] != "files" || a[0]["language"] != "go" || a[0]["system"] != "arch" || a[0]["from"] != "cmd/xorg" || a[0]["binary"] != "xorg" {
|
||||
t.Fatalf("%v", a)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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