47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
|
|
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)
|
||
|
|
}
|
||
|
|
}
|