| 1 | package store_test |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "testing" |
| 6 | |
| 7 | "amadan.net/oficina/sheets/internal/sheets/seal" |
| 8 | "amadan.net/oficina/sheets/internal/sheets/sealtest" |
| 9 | "amadan.net/oficina/sheets/internal/sheets/store" |
| 10 | ) |
| 11 | |
| 12 | func TestInputEventIsSealedOnDisk(t *testing.T) { |
| 13 | dir := t.TempDir() |
| 14 | dbPath := filepath.Join(dir, "test.db") |
| 15 | db := openTestDB(t, dbPath) // helper defined below |
| 16 | s, _ := seal.New(make32()) |
| 17 | |
| 18 | err := store.AppendInput(db, s, store.InputEvent{ |
| 19 | TabID: 1, RowID: 1, ColID: 1, ActorID: 7, |
| 20 | OldRaw: "", |
| 21 | NewRaw: "CANARY-CELL-VALUE-8f3a", |
| 22 | }) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | checkpoint(t, db) // force a WAL checkpoint so bytes hit the file |
| 27 | |
| 28 | sealtest.AssertNoPlaintext(t, dbPath) |
| 29 | } |
| 30 | |
| 31 | // A recalc marker records that a pass happened and how wide it was. It must |
| 32 | // never carry derived values: logging them makes the log grow with the |
| 33 | // fan-out of every edit rather than with the number of edits, in a file |
| 34 | // Litestream ships continuously. See spec section 4.3. |
| 35 | func TestRecalcMarkerHoldsNoValues(t *testing.T) { |
| 36 | dir := t.TempDir() |
| 37 | db := openTestDB(t, filepath.Join(dir, "test.db")) |
| 38 | if err := store.AppendRecalc(db, 42, 1200); err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | var e store.Event |
| 42 | db.Where("kind = ?", store.KindRecalc).First(&e) |
| 43 | if len(e.PayloadSealed) != 0 { |
| 44 | t.Fatal("recalc marker carries a payload; it must not") |
| 45 | } |
| 46 | if e.DerivedCount != 1200 { |
| 47 | t.Fatalf("DerivedCount = %d, want 1200", e.DerivedCount) |
| 48 | } |
| 49 | } |
| 50 | |