Read each module's own manifest through mesh-sdk's catalogue reader (H-A-498)
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
This commit is contained in:
@@ -5,15 +5,25 @@ import (
|
||||
"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) {
|
||||
m := readManifest(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 := m.text(t, bar+"-bar")
|
||||
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 {
|
||||
@@ -21,7 +31,7 @@ func TestEachBarPlacesBothPlacesOnce(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
bottom := m.text(t, "bottom-bar")
|
||||
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") &&
|
||||
@@ -31,7 +41,16 @@ func TestEachBarPlacesBothPlacesOnce(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTheMemoryIsWhatProgramsHoldNotTheCache(t *testing.T) {
|
||||
bottom := readManifest(t).text(t, "bottom-bar")
|
||||
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")
|
||||
@@ -39,9 +58,17 @@ func TestTheMemoryIsWhatProgramsHoldNotTheCache(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestABarNamesNoTemplateOfItsOwnForTheBlocksItPlaces(t *testing.T) {
|
||||
m := readManifest(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(m.text(t, id), "${contribution:") {
|
||||
if strings.Contains(templateText(t, m, id), "${contribution:") {
|
||||
t.Errorf("the %s still places a contribution the old way", id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user