aboutsummaryrefslogtreecommitdiff
path: root/internal/journal/journal_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 21:21:58 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 21:21:58 +0200
commita92ce86c0dff7ce8f1de4113f20edd76c249371e (patch)
treec41a4f01c610a49cf3b60e9e9e658d6cb8b94b33 /internal/journal/journal_test.go
parent3890b27b5a68f5521f4f0a234cebf528744356ee (diff)
downloadkrino-a92ce86c0dff7ce8f1de4113f20edd76c249371e.tar.gz
krino-a92ce86c0dff7ce8f1de4113f20edd76c249371e.zip
plan 9: the log restores a missing final newline
Diffstat (limited to 'internal/journal/journal_test.go')
-rw-r--r--internal/journal/journal_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/journal/journal_test.go b/internal/journal/journal_test.go
index a95bb05..e8b18ae 100644
--- a/internal/journal/journal_test.go
+++ b/internal/journal/journal_test.go
@@ -148,3 +148,30 @@ func TestAppendIsAppendOnly(t *testing.T) {
t.Errorf("%d lines after two Open/Append/Close cycles, want 2: the second Open truncated", got)
}
}
+
+// TestOpenRepairsAMissingFinalNewline: a crash can leave the log's last
+// line without its newline; the next run's first line must not be glued
+// onto it, or that run could never be undone (review M8).
+func TestOpenRepairsAMissingFinalNewline(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "krino.log")
+ if err := os.WriteFile(path, []byte("2026-09-11T10:02:03+02:00\tR0\tdl\ta.pdf\t1\tmo"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ w, err := Open(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ at := time.Date(2026, 9, 11, 10, 5, 0, 0, time.UTC)
+ for _, e := range []Entry{{Time: at, Run: "R1", Action: "run-start", Status: "ok"}, {Time: at, Run: "R1", Action: "run-end", Status: "ok"}} {
+ if err := w.Append(e); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := w.Close(); err != nil {
+ t.Fatal(err)
+ }
+ entries, err := Entries(path, "R1")
+ if err != nil || len(entries) != 2 {
+ t.Fatalf("Entries(R1) = %d entries, %v; want run-start and run-end", len(entries), err)
+ }
+}