about summary refs log tree commit homepage
path: root/t/lei-mirror.t
diff options
context:
space:
mode:
Diffstat (limited to 't/lei-mirror.t')
-rw-r--r--t/lei-mirror.t75
1 files changed, 65 insertions, 10 deletions
diff --git a/t/lei-mirror.t b/t/lei-mirror.t
index 7dd03b26..76041b73 100644
--- a/t/lei-mirror.t
+++ b/t/lei-mirror.t
@@ -1,10 +1,13 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# 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;
+use v5.12; use PublicInbox::TestCommon;
 use PublicInbox::Inbox;
-require_mods(qw(-httpd lei));
+require_mods(qw(-httpd lei DBD::SQLite));
 require_cmd('curl');
+require_git_http_backend;
+use PublicInbox::Spawn qw(which);
+require PublicInbox::Msgmap;
 my $sock = tcp_server();
 my ($tmpdir, $for_destroy) = tmpdir();
 my $http = 'http://'.tcp_host_port($sock);
@@ -12,25 +15,47 @@ my ($ro_home, $cfg_path) = setup_public_inboxes;
 my $cmd = [ qw(-httpd -W0 ./t/lei-mirror.psgi),
         "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ];
 my $td = start_script($cmd, { PI_CONFIG => $cfg_path }, { 3 => $sock });
+my %created;
 test_lei({ tmpdir => $tmpdir }, sub {
         my $home = $ENV{HOME};
         my $t1 = "$home/t1-mirror";
+        my $mm_orig = "$ro_home/t1/public-inbox/msgmap.sqlite3";
+        $created{v1} = PublicInbox::Msgmap->new_file($mm_orig)->created_at;
         lei_ok('add-external', $t1, '--mirror', "$http/t1/", \'--mirror v1');
-        ok(-f "$t1/public-inbox/msgmap.sqlite3", 't1-mirror indexed');
-        is(PublicInbox::Inbox::try_cat("$t1/description"),
+        my $mm_dup = "$t1/public-inbox/msgmap.sqlite3";
+        ok(-f $mm_dup, 't1-mirror indexed');
+        is(PublicInbox::IO::try_cat("$t1/description"),
                 "mirror of $http/t1/\n", 'description set');
         ok(-f "$t1/Makefile", 'convenience Makefile added (v1)');
+        SKIP: {
+                my $make = require_cmd('make', 1);
+                delete local @ENV{qw(MFLAGS MAKEFLAGS MAKELEVEL)};
+                is(xsys([$make, 'help'], undef, { -C => $t1, 1 => \(my $help) }),
+                        0, "$make handled Makefile without errors");
+                isnt($help, '', 'make help worked');
+        }
+        ok(-f "$t1/inbox.config.example", 'inbox.config.example downloaded');
+        is((stat(_))[9], $created{v1},
+                'inbox.config.example mtime is ->created_at');
+        is((stat(_))[2] & 0222, 0, 'inbox.config.example not writable');
+        my $tb = PublicInbox::Msgmap->new_file($mm_dup)->created_at;
+        is($tb, $created{v1}, 'created_at matched in mirror');
 
         lei_ok('ls-external');
         like($lei_out, qr!\Q$t1\E!, 't1 added to ls-externals');
 
         my $t2 = "$home/t2-mirror";
+        $mm_orig = "$ro_home/t2/msgmap.sqlite3";
+        $created{v2} = PublicInbox::Msgmap->new_file($mm_orig)->created_at;
         lei_ok('add-external', $t2, '--mirror', "$http/t2/", \'--mirror v2');
-        ok(-f "$t2/msgmap.sqlite3", 't2-mirror indexed');
+        $mm_dup = "$t2/msgmap.sqlite3";
+        ok(-f $mm_dup, 't2-mirror indexed');
         ok(-f "$t2/description", 't2 description');
         ok(-f "$t2/Makefile", 'convenience Makefile added (v2)');
-        is(PublicInbox::Inbox::try_cat("$t2/description"),
+        is(PublicInbox::IO::try_cat("$t2/description"),
                 "mirror of $http/t2/\n", 'description set');
+        $tb = PublicInbox::Msgmap->new_file($mm_dup)->created_at;
+        is($tb, $created{v2}, 'created_at matched in v2 mirror');
 
         lei_ok('ls-external');
         like($lei_out, qr!\Q$t2\E!, 't2 added to ls-externals');
@@ -65,6 +90,14 @@ test_lei({ tmpdir => $tmpdir }, sub {
         lei_ok('ls-external');
         unlike($lei_out, qr!\Q$d\E!s, 'not added to ls-external');
 
+        $d = "$home/bad-epoch";
+        ok(!lei(qw(add-external -q --epoch=0.. --mirror), "$http/t1/", $d),
+                'v1 fails on --epoch');
+        ok(!-d $d, 'destination not created on unacceptable --epoch');
+        ok(!lei(qw(add-external -q --epoch=1 --mirror), "$http/t2/", $d),
+                'v2 fails on bad epoch range');
+        ok(!-d $d, 'destination not created on bad epoch');
+
         my %phail = (
                 HTTPS => 'https://public-inbox.org/' . 'phail',
                 ONION =>
@@ -142,6 +175,28 @@ SKIP: {
         ok(unlink("$d/t1/manifest.js.gz"), 'manifest created');
         my $after = [ glob("$d/t1/*") ];
         is_deeply($before, $after, 'no new files created');
+
+        local $ENV{HOME} = $tmpdir;
+        ok(run_script([qw(-index -Lbasic), "$d/t1"]), 'index v1');
+        ok(run_script([qw(-index -Lbasic), "$d/t2"]), 'index v2');
+
+        SKIP: {
+                join('', sort(keys %created)) eq 'v1v2' or
+                        skip "lei didn't run", 2;
+                my $f = "$d/t1/public-inbox/msgmap.sqlite3";
+                my $ca = PublicInbox::Msgmap->new_file($f)->created_at;
+                is($ca, $created{v1}, 'clone + index v1 synced ->created_at');
+
+                $f = "$d/t2/msgmap.sqlite3";
+                $ca = PublicInbox::Msgmap->new_file($f)->created_at;
+                is($ca, $created{v2}, 'clone + index v2 synced ->created_at');
+        }
+        test_lei(sub {
+                lei_ok qw(inspect num:1 --dir), "$d/t1";
+                ok(ref(json_utf8->decode($lei_out)), 'inspect num: on v1');
+                lei_ok qw(inspect num:1 --dir), "$d/t2";
+                ok(ref(json_utf8->decode($lei_out)), 'inspect num: on v2');
+        });
 }
 
 ok($td->kill, 'killed -httpd');
@@ -153,14 +208,14 @@ $td->join;
         my $exp = "mirror of https://example.com/src/\n";
         my $f = "$tmpdir/description";
         PublicInbox::LeiMirror::set_description($mrr);
-        is(PublicInbox::Inbox::try_cat($f), $exp, 'description set on ENOENT');
+        is(PublicInbox::IO::try_cat($f), $exp, 'description set on ENOENT');
 
         my $fh;
         (open($fh, '>', $f) and close($fh)) or xbail $!;
         PublicInbox::LeiMirror::set_description($mrr);
-        is(PublicInbox::Inbox::try_cat($f), $exp, 'description set on empty');
+        is(PublicInbox::IO::try_cat($f), $exp, 'description set on empty');
         (open($fh, '>', $f) and print $fh "x\n" and close($fh)) or xbail $!;
-        is(PublicInbox::Inbox::try_cat($f), "x\n",
+        is(PublicInbox::IO::try_cat($f), "x\n",
                 'description preserved if non-default');
 }