feat(starship): implement PlanForce to reinstall all packages
This commit is contained in:
@@ -3,7 +3,6 @@ package starship
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -75,5 +74,13 @@ func (m Module) Verify(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
|
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
|
||||||
return module.Plan{}, errors.New("PlanForce not implemented")
|
if len(m.pkgs) == 0 {
|
||||||
|
return module.Plan{}, nil
|
||||||
|
}
|
||||||
|
pkgs := append([]string{}, m.pkgs...)
|
||||||
|
return module.Plan{Actions: []module.Action{{
|
||||||
|
Description: "pacman -S (force) " + strings.Join(pkgs, ", "),
|
||||||
|
Kind: module.ActionPackageInstall,
|
||||||
|
Exec: func(ctx context.Context) error { return m.pm.Reinstall(ctx, pkgs) },
|
||||||
|
}}}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,4 +110,30 @@ func TestVerifyAfterApply(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPlanForceReinstallsAllPackages(t *testing.T) {
|
||||||
|
r := &fakeRunner{installed: map[string]bool{"starship": true}}
|
||||||
|
m := New([]string{"starship"}, 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 even when packages are installed")
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var _ module.Module = Module{}
|
var _ module.Module = Module{}
|
||||||
|
|||||||
Reference in New Issue
Block a user