Files
mesh-catalog/modules/i3status-rust/cmd/i3status-rust-tools/blocks_test.go
T

64 lines
2.4 KiB
Go

package main
import (
"os"
"path/filepath"
"strings"
"testing"
)
// 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)
for _, bar := range []string{"bottom", "top"} {
content := m.text(t, 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 := m.text(t, "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) {
bottom := readManifest(t).text(t, "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) {
m := readManifest(t)
for _, id := range []string{"top-bar", "bottom-bar"} {
if strings.Contains(m.text(t, 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)
}
}