The fifteen desktop modules' tools tests failed on every manifest with "json: unknown field class": a test helper copied into each module decoded module.json into its own struct, refusing unknown fields. Manifest strictness is the catalog check's alone, and the manifest's form is a contract read through mesh-sdk's catalogue package, so the copied `manifest` struct and its reader go from the fifteen desktop modules and pacman; each test reads module.json with catalogue.Decode and asserts only the module's own promises (claims, files, tools) on catalogue.Manifest. Builds: design 47 H2 H-A-498, H-A-498 addendum
136 lines
4.5 KiB
Go
136 lines
4.5 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// feh's shape (novox/hq ADR 0208): no seat; it requires the X display on its own machine, carries
|
|
// the wallpaper as its own archive (ADR 0205), owns ~/.fehbg pointing at it, and sets it once from
|
|
// the session's start.
|
|
|
|
func TestItRequiresTheXDisplayAndClaimsNothing(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
if m.Module != "feh" || m.DefinesSeats != nil || m.Claims != nil {
|
|
t.Fatalf("module %q, seats %v, claims %v", m.Module, m.DefinesSeats, m.Claims)
|
|
}
|
|
if !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
|
|
t.Fatalf("requires: %v", m.Requires)
|
|
}
|
|
if present, absent := packages(m); !reflect.DeepEqual(present, []string{"feh"}) || absent != nil {
|
|
t.Fatalf("packages: %v, absent %v", present, absent)
|
|
}
|
|
}
|
|
|
|
func TestTheWallpaperIsTheModulesOwnArchive(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
a := resource(t, m, "wallpapers")
|
|
if a["type"] != "archive" || a["artifact"] != "wallpapers" || a["path"] != "${machine:account-home}/.local/share/feh/wallpapers" || a["owner"] != "${machine:account}" {
|
|
t.Fatalf("%v", a)
|
|
}
|
|
found := false
|
|
for _, art := range m.Build.Artifacts {
|
|
if art.Name == "wallpapers" && art.Kind == "archive" && art.From == "wallpaper" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("no archive artifact built from wallpaper/")
|
|
}
|
|
info, err := os.Stat(filepath.Join("..", "..", "wallpaper", "default.jpg"))
|
|
if err != nil || info.Size() == 0 {
|
|
t.Fatalf("the image: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestFehbgIsOwnedAndTheSessionStartRunsItOnce(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
fromTemplate(t, m, "fehbg", "files/fehbg")
|
|
f := resource(t, m, "fehbg")
|
|
if f["path"] != "${machine:account-home}/.fehbg" || f["mode"] != "0755" {
|
|
t.Fatalf("%v", f)
|
|
}
|
|
if c := templateText(t, m, "fehbg"); !strings.Contains(c, "$HOME/.local/share/feh/wallpapers/default.jpg") || strings.Contains(c, ".hal") {
|
|
t.Fatalf("%s", c)
|
|
}
|
|
if len(shell(t, m)) != 1 || shell(t, m)[0].For != "xinitrc" || shell(t, m)[0].Slot != "normal" || strings.Count(shell(t, m)[0].Code, `"$HOME/.fehbg"`) != 1 {
|
|
t.Fatalf("%+v", shell(t, m))
|
|
}
|
|
}
|
|
|
|
func TestTheKeyThatRestoresTheWallpaperIsAnI3DropIn(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
i3LinesAreSource(t, m, "files/i3/50-feh.conf")
|
|
if p := i3Lines(m); p == "" {
|
|
t.Fatalf("path: %v", p)
|
|
}
|
|
if c := i3Lines(m); !strings.Contains(c, "bindsym $mod+Shift+b exec --no-startup-id ~/.fehbg\n") {
|
|
t.Fatalf("%s", c)
|
|
}
|
|
}
|
|
|
|
func TestTheToolsAgreeWithTheManifest(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
checkTheToolsAgree(t, m)
|
|
checkNoSecretsOrInstallationNames(t)
|
|
}
|
|
|
|
// No file resource carries its text inline (novox/hq ADR 0349 §2).
|
|
func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
everyFileIsATemplate(t, m)
|
|
}
|