package main import ( "os" "path/filepath" "reflect" "strings" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" ) // i3status-rust's shape (novox/hq ADR 0208): it claims node-bar, requires the X display on its own // machine (its bars are i3bar's), owns its two bars and their icons, places the bars as an i3 drop-in, // and runs the bar watchdog once per session. No block follows one machine's hardware or one person's // devices. func TestItClaimsTheBarSeatAndRequiresTheXDisplay(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.Moved { t.Fatal("the module is not marked moved") } if m.Module != "i3status-rust" || m.DefinesSeats != nil { t.Fatalf("module %q declares seats %v", m.Module, m.DefinesSeats) } if len(m.Claims) != 1 || m.Claims[0].Name != "node-bar" || m.Claims[0].Scope != "node" || len(m.Claims[0].Renders) != 0 { t.Fatalf("claims: %+v", 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{"i3status-rust"}) || absent != nil { t.Fatalf("packages: %v, absent %v", present, absent) } } func TestItOwnsItsFilesAsWrittenInTheModule(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, src := range map[string]string{ "top-bar": "files/top-bar.toml", "bottom-bar": "files/bottom-bar.toml", "icons": "files/icons/custom-icons.toml", "updates": "files/bin/i3status-updates", "watchdog": "files/bin/i3bar-watchdog", "value": "files/bin/i3status-value", } { fromTemplate(t, m, id, src) } } func TestNoBlockFollowsAMachinesHardwareOrAPersonsDevicesOrCarriesAKey(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") for _, never := range []string{`block = "battery"`, `block = "amd_gpu"`, `block = "nvidia_gpu"`, "mac = ", "api_key", "city_id", "openweathermap", "~/scripts/"} { if strings.Contains(bottom, never) { t.Errorf("the bottom bar has %s", never) } } } func TestTheBarsAreAContributionToTheWindowManagerAndTheWatchdogRunsOncePerSession(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/60-i3status-rust.conf") c := i3Lines(m) if strings.Count(c, "bar {") != 2 || !strings.Contains(c, "status_command i3status-rs ~/.config/i3status-rust/bottom-bar.toml") || !strings.Contains(c, "font pango:JetBrainsMono Nerd Font 11") { t.Fatalf("%s", c) } if len(shell(t, m)) != 1 || shell(t, m)[0].For != "xinitrc" || shell(t, m)[0].Slot != "normal" || !strings.Contains(shell(t, m)[0].Code, `"$HOME/.local/bin/i3bar-watchdog" "$$" &`) { t.Fatalf("%+v", shell(t, m)) } } 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) }