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
91 lines
3.4 KiB
Go
91 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// The blocks other modules contribute are a collection of text (design 57 L3, novox/hq ADR 0349 clause 13): each
|
|
// contributor gives its block in i3status-rust's grammar, and the bars place the collection where they want it.
|
|
|
|
func TestEachBarPlacesBothPlacesOnce(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)
|
|
}
|
|
for _, bar := range []string{"bottom", "top"} {
|
|
content := templateText(t, m, bar+"-bar")
|
|
for _, place := range []string{"resources", "status"} {
|
|
ph := "${collected:contribution:node-bar:block:bar=" + bar + ",place=" + place + "}"
|
|
if strings.Count(content, ph) != 1 {
|
|
t.Errorf("the %s bar places %s %d times", bar, ph, strings.Count(content, ph))
|
|
}
|
|
}
|
|
}
|
|
bottom := templateText(t, m, "bottom-bar")
|
|
resources := strings.Index(bottom, "place=resources")
|
|
if !(strings.Index(bottom, `block = "memory"`) < resources && resources < strings.Index(bottom, `block = "docker"`)) ||
|
|
!(strings.Index(bottom, `block = "sound"`) < strings.Index(bottom, "place=status") &&
|
|
strings.Index(bottom, "place=status") < strings.Index(bottom, `block = "weather"`)) {
|
|
t.Fatal("the places are not beside the memory and beside the sound")
|
|
}
|
|
}
|
|
|
|
func TestTheMemoryIsWhatProgramsHoldNotTheCache(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)
|
|
}
|
|
bottom := templateText(t, m, "bottom-bar")
|
|
if !strings.Contains(bottom, `format = "$icon $mem_used.eng(w:2) ($mem_used_percents.eng(w:2))"`) ||
|
|
strings.Contains(bottom, "mem_total_used") {
|
|
t.Fatal("the memory block counts the cache as used")
|
|
}
|
|
}
|
|
|
|
func TestABarNamesNoTemplateOfItsOwnForTheBlocksItPlaces(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)
|
|
}
|
|
for _, id := range []string{"top-bar", "bottom-bar"} {
|
|
if strings.Contains(templateText(t, m, id), "${contribution:") {
|
|
t.Errorf("the %s still places a contribution the old way", id)
|
|
}
|
|
}
|
|
if _, err := os.Stat("../../files/block.tmpl"); err == nil {
|
|
t.Error("files/block.tmpl is still there, and no claim renders it")
|
|
}
|
|
}
|
|
|
|
func TestTheBundleFindsTheValueARenderedBlockShows(t *testing.T) {
|
|
// What the power module's block renders on a machine called laptop.
|
|
got := "[[block]]\nblock = \"custom\"\ncommand = \"~/.local/bin/i3status-value power.draw laptop\"\ninterval = 5\nhide_when_empty = true\n\n"
|
|
f := filepath.Join(t.TempDir(), "bottom-bar.toml")
|
|
if err := os.WriteFile(f, []byte(got), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if w := wantedIn([]string{f}); len(w) != 1 || w[0] != (Wanted{"power.draw", "laptop"}) {
|
|
t.Fatalf("%v", w)
|
|
}
|
|
}
|