Fix profile updates and validate configuration before apply

This commit is contained in:
ms2k 2026-10-05 21:45:05 +09:00
commit 2bf14948d7

View file

@ -98,3 +98,38 @@ func TestNoSharedApps(t *testing.T) {
t.Fatal(got)
}
}
func TestSliceDropIns(t *testing.T) {
c := testConfig()
c.Units["compute"] = []string{"custom.slice"}
c.Prefixes["bulk"] = []string{"custom-.slice.d"}
files, err := c.render()
if err != nil {
t.Fatal(err)
}
for file, limit := range map[string]string{
"custom.slice.d/50-budget.conf": "16G", "custom-.slice.d/50-budget.conf": "8G",
} {
if text := files[file]; !strings.HasPrefix(text, "[Slice]\n") || !strings.Contains(text, "MemoryMax="+limit+"\n") {
t.Fatalf("%s: %q", file, text)
}
}
if got := c.unitProfile("custom-work.slice"); got != "bulk" {
t.Fatalf("slice prefix profile: %q", got)
}
}
func TestInvalidPrefixes(t *testing.T) {
for _, prefix := range []string{"snap-firefox", "snap.firefox", "snap.firefox.scope", "snap.firefox.timer.d"} {
t.Run(prefix, func(t *testing.T) {
c := testConfig()
c.Prefixes["default"] = []string{prefix}
if _, err := c.render(); err == nil {
t.Fatal("invalid prefix accepted")
}
if got := c.unitProfile("session-ui.service"); got != "" {
t.Fatalf("invalid prefix matched an unrelated unit: %q", got)
}
})
}
}