openrazer (the official driver, daemon and library), polychromatic (the AUR tray, kept as found; its i3 line moves out of the i3 module into its own node-display-session contribution), forticlient (the AUR VPN client: its service declared, its configuration never read) and nm-applet (the desktop half of NetworkManager, apart from the server-side module). The openrazer daemon fails on both workstations because the account is not in the openrazer group; openrazer_check names it and the README carries the one-off step, since the account's user resource is zsh's. desktop.go learns to tell a program from another sharing its 15-character command name, so polychromatic's tools never count or end themselves, and a copies test holds the six carriers to one text.
113 lines
3.7 KiB
Go
113 lines
3.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// openrazer's shape (novox/hq ADR 0207, ADR 0208, ADR 0210): the three official packages of the
|
|
// driver, the daemon and its client library, no seat, no display (the daemon needs none), no start of
|
|
// its own (D-Bus activation through the package's unit is the one start), nothing of the tray's (the
|
|
// polychromatic module's), and the Go bundle serving exactly the listed openrazer_ tools.
|
|
|
|
type manifest struct {
|
|
Module string `json:"module"`
|
|
Version string `json:"version"`
|
|
Capabilities []string `json:"capabilities"`
|
|
Requires []string `json:"requires"`
|
|
Tools []string `json:"tools"`
|
|
Resources []map[string]any `json:"resources"`
|
|
Claims []any `json:"claims"`
|
|
Seats []any `json:"seats"`
|
|
Shell []any `json:"shell"`
|
|
Contributions []struct {
|
|
Seat string `json:"seat"`
|
|
Kind string `json:"kind"`
|
|
Content string `json:"content"`
|
|
} `json:"contributions"`
|
|
Environment any `json:"environment"`
|
|
Build struct {
|
|
Artifacts []map[string]any `json:"artifacts"`
|
|
} `json:"build"`
|
|
}
|
|
|
|
func readManifest(t *testing.T) (manifest, string) {
|
|
t.Helper()
|
|
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
dec := json.NewDecoder(strings.NewReader(string(raw)))
|
|
dec.DisallowUnknownFields()
|
|
var m manifest
|
|
if err := dec.Decode(&m); err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
return m, string(raw)
|
|
}
|
|
|
|
func TestTheToolsAgreeWithTheManifest(t *testing.T) {
|
|
m, raw := readManifest(t)
|
|
served := map[string]bool{}
|
|
for _, tool := range tools() {
|
|
served[tool.Name] = true
|
|
if !strings.HasPrefix(tool.Name, "openrazer_") || strings.TrimSpace(tool.Description) == "" {
|
|
t.Errorf("%s: prefixed %s and described", tool.Name, "openrazer_")
|
|
}
|
|
}
|
|
for _, name := range m.Tools {
|
|
if !served[name] {
|
|
t.Errorf("module.json lists %s, which the bundle does not serve", name)
|
|
}
|
|
delete(served, name)
|
|
}
|
|
for name := range served {
|
|
t.Errorf("the bundle serves %s, which module.json does not list", name)
|
|
}
|
|
if len(m.Build.Artifacts) != 1 {
|
|
t.Fatalf("%v", m.Build.Artifacts)
|
|
}
|
|
b := m.Build.Artifacts[0]
|
|
if b["kind"] != "bundle" || b["language"] != "go" || b["system"] != "arch" ||
|
|
b["from"] != "cmd/openrazer-tools" || b["binary"] != "openrazer-tools" {
|
|
t.Errorf("the Go tools bundle: %v", b)
|
|
}
|
|
s := strings.ToLower(raw)
|
|
for _, never := range []string{"/home/", "jochen", "g14", "shanks", "novox.be", "http", "password", "token"} {
|
|
if strings.Contains(s, never) {
|
|
t.Errorf("module.json names %q", never)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestItInstallsTheStackAndStartsNothing(t *testing.T) {
|
|
m, raw := readManifest(t)
|
|
if m.Module != "openrazer" || m.Requires != nil || !reflect.DeepEqual(m.Capabilities, []string{"package-manager"}) {
|
|
t.Fatalf("%+v", m)
|
|
}
|
|
var pkgs []string
|
|
for _, r := range m.Resources {
|
|
if r["type"] != "package" {
|
|
t.Errorf("only packages: %v", r)
|
|
}
|
|
pkgs = append(pkgs, r["package"].(string))
|
|
}
|
|
if !reflect.DeepEqual(pkgs, packages) {
|
|
t.Fatalf("%v", pkgs)
|
|
}
|
|
if m.Claims != nil || m.Seats != nil || m.Environment != nil || m.Shell != nil || m.Contributions != nil {
|
|
t.Fatal("it holds no seat, sets no environment and adds no start")
|
|
}
|
|
// The tray is polychromatic's, from outside the official repositories; the kernel headers DKMS
|
|
// builds against are the kernel's; the account's groups are its user resource's (zsh's).
|
|
for _, never := range []string{"polychromatic", "linux-headers", "\"dkms\"", "\"user\"", "groups"} {
|
|
if strings.Contains(raw, never) {
|
|
t.Errorf("module.json names %s", never)
|
|
}
|
|
}
|
|
}
|