feat(zellij): implement PlanForce

This commit is contained in:
MDietermann
2026-04-14 22:06:10 +02:00
parent 47064338c8
commit 4ed257bbd1
2 changed files with 63 additions and 2 deletions

View File

@@ -81,4 +81,45 @@ func TestZellijInstalledPresentEmptyPlan(t *testing.T) {
}
}
func TestPlanForceReinstallsAndRewritesConfig(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
os.MkdirAll(filepath.Join(home, ".config", "zellij"), 0o755)
os.WriteFile(filepath.Join(home, ".config", "zellij", "config.kdl"), []byte("old\n"), 0o644)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte("fresh {}\n"))
}))
defer srv.Close()
r := &fakeRunner{installed: map[string]bool{"zellij": true}}
m := New(config.ZellijConfig{ConfigURL: srv.URL}, platform.NewPacman(r))
plan, err := m.PlanForce(context.Background())
if err != nil {
t.Fatalf("PlanForce: %v", err)
}
if plan.IsEmpty() {
t.Fatal("force plan must not be empty")
}
for _, a := range plan.Actions {
if err := a.Exec(context.Background()); err != nil {
t.Fatalf("Exec: %v", err)
}
}
sawReinstall := false
for _, c := range r.runCalls {
if len(c) >= 4 && c[0] == "sudo" && c[1] == "pacman" && c[2] == "-S" && c[3] == "--noconfirm" {
sawReinstall = true
}
}
if !sawReinstall {
t.Fatalf("no pacman reinstall call; calls=%v", r.runCalls)
}
got, err := os.ReadFile(filepath.Join(home, ".config", "zellij", "config.kdl"))
if err != nil {
t.Fatalf("config not written: %v", err)
}
if string(got) != "fresh {}\n" {
t.Fatalf("config not overwritten: %q", got)
}
}
var _ module.Module = Module{}