aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/apply_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 21:30:49 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 21:30:49 +0200
commit643eac4a2cba7b34b8a33af1b3dbdc54d9816a53 (patch)
tree5c53881b5d85e5042080a45e070ef3922904389c /internal/engine/apply_test.go
parent7e0d8494074398854f30feb75211c52ea5cc2635 (diff)
downloadkrino-643eac4a2cba7b34b8a33af1b3dbdc54d9816a53.tar.gz
krino-643eac4a2cba7b34b8a33af1b3dbdc54d9816a53.zip
plan 9: undo checks trash identity, groups by directory, re-checks at execution, removes directories it recreates
Diffstat (limited to 'internal/engine/apply_test.go')
-rw-r--r--internal/engine/apply_test.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/internal/engine/apply_test.go b/internal/engine/apply_test.go
index a54bffc..104fb73 100644
--- a/internal/engine/apply_test.go
+++ b/internal/engine/apply_test.go
@@ -749,11 +749,19 @@ func TestRunUndoStepTrashReadsEntryNameFromDetailNotDst(t *testing.T) {
t.Fatal(err)
}
+ // Original is what the run logged for the trash step: the entry name in
+ // Detail, and the entry's own path, size and mtime (checked again at
+ // execution time, review undo F8).
+ entryPath := filepath.Join(trash.Dir(), "files", entry)
+ fi, err := os.Stat(entryPath)
+ if err != nil {
+ t.Fatal(err)
+ }
step := UndoStep{
Action: "undo-trash",
Src: "/this/path/does/not/exist/files/wrong-name",
Dst: target,
- Original: journal.Entry{Detail: entry},
+ Original: journal.Entry{Action: "trash", Src: target, Dst: entryPath, Size: fi.Size(), ModTime: fi.ModTime(), Detail: entry},
}
sr := runUndoStep(step)
if sr.Status != "ok" {
@@ -863,11 +871,15 @@ func TestUndoFileContinuesPastFailedMkdir(t *testing.T) {
defer j.Close()
e := &Engine{Now: time.Now}
+ keepInfo, err := os.Stat(keep)
+ if err != nil {
+ t.Fatal(err)
+ }
uf := UndoFile{
File: "f", Dir: "d",
Steps: []UndoStep{
{Action: "undo-mkdir", Src: nonEmpty},
- {Action: "undo-copy", Src: keep},
+ {Action: "undo-copy", Src: keep, Original: journal.Entry{Action: "copy", Dst: keep, Size: keepInfo.Size(), ModTime: keepInfo.ModTime()}},
},
}
fr, err := e.undoFile(uf, j, "run2")
@@ -967,9 +979,13 @@ func TestApplyUndoDoesNotCountFailedMkdirAsFailed(t *testing.T) {
defer j.Close()
e := &Engine{Now: time.Now}
+ dstInfo, err := os.Stat(dst)
+ if err != nil {
+ t.Fatal(err)
+ }
up := &UndoPlan{Run: "r", Files: []UndoFile{
{File: "a.pdf", Dir: "d", Steps: []UndoStep{
- {Action: "undo-move", Src: dst, Dst: src},
+ {Action: "undo-move", Src: dst, Dst: src, Original: journal.Entry{Action: "move", Src: src, Dst: dst, Size: dstInfo.Size(), ModTime: dstInfo.ModTime()}},
{Action: "undo-mkdir", Src: dir},
}},
}}