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
111 lines
3.9 KiB
Go
111 lines
3.9 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// 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.
|
|
|
|
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)
|
|
}
|
|
raw := string(manifestJSON)
|
|
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) {
|
|
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)
|
|
}
|
|
raw := string(manifestJSON)
|
|
if m.Module != "openrazer" || m.Requires != nil || !reflect.DeepEqual(m.Capabilities, []string{"package-manager"}) {
|
|
t.Fatalf("%+v", m)
|
|
}
|
|
var pkgs []string
|
|
var accounts []map[string]any
|
|
for i, r := range m.Resources {
|
|
switch r["type"] {
|
|
case "package":
|
|
if len(accounts) > 0 {
|
|
t.Errorf("a package after the account: the group is the driver's package's to make first: %v", r)
|
|
}
|
|
pkgs = append(pkgs, r["package"].(string))
|
|
case "user":
|
|
accounts = append(accounts, m.Resources[i])
|
|
default:
|
|
t.Errorf("only packages and the account's group: %v", r)
|
|
}
|
|
}
|
|
if !reflect.DeepEqual(pkgs, packages) {
|
|
t.Fatalf("%v", pkgs)
|
|
}
|
|
// The operator's account in the driver's group, and nothing else of the account: its shell and home
|
|
// are the login shell's module's (novox/hq ADR 0252). Written after the packages, so the group the
|
|
// driver's package makes exists when the account is put in it.
|
|
want := map[string]any{"id": "account", "type": "user", "name": "${machine:account}", "groups": []any{group}}
|
|
if len(accounts) != 1 || !reflect.DeepEqual(accounts[0], want) {
|
|
t.Fatalf("the account: %v, want %v", accounts, want)
|
|
}
|
|
if m.Claims != nil || m.DefinesSeats != 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.
|
|
for _, never := range []string{"polychromatic", "linux-headers", "\"dkms\"", "\"shell\"", "\"home\""} {
|
|
if strings.Contains(raw, never) {
|
|
t.Errorf("module.json names %s", never)
|
|
}
|
|
}
|
|
}
|