Files
mesh-catalog/modules/blueman/cmd/blueman-tools/manifest_test.go
T
jschoubben a3db292b8d Read each module's own manifest through mesh-sdk's catalogue reader (H-A-498)
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
2026-11-22 21:32:03 +01:00

105 lines
3.6 KiB
Go

package main
import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// blueman's shape (novox/hq ADR 0208, ADR 0210): one official package, no seat, the X display on its
// own machine, no start of its own (the package's autostart entry is the one start), nothing of the
// bluetooth module's (bluez, its utilities, its daemon), and the Go bundle serving exactly the listed
// blueman_ tools.
func TestItInstallsTheAppletAndNothingElse(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.Module != "blueman" || !reflect.DeepEqual(m.Requires, []string{"x11-display"}) ||
!reflect.DeepEqual(m.Capabilities, []string{"package-manager"}) {
t.Fatalf("%+v", m)
}
if len(m.Resources) != 1 || m.Resources[0]["type"] != "package" || m.Resources[0]["package"] != packageFor {
t.Fatalf("resources: %v", m.Resources)
}
if m.Claims != nil || m.DefinesSeats != nil || m.Environment != nil {
t.Fatal("it holds no seat and sets no environment")
}
}
func TestItAddsNoSecondStartAndDeclaresNothingOfTheBluetoothModule(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)
// The package ships its XDG autostart entry, which the session's dex runs: an xinitrc slot or a
// window-manager exec would start it twice.
if m.Shell != nil || m.Contributions != nil {
t.Fatalf("a second start: shell %v, contributions %v", m.Shell, m.Contributions)
}
for _, never := range []string{"autostart", "service", "bluez", "/etc/bluetooth"} {
if strings.Contains(raw, never) {
t.Errorf("module.json names %q: the start is the package's, the stack the bluetooth module's", never)
}
}
}
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, "blueman_") || strings.TrimSpace(tool.Description) == "" {
t.Errorf("%s: prefixed blueman_ and described", tool.Name)
}
}
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/blueman-tools" || b.Binary != "blueman-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)
}
}
}