Add systemd resource budgets with TOML profiles
This commit is contained in:
commit
be8749a384
1 changed files with 2591 additions and 0 deletions
48
internal/budget/files_test.go
Normal file
48
internal/budget/files_test.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package budget
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWriteFiles(t *testing.T) {
|
||||
p := homePaths(t.TempDir())
|
||||
old := "old.scope.d/50-budget.conf"
|
||||
put(t, filepath.Join(p.units, old), "old")
|
||||
put(t, filepath.Join(p.units, "user.conf"), "keep")
|
||||
put(t, filepath.Join(p.state, "files.json"), `["old.scope.d/50-budget.conf"]`)
|
||||
files := map[string]string{"app-.scope.d/50-budget.conf": "[Scope]\nMemoryMax=8G\n", "search.slice": "[Slice]\n"}
|
||||
if err := writeFiles(p, files); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(p.units, old)); !os.IsNotExist(err) {
|
||||
t.Fatalf("stale owned file remains: %v", err)
|
||||
}
|
||||
data, err := os.ReadFile(filepath.Join(p.units, "user.conf"))
|
||||
if err != nil || string(data) != "keep" {
|
||||
t.Fatal("unmanaged configuration changed")
|
||||
}
|
||||
data, err = os.ReadFile(filepath.Join(p.state, "files.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var manifest []string
|
||||
if err := json.Unmarshal(data, &manifest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(manifest, keys(files)) {
|
||||
t.Fatal(manifest)
|
||||
}
|
||||
for name, want := range files {
|
||||
data, err := os.ReadFile(filepath.Join(p.units, name))
|
||||
if err != nil || string(data) != want {
|
||||
t.Fatalf("%s: %q, %v", name, data, err)
|
||||
}
|
||||
}
|
||||
if err := writeFiles(p, files); err != nil {
|
||||
t.Fatal("second apply failed:", err)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue