about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-05 09:40:17 +0000
committerEric Wong <e@80x24.org>2021-10-05 23:09:45 +0000
commitef68ada3b207fdb511ebe6d33b072a84277e6cd6 (patch)
tree1154347962fccb85bbf0d8fcbb6489f4045448a7 /t
parent88344a50f62a39dcb5673b0aa42ebec7ec44bd71 (diff)
downloadpublic-inbox-ef68ada3b207fdb511ebe6d33b072a84277e6cd6.tar.gz
This lets administrators reindex specific time ranges
according to git "approxidate" formats.  These arguments
are passed directly to underlying git-log(1) invocations
and may still reach into old epochs.

Since these options rely on git committer dates (which we infer
from the most recent Received: header), they are not guaranteed
to be strictly tied to git history and it's possible to
over/under-reindex some messages.  It's probably not a major
problem in practice, though; reindexing a few extra messages
is generally harmless aside from some extra device wear.

Since this currently relies on git-log, these options do not
affect -extindex, yet.
Diffstat (limited to 't')
-rw-r--r--t/reindex-time-range.t58
1 files changed, 58 insertions, 0 deletions
diff --git a/t/reindex-time-range.t b/t/reindex-time-range.t
new file mode 100644
index 00000000..59f5c2aa
--- /dev/null
+++ b/t/reindex-time-range.t
@@ -0,0 +1,58 @@
+# Copyright (C) all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict; use v5.10.1; use PublicInbox::TestCommon;
+require_mods qw(DBD::SQLite);
+my $tmp = tmpdir();
+my $eml;
+my $cb = sub {
+        my ($im, $ibx) = @_;
+        $eml //= eml_load 't/utf8.eml';
+        for my $i (1..3) {
+                $eml->header_set('Message-ID', "<$i\@example.com>");
+                my $d = "Thu, 01 Jan 1970 0$i:30:00 +0000";
+                $eml->header_set('Date', $d);
+                $im->add($eml);
+        }
+};
+my %ibx = map {;
+        "v$_" => create_inbox("v$_", version => $_,
+                        indexlevel => 'basic', tmpdir => "$tmp/v$_", $cb);
+} (1, 2);
+
+my $env = { TZ => 'UTC' };
+my ($out, $err);
+for my $v (sort keys %ibx) {
+        my $opt = { -C => $ibx{$v}->{inboxdir}, 1 => \$out, 2 => \$err };
+
+        ($out, $err) = ('', '');
+        run_script([ qw(-index -vv) ], $env, $opt);
+        is($?, 0, 'no error on initial index');
+
+        for my $x (qw(until before)) {
+                ($out, $err) = ('', '');
+                run_script([ qw(-index --reindex -vv),
+                                "--$x=1970-01-01T02:00:00Z" ], $env, $opt);
+                is($?, 0, "no error with --$x");
+                like($err, qr! 1/1\b!, "$x only indexed one message");
+        }
+        for my $x (qw(after since)) {
+                ($out, $err) = ('', '');
+                run_script([ qw(-index --reindex -vv),
+                                "--$x=1970-01-01T02:00:00Z" ], $env, $opt);
+                is($?, 0, "no error with --$x");
+                like($err, qr! 2/2\b!, "$x only indexed one message");
+        }
+
+        ($out, $err) = ('', '');
+        run_script([ qw(-index --reindex -vv) ], $env, $opt);
+        is($?, 0, 'no error on initial index');
+
+        for my $x (qw(since before after until)) {
+                ($out, $err) = ('', '');
+                run_script([ qw(-index -v), "--$x=1970-01-01T02:00:00Z" ],
+                        $env, $opt);
+                isnt($?, 0, "--$x fails on --reindex");
+        }
+}
+
+done_testing;