Fix profile updates and validate configuration before apply
This commit is contained in:
parent
b552ec49cb
commit
2bf14948d7
1 changed files with 372 additions and 12 deletions
|
|
@ -46,3 +46,40 @@ func TestWriteFiles(t *testing.T) {
|
|||
t.Fatal("second apply failed:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilesRetry(t *testing.T) {
|
||||
p := homePaths(t.TempDir())
|
||||
old := "old-a.scope.d/50-budget.conf"
|
||||
put(t, filepath.Join(p.units, old), "old")
|
||||
put(t, filepath.Join(p.state, "files.json"), `["old-a.scope.d/50-budget.conf", "old-b.scope.d/50-budget.conf"]`)
|
||||
blocker := filepath.Join(p.units, "new.scope.d")
|
||||
put(t, blocker, "blocked")
|
||||
files := map[string]string{"new.scope.d/50-budget.conf": "[Scope]\nMemoryMax=8G\n"}
|
||||
if err := writeFiles(p, files); err == nil {
|
||||
t.Fatal("write failure ignored")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(p.units, old)); !os.IsNotExist(err) {
|
||||
t.Fatalf("cleanup did not finish before the write failure: %v", err)
|
||||
}
|
||||
if err := os.Remove(blocker); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := writeFiles(p, files); err != nil {
|
||||
t.Fatal("retry failed:", err)
|
||||
}
|
||||
data, err := os.ReadFile(filepath.Join(p.units, "new.scope.d/50-budget.conf"))
|
||||
if err != nil || string(data) != files["new.scope.d/50-budget.conf"] {
|
||||
t.Fatalf("replacement file: %q, %v", data, err)
|
||||
}
|
||||
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 was not updated:", manifest)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue