From 6ef83d6bdfb6120f9e1fbd145e0bc463196103d1 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Wed, 16 Sep 2026 09:39:59 +0200 Subject: gui: History and undo tab; each plan and undo is its own run --- gui/internal/model/plan_test.go | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'gui/internal/model/plan_test.go') diff --git a/gui/internal/model/plan_test.go b/gui/internal/model/plan_test.go index bf8f19f..746ddfc 100644 --- a/gui/internal/model/plan_test.go +++ b/gui/internal/model/plan_test.go @@ -52,18 +52,14 @@ func sandboxDir(t *testing.T, conf string, files map[string]string) (*engine.Eng return e, h } -func planTab(t *testing.T, e *engine.Engine) (*PlanTab, *engine.Session) { +func planTab(t *testing.T, e *engine.Engine) *PlanTab { t.Helper() - s, err := e.NewSession(false) + tab, err := Plan(context.Background(), e, e.Dirs[0]) if err != nil { t.Fatal(err) } - t.Cleanup(func() { s.Close() }) - tab, err := Plan(context.Background(), s, e.Dirs[0]) - if err != nil { - t.Fatal(err) - } - return tab, s + t.Cleanup(func() { tab.Close() }) + return tab } // TestPlanRowsAndCounts: the tab shows one row per file with steps, a row @@ -79,7 +75,7 @@ func TestPlanRowsAndCounts(t *testing.T) { "c.txt": strings.Repeat("x", 2048), // over max-read: content unknown "plain.txt": "nothing", }) - tab, _ := planTab(t, e) + tab := planTab(t, e) if tab.Counts.Scanned != 4 || tab.Counts.Acting != 1 || tab.Counts.Excluded != 1 { t.Errorf("counts = %+v", tab.Counts) } @@ -111,7 +107,7 @@ func TestPlanRowsAndCounts(t *testing.T) { func TestSelectionAndApply(t *testing.T) { conf := "(path \"~/dl\")\n(rule \"all\" (move \"Out\"))\n" e, h := sandboxDir(t, conf, map[string]string{"a.pdf": "one", "b.pdf": "two"}) - tab, _ := planTab(t, e) + tab := planTab(t, e) if tab.SelectedCount() != 2 { t.Fatalf("rows do not start selected: %+v", tab.Rows) } @@ -154,7 +150,7 @@ func TestSelectionAndApply(t *testing.T) { func TestReplaceWithTrash(t *testing.T) { conf := "(path \"~/dl\")\n(rule \"all\" (move \"Out\"))\n" e, h := sandboxDir(t, conf, map[string]string{"a.pdf": "one"}) - tab, _ := planTab(t, e) + tab := planTab(t, e) if err := tab.Replace(0, plan.Trash); err != nil { t.Fatal(err) } @@ -195,7 +191,7 @@ func TestPlanLeavesTheDirectoryAlone(t *testing.T) { func TestPlanHoldsTheLock(t *testing.T) { conf := "(path \"~/dl\")\n(rule \"all\" (move \"Out\"))\n" e, _ := sandboxDir(t, conf, map[string]string{"a.pdf": "one"}) - tab, _ := planTab(t, e) + tab := planTab(t, e) if _, err := lock.Acquire(context.Background(), e.Config.LockFile("dl"), false); !errors.Is(err, lock.ErrHeld) { t.Fatalf("an open plan does not hold the lock: %v", err) } @@ -217,7 +213,7 @@ func TestPlanHoldsTheLock(t *testing.T) { func TestApplyReleasesTheLock(t *testing.T) { conf := "(path \"~/dl\")\n(rule \"all\" (move \"Out\"))\n" e, _ := sandboxDir(t, conf, map[string]string{"a.pdf": "one"}) - tab, _ := planTab(t, e) + tab := planTab(t, e) if _, err := tab.Apply(context.Background()); err != nil { t.Fatal(err) } @@ -241,12 +237,7 @@ func TestPlanRefusesAHeldDirectory(t *testing.T) { t.Fatal(err) } defer held.Release() - s, err := e.NewSession(false) - if err != nil { - t.Fatal(err) - } - defer s.Close() - if _, err := Plan(context.Background(), s, e.Dirs[0]); !errors.Is(err, lock.ErrHeld) { + if _, err := Plan(context.Background(), e, e.Dirs[0]); !errors.Is(err, lock.ErrHeld) { t.Fatalf("Plan = %v, want lock.ErrHeld", err) } else if !strings.Contains(err.Error(), "dl") { t.Errorf("the message does not name the directory: %v", err) @@ -259,7 +250,7 @@ func TestPlanRefusesAHeldDirectory(t *testing.T) { func TestRescanForgetsUnusedNames(t *testing.T) { conf := "(path \"~/dl\")\n(rule \"all\" (move \"Out\") (rename \"same.pdf\"))\n" e, _ := sandboxDir(t, conf, map[string]string{"a.pdf": "one", "b.pdf": "two"}) - tab, s := planTab(t, e) + tab := planTab(t, e) // Each file moves into Out and is then renamed; the second file's name // is taken, so the plan reserves a suffixed one for it. want := destinations(t, tab) @@ -271,7 +262,7 @@ func TestRescanForgetsUnusedNames(t *testing.T) { if err := tab.Close(); err != nil { t.Fatal(err) } - again, err := Plan(context.Background(), s, e.Dirs[0]) + again, err := Plan(context.Background(), e, e.Dirs[0]) if err != nil { t.Fatal(err) } @@ -286,7 +277,7 @@ func TestRescanForgetsUnusedNames(t *testing.T) { if err := again.Close(); err != nil { t.Fatal(err) } - third, err := Plan(context.Background(), s, e.Dirs[0]) + third, err := Plan(context.Background(), e, e.Dirs[0]) if err != nil { t.Fatal(err) } -- cgit v1.3