feat(renode): implement PlanForce to reinstall packages and rewrite assets
This commit is contained in:
@@ -142,4 +142,52 @@ func TestApplyRendersSimScriptAndDownloadsWokwi(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanForceReinstallsEverything(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Write([]byte("wokwi-forced"))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
// Even with everything already "installed", force plan should be non-empty.
|
||||
os.MkdirAll(filepath.Join(home, ".local", "bin"), 0o755)
|
||||
os.WriteFile(filepath.Join(home, ".local", "bin", "wokwi-cli"), []byte("stale"), 0o755)
|
||||
r := &fakeRunner{installed: map[string]bool{"yay": true, "renode-bin": true, "arm-none-eabi-gdb": true}}
|
||||
m := New(sampleCfg(srv.URL), platform.NewPacman(r), platform.NewYay(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 %q: %v", a.Description, err)
|
||||
}
|
||||
}
|
||||
var sawYayReinstall, sawPacmanReinstall bool
|
||||
for _, c := range r.runCalls {
|
||||
if len(c) >= 3 && c[0] == "yay" && c[1] == "-S" && c[2] == "--noconfirm" {
|
||||
sawYayReinstall = true
|
||||
}
|
||||
if len(c) >= 4 && c[0] == "sudo" && c[1] == "pacman" && c[2] == "-S" && c[3] == "--noconfirm" {
|
||||
sawPacmanReinstall = true
|
||||
}
|
||||
}
|
||||
if !sawYayReinstall {
|
||||
t.Errorf("no yay reinstall call; calls=%v", r.runCalls)
|
||||
}
|
||||
if !sawPacmanReinstall {
|
||||
t.Errorf("no pacman reinstall call; calls=%v", r.runCalls)
|
||||
}
|
||||
// wokwi-cli should have been overwritten with the fresh payload
|
||||
wokwi, _ := os.ReadFile(filepath.Join(home, ".local", "bin", "wokwi-cli"))
|
||||
if string(wokwi) != "wokwi-forced" {
|
||||
t.Errorf("wokwi-cli not overwritten: %q", wokwi)
|
||||
}
|
||||
}
|
||||
|
||||
var _ module.Module = Module{}
|
||||
|
||||
Reference in New Issue
Block a user