Files
archie/internal/platform/deletions/deletions_test.go
T
sam 073959b4f9 feat(memory): scope chat notes and preserve deletions on restore (#2069)
Keep personal notes private by default and require review before publishing shared notes. Restore backups and replay forgotten notes in one transaction, and retain the installed release when an unattended rollback could bring back forgotten notes.
2026-11-21 13:20:31 +11:00

51 lines
1.4 KiB
Go

package deletions
import (
"testing"
"time"
"github.com/google/uuid"
)
// TestLogRecordsEachDeletion guards the record a restore reads: every deletion
// is one line, and the lines read back in order.
func TestLogRecordsEachDeletion(t *testing.T) {
path := Path(t.TempDir())
log := NewLog(path)
note := uuid.New()
other := uuid.New()
entries := []Entry{
{Table: "memory.notes", OrgID: "default", ID: note, At: time.Now().UTC().Truncate(time.Second)},
{Table: "another.table", OrgID: "default", ID: other, At: time.Now().UTC().Truncate(time.Second)},
}
for _, e := range entries {
if err := log.Append(t.Context(), e); err != nil {
t.Fatal(err)
}
}
read, err := NewLog(path).Entries()
if err != nil {
t.Fatal(err)
}
if len(read) != len(entries) {
t.Fatalf("read %d entries, want %d", len(read), len(entries))
}
for i, e := range read {
if e.ID != entries[i].ID || e.Table != entries[i].Table || e.OrgID != entries[i].OrgID {
t.Fatalf("entry %d = %+v, want %+v", i, e, entries[i])
}
}
}
// TestMissingLogHoldsNoDeletions guards the state of an instance that has never
// deleted anything: no file is not a failure.
func TestMissingLogHoldsNoDeletions(t *testing.T) {
entries, err := NewLog(Path(t.TempDir())).Entries()
if err != nil {
t.Fatal(err)
}
if len(entries) != 0 {
t.Fatalf("read %d entries from a log that does not exist", len(entries))
}
}