aboutsummaryrefslogtreecommitdiff
path: root/cmds/export_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmds/export_test.go')
-rw-r--r--cmds/export_test.go46
1 files changed, 44 insertions, 2 deletions
diff --git a/cmds/export_test.go b/cmds/export_test.go
index 0be1ac3..4483f10 100644
--- a/cmds/export_test.go
+++ b/cmds/export_test.go
@@ -224,6 +224,10 @@ func TestExportURLDedup(t *testing.T) {
// no row at all.
func TestExportRelabelsStarredNegative(t *testing.T) {
p := &pagedServer{starred: makeEntries(1, 1000, true, 7)}
+ // The star happened two hours ago; the flip must carry that moment, not
+ // the export run's clock.
+ starChanged := time.Now().Add(-2 * time.Hour).UTC().Truncate(time.Second)
+ p.starred[0].ChangedAt = starChanged
dir := t.TempDir()
labelsPath := filepath.Join(dir, "labels.jsonl")
@@ -256,8 +260,11 @@ func TestExportRelabelsStarredNegative(t *testing.T) {
if got.EntryID != 1000 || got.Title != "Title 1000" || got.FeedID != 7 {
t.Errorf("relabel must keep the row's identity, got %+v", got)
}
- if !got.CapturedAt.After(old) {
- t.Errorf("captured_at = %v, want refreshed past %v", got.CapturedAt, old)
+ if !got.CapturedAt.Equal(starChanged) {
+ t.Errorf("captured_at = %v, want the star's own time %v", got.CapturedAt, starChanged)
+ }
+ if got.CapturedAt.Before(old) {
+ t.Errorf("captured_at = %v predates the negative's %v; the star never moved the row", got.CapturedAt, old)
}
// The pre-rewrite file is preserved as a backup.
@@ -317,6 +324,41 @@ func TestExportRelabelsRecFeedStar(t *testing.T) {
}
}
+// Labels carry each entry's own changed_at (when the judgment happened), not
+// the export run's clock; an entry reporting no changed_at falls back to the
+// run time.
+func TestExportStampsChangedAt(t *testing.T) {
+ judgment := time.Now().Add(-9 * 24 * time.Hour).UTC().Truncate(time.Second)
+ starred := makeEntries(2, 1000, true, 7)
+ starred[0].ChangedAt = judgment
+ starred[1].ChangedAt = time.Time{}
+ p := &pagedServer{starred: starred}
+ dir := t.TempDir()
+
+ started := time.Now()
+ runExportAgainst(t, p, dir)
+ finished := time.Now()
+
+ labels, err := core.ReadLabels(filepath.Join(dir, "labels.jsonl"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(labels) != 2 {
+ t.Fatalf("expected 2 rows, got %d", len(labels))
+ }
+ byID := map[int64]core.LabelRow{}
+ for _, row := range labels {
+ byID[row.EntryID] = row
+ }
+ if !byID[1000].CapturedAt.Equal(judgment) {
+ t.Errorf("captured_at = %v, want the entry's changed_at %v", byID[1000].CapturedAt, judgment)
+ }
+ fallback := byID[1001].CapturedAt
+ if fallback.Before(started) || fallback.After(finished) {
+ t.Errorf("zero changed_at should fall back to the run clock, got %v (run %v→%v)", fallback, started, finished)
+ }
+}
+
func TestExportRecFeedResolution(t *testing.T) {
// Two starred entries ON the recommendations feed (feed id 99).
rec := makeEntries(2, 3000, true, 99)