package main import ( "os" "path/filepath" "reflect" "strings" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" ) // feh's shape (novox/hq ADR 0208): no seat; it requires the X display on its own machine, carries // the wallpaper as its own archive (ADR 0205), owns ~/.fehbg pointing at it, and sets it once from // the session's start. func TestItRequiresTheXDisplayAndClaimsNothing(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 != "feh" || m.DefinesSeats != nil || m.Claims != nil { t.Fatalf("module %q, seats %v, claims %v", m.Module, m.DefinesSeats, 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{"feh"}) || absent != nil { t.Fatalf("packages: %v, absent %v", present, absent) } } func TestTheWallpaperIsTheModulesOwnArchive(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) } a := resource(t, m, "wallpapers") if a["type"] != "archive" || a["artifact"] != "wallpapers" || a["path"] != "${machine:account-home}/.local/share/feh/wallpapers" || a["owner"] != "${machine:account}" { t.Fatalf("%v", a) } found := false for _, art := range m.Build.Artifacts { if art.Name == "wallpapers" && art.Kind == "archive" && art.From == "wallpaper" { found = true } } if !found { t.Fatal("no archive artifact built from wallpaper/") } info, err := os.Stat(filepath.Join("..", "..", "wallpaper", "default.jpg")) if err != nil || info.Size() == 0 { t.Fatalf("the image: %v", err) } } func TestFehbgIsOwnedAndTheSessionStartRunsItOnce(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) } fromTemplate(t, m, "fehbg", "files/fehbg") f := resource(t, m, "fehbg") if f["path"] != "${machine:account-home}/.fehbg" || f["mode"] != "0755" { t.Fatalf("%v", f) } if c := templateText(t, m, "fehbg"); !strings.Contains(c, "$HOME/.local/share/feh/wallpapers/default.jpg") || strings.Contains(c, ".hal") { t.Fatalf("%s", c) } if len(shell(t, m)) != 1 || shell(t, m)[0].For != "xinitrc" || shell(t, m)[0].Slot != "normal" || strings.Count(shell(t, m)[0].Code, `"$HOME/.fehbg"`) != 1 { t.Fatalf("%+v", shell(t, m)) } } func TestTheKeyThatRestoresTheWallpaperIsAnI3DropIn(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/50-feh.conf") if p := i3Lines(m); p == "" { t.Fatalf("path: %v", p) } if c := i3Lines(m); !strings.Contains(c, "bindsym $mod+Shift+b exec --no-startup-id ~/.fehbg\n") { t.Fatalf("%s", c) } } 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) }