aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/correct_audit_fixes_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/correct_audit_fixes_test.go')
-rw-r--r--internal/admin/correct_audit_fixes_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/admin/correct_audit_fixes_test.go b/internal/admin/correct_audit_fixes_test.go
index 60073f7..d97732d 100644
--- a/internal/admin/correct_audit_fixes_test.go
+++ b/internal/admin/correct_audit_fixes_test.go
@@ -49,3 +49,27 @@ func TestRestoreAccountSecretRefusesNonMappingBody(t *testing.T) {
t.Fatalf("password hash not preserved: %s", out)
}
}
+
+// Regression: a failed undo returned a nil change exactly like an empty
+// history, so the UI reported "Nothing to undo" for a real failure.
+func TestUndoFailureIsReportedDistinctly(t *testing.T) {
+ dir := t.TempDir()
+ us := NewUndoStack(dir)
+ us.Push(ChangeDesc{
+ Description: "edit with a missing before-image",
+ FilePath: filepath.Join(dir, "rooms", "1.yaml"),
+ OldContent: nil,
+ NewContent: []byte("id: 1\n"),
+ })
+ if ch := us.Undo(); ch != nil {
+ t.Fatal("undo with a missing before-image unexpectedly succeeded")
+ }
+ if err := us.LastError(); err == nil {
+ t.Fatal("LastError = nil after a failed undo; the UI would report 'Nothing to undo'")
+ }
+ // A genuinely empty history is a clean nil change and nil error.
+ us2 := NewUndoStack(t.TempDir())
+ if ch := us2.Undo(); ch != nil || us2.LastError() != nil {
+ t.Fatal("empty history must be a clean nil change and nil error")
+ }
+}