mesh/merge-gate head e7ff7c3045fc merged into trunk afb94d925e94 — pass: builds mesh-provisioner-client → ace, g14, novox, shanks; no bus step; every machi…
mesh/repo-check head e7ff7c3045fc merged into trunk afb94d925e94 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
89 lines
3.4 KiB
Go
89 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// The bar files i3status-rust's bars come to, filled by this client from power's items of the collection
|
|
// contribution:node-bar:block, are byte for byte what the old shaped contribution made (design 57 L3, issue 781).
|
|
// The module files are the catalogue's own; testdata/bars holds the bars as composed before the move, for a machine
|
|
// with neither capability, the battery, the power meter and both. The controller's side of the same bars, not handed,
|
|
// is pinned by mesh-controller internal/catalogue TestTheBarsOfTheCatalogueAreTheSameHandedOrNot.
|
|
|
|
func TestNatsTheBarsFilledFromPowersItemsAreWhatTheOldContributionMade(t *testing.T) {
|
|
modules := filepath.Join("..", "..", "..")
|
|
raw, err := os.ReadFile(filepath.Join(modules, "power", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var power struct {
|
|
Items []struct {
|
|
Collection string `json:"collection"`
|
|
Name string `json:"name"`
|
|
IfCapability string `json:"if-capability"`
|
|
Attributes map[string]string `json:"attributes"`
|
|
Template string `json:"template"`
|
|
} `json:"items"`
|
|
}
|
|
if err := json.Unmarshal(raw, &power); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for name, caps := range map[string][]string{"none": nil, "battery": {"battery"}, "power-meter": {"power-meter"},
|
|
"both": {"battery", "power-meter"}} {
|
|
t.Run(name, func(t *testing.T) {
|
|
has := map[string]bool{}
|
|
for _, c := range caps {
|
|
has[c] = true
|
|
}
|
|
bar := func(which string) string {
|
|
b, err := os.ReadFile(filepath.Join(modules, "i3status-rust", "files", which+"-bar.toml"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return string(b)
|
|
}
|
|
barTpl, _ := templates(t, map[string]string{"bottom": bar("bottom"), "top": bar("top")})
|
|
bars := Plan{Templates: barTpl, Files: []PlannedFile{
|
|
{ID: "bottom", Path: "/bars/bottom.toml", Template: "bottom", OwnerAtRuntime: "owned"},
|
|
{ID: "top", Path: "/bars/top.toml", Template: "top", OwnerAtRuntime: "owned"}},
|
|
Collections: []PlannedCollection{{Name: "contribution:node-bar:block", Comment: "#"}},
|
|
Placement: map[string]string{"machine:name": "workstation"}}
|
|
texts := map[string]string{}
|
|
var items []PlannedItem
|
|
for _, it := range power.Items {
|
|
if it.IfCapability != "" && !has[it.IfCapability] {
|
|
continue // the controller leaves it out of the plan
|
|
}
|
|
text, err := os.ReadFile(filepath.Join(modules, "power", it.Template))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
id := filepath.Base(it.Template)
|
|
texts[id] = string(text)
|
|
items = append(items, PlannedItem{Collection: it.Collection, Name: it.Name, Template: id,
|
|
Attributes: it.Attributes})
|
|
}
|
|
itemTpl, _ := templates(t, texts)
|
|
contrib := Plan{Templates: itemTpl, Items: items, Placement: map[string]string{"machine:name": "workstation"}}
|
|
|
|
b := startBus(t)
|
|
e := startEngine(t, map[string]string{"/bars/bottom.toml": "owned", "/bars/top.toml": "owned"})
|
|
b.assign(t, "i3status-rust", bars)
|
|
b.assign(t, "power", contrib)
|
|
aClient(t, b, e, t.TempDir())
|
|
for _, which := range []string{"bottom", "top"} {
|
|
golden, err := os.ReadFile(filepath.Join("testdata", "bars", name+"."+which+"-bar.toml"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
eventually(t, "the "+which+" bar is what it was", func() bool {
|
|
return e.read(t, "/bars/"+which+".toml") == string(golden)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|