feat(themes): implement PlanForce
This commit is contained in:
@@ -63,4 +63,49 @@ func applyOnce(t *testing.T, m Module) error {
|
||||
return m.Apply(context.Background(), p, nop{})
|
||||
}
|
||||
|
||||
func TestPlanForceRewritesAllThemes(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
os.WriteFile(filepath.Join(src, "one.toml"), []byte("FRESH-A"), 0o644)
|
||||
os.MkdirAll(filepath.Join(src, "sub"), 0o755)
|
||||
os.WriteFile(filepath.Join(src, "sub", "two.toml"), []byte("FRESH-B"), 0o644)
|
||||
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
m := New(config.ThemesConfig{Source: src})
|
||||
dst := filepath.Join(home, ".config", "archduino", "themes")
|
||||
os.MkdirAll(filepath.Join(dst, "sub"), 0o755)
|
||||
os.WriteFile(filepath.Join(dst, "one.toml"), []byte("FRESH-A"), 0o644)
|
||||
os.WriteFile(filepath.Join(dst, "sub", "two.toml"), []byte("FRESH-B"), 0o644)
|
||||
|
||||
st, _ := m.Detect(context.Background())
|
||||
p, _ := m.Plan(context.Background(), st)
|
||||
if !p.IsEmpty() {
|
||||
t.Fatalf("precondition: plan should be empty, got %+v", p.Actions)
|
||||
}
|
||||
|
||||
os.WriteFile(filepath.Join(dst, "one.toml"), []byte("STALE"), 0o644)
|
||||
os.WriteFile(filepath.Join(dst, "sub", "two.toml"), []byte("STALE"), 0o644)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
got, _ := os.ReadFile(filepath.Join(dst, "one.toml"))
|
||||
if string(got) != "FRESH-A" {
|
||||
t.Fatalf("one.toml not rewritten: %q", got)
|
||||
}
|
||||
got, _ = os.ReadFile(filepath.Join(dst, "sub", "two.toml"))
|
||||
if string(got) != "FRESH-B" {
|
||||
t.Fatalf("two.toml not rewritten: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
var _ module.Module = Module{}
|
||||
|
||||
Reference in New Issue
Block a user