feat(shellconfig): implement PlanForce
This commit is contained in:
@@ -55,4 +55,42 @@ func TestShellConfigIdempotent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanForceRewritesBlocks(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
cfg := config.ShellConfigSection{Blocks: []config.ShellConfigBlock{
|
||||
{Name: "path", File: ".zshrc", Content: `export PATH="$HOME/.local/bin:$PATH"`},
|
||||
}}
|
||||
m := New(cfg)
|
||||
st, _ := m.Detect(context.Background())
|
||||
p, _ := m.Plan(context.Background(), st)
|
||||
if err := m.Apply(context.Background(), p, nop{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st2, _ := m.Detect(context.Background())
|
||||
p2, _ := m.Plan(context.Background(), st2)
|
||||
if !p2.IsEmpty() {
|
||||
t.Fatalf("precondition: regular plan should be empty")
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
data, _ := os.ReadFile(filepath.Join(home, ".zshrc"))
|
||||
if !strings.Contains(string(data), `export PATH="$HOME/.local/bin:$PATH"`) {
|
||||
t.Fatalf("content missing after force: %q", data)
|
||||
}
|
||||
if !strings.Contains(string(data), ">>> path >>>") {
|
||||
t.Fatalf("block marker missing: %q", data)
|
||||
}
|
||||
}
|
||||
|
||||
var _ module.Module = Module{}
|
||||
|
||||
Reference in New Issue
Block a user