feat: drop-in support for custom templates
User templates can now be added without rebuilding: drop a script into ~/.config/motd-assist/templates/ and reference it from a preset via "install": "<filename>". Same-name files override built-ins; new files are picked up by the running TUI via 'r'. `motd-assist templates` lists known templates and creates the drop-in directory. Apply plans now embed the resolved template content (Plan.ResolveContents) so the sudo/root process never needs to read user config; snapshots store installed script content so restore works under sudo as well. Validation rejects plans with unresolved content.
This commit is contained in:
parent
d56659e21a
commit
303c49b484
10 changed files with 375 additions and 48 deletions
|
|
@ -38,12 +38,39 @@ func TestValidateRejectsUnknownNames(t *testing.T) {
|
|||
func TestValidateRejectsForeignOverwrite(t *testing.T) {
|
||||
root := setupDir(t, map[string]string{"00-header": "#!/bin/sh\necho eigenes\n"})
|
||||
|
||||
err := Validate(root, Plan{Installs: []InstallOp{{Name: "00-header", Source: "footer", Enabled: true}}})
|
||||
err := Validate(root, Plan{Installs: []InstallOp{{
|
||||
Name: "00-header", Source: "footer", Enabled: true,
|
||||
Content: "#!/bin/sh\necho neu\n",
|
||||
}}})
|
||||
if err == nil {
|
||||
t.Error("Install über fremdes Script sollte abgelehnt werden")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsEmptyInstallContent(t *testing.T) {
|
||||
root := setupDir(t, nil)
|
||||
|
||||
err := Validate(root, Plan{Installs: []InstallOp{{Name: "10-x", Source: "unbekannt", Enabled: true}}})
|
||||
if err == nil {
|
||||
t.Error("Install ohne aufgelösten Inhalt sollte abgelehnt werden")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveContentsEmbedsTemplates(t *testing.T) {
|
||||
plan := Plan{Installs: []InstallOp{{Name: "10-x", Source: "brand-header", Enabled: true}}}
|
||||
if err := plan.ResolveContents(); err != nil {
|
||||
t.Fatalf("ResolveContents: %v", err)
|
||||
}
|
||||
if plan.Installs[0].Content == "" {
|
||||
t.Error("Content wurde nicht befüllt")
|
||||
}
|
||||
|
||||
missing := Plan{Installs: []InstallOp{{Name: "10-y", Source: "gibt-es-nicht", Enabled: true}}}
|
||||
if err := missing.ResolveContents(); err == nil {
|
||||
t.Error("unbekannte Vorlage sollte einen Fehler liefern")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsForeignRemove(t *testing.T) {
|
||||
root := setupDir(t, map[string]string{"10-sysinfo": "#!/bin/sh\necho eigenes\n"})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue