Add systemd resource budgets with TOML profiles
This commit is contained in:
commit
be8749a384
1 changed files with 2591 additions and 0 deletions
47
internal/budget/example_test.go
Normal file
47
internal/budget/example_test.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package budget
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUbuntuUnits(t *testing.T) {
|
||||
c, err := loadConfig(filepath.Join("..", "..", "profiles.example.toml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for unit, want := range map[string]string{
|
||||
"gnome-terminal-server.service": "unrestricted",
|
||||
"app-org.gnome.Terminal.service": "unrestricted",
|
||||
"app-org.gnome.Terminal-123.scope": "unrestricted",
|
||||
"app-org.gnome.Nautilus-123.scope": "default",
|
||||
"snap.firefox.firefox-123.scope": "default",
|
||||
"snap.firefox.firefox-helper.service": "",
|
||||
"budget.service": "",
|
||||
} {
|
||||
if got := c.unitProfile(unit); got != want {
|
||||
t.Errorf("%s: got %q, want %q", unit, got, want)
|
||||
}
|
||||
}
|
||||
group := "/app.slice/app-org.gnome.Terminal.slice/gnome-terminal-server.service"
|
||||
for exe, want := range map[string]string{
|
||||
"rg": "search", "java": "compute", "python3.12": "compute", "rsync": "bulk",
|
||||
"cargo": "", "go": "", "npm": "", "kubectl": "",
|
||||
} {
|
||||
got, slice := c.classify(exe, group)
|
||||
if got != want || slice != "" {
|
||||
t.Errorf("%s: got %q, %q; want %q, empty slice", exe, got, slice, want)
|
||||
}
|
||||
}
|
||||
files, err := c.render()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := files["snap.firefox.firefox-.scope.d/50-budget.conf"]; !strings.Contains(got, "[Scope]\n") || !strings.Contains(got, "MemoryMax=3G\n") {
|
||||
t.Fatal("Firefox Snap ceiling missing", got)
|
||||
}
|
||||
if got := files["gnome-terminal-server.service.d/50-budget.conf"]; !strings.Contains(got, "MemoryMax=infinity\n") {
|
||||
t.Fatal("terminal exception missing", got)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue