feat(zsh): implement PlanForce
This commit is contained in:
@@ -114,4 +114,46 @@ func TestZshPlanApplyInstallsEverything(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanForceReinstallsEverything(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
os.MkdirAll(filepath.Join(home, ".oh-my-zsh", ".git"), 0o755)
|
||||
os.MkdirAll(filepath.Join(home, ".oh-my-zsh", "custom", "plugins", "zsh-autosuggestions", ".git"), 0o755)
|
||||
r := &fakeRunner{installed: map[string]bool{"zsh": true}}
|
||||
m := New(config.ZshConfig{
|
||||
OhMyZshRepo: "https://x/omz.git",
|
||||
Plugins: []config.ZshPlugin{{Name: "zsh-autosuggestions", Repo: "https://x/a.git"}},
|
||||
}, platform.NewPacman(r), platform.GitClient{Runner: 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, sawOMZ, sawPlugin := false, false, 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 len(c) >= 4 && c[0] == "git" && c[3] == "https://x/omz.git" {
|
||||
sawOMZ = true
|
||||
}
|
||||
if len(c) >= 4 && c[0] == "git" && c[3] == "https://x/a.git" {
|
||||
sawPlugin = true
|
||||
}
|
||||
}
|
||||
if !sawReinstall || !sawOMZ || !sawPlugin {
|
||||
t.Fatalf("missing force action; calls=%v", r.runCalls)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(home, ".oh-my-zsh")); !os.IsNotExist(err) {
|
||||
t.Fatalf("oh-my-zsh dir should have been removed; stat err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
var _ module.Module = Module{}
|
||||
|
||||
Reference in New Issue
Block a user