2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
6 require_mods(qw(DBD::SQLite Search::Xapian));
7 my $sock = tcp_server();
8 my ($tmpdir, $for_destroy) = tmpdir();
9 my $http = 'http://'.tcp_host_port($sock);
10 my ($ro_home, $cfg_path) = setup_public_inboxes;
11 my $cmd = [ qw(-httpd -W0), "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ];
12 my $td = start_script($cmd, { PI_CONFIG => $cfg_path }, { 3 => $sock });
13 test_lei({ tmpdir => $tmpdir }, sub {
14 my $home = $ENV{HOME};
15 my $t1 = "$home/t1-mirror";
16 lei_ok('add-external', $t1, '--mirror', "$http/t1/", \'--mirror v1');
17 ok(-f "$t1/public-inbox/msgmap.sqlite3", 't1-mirror indexed');
19 lei_ok('ls-external');
20 like($lei_out, qr!\Q$t1\E!, 't1 added to ls-externals');
22 my $t2 = "$home/t2-mirror";
23 lei_ok('add-external', $t2, '--mirror', "$http/t2/", \'--mirror v2');
24 ok(-f "$t2/msgmap.sqlite3", 't2-mirror indexed');
26 lei_ok('ls-external');
27 like($lei_out, qr!\Q$t2\E!, 't2 added to ls-externals');
29 ok(!lei('add-external', $t2, '--mirror', "$http/t2/"),
30 '--mirror fails if reused') or diag "$lei_err.$lei_out = $?";
32 lei_ok('ls-external');
33 like($lei_out, qr!\Q$t2\E!, 'still in ls-externals');
35 ok(!lei('add-external', "$t2-fail", '-Lmedium'), '--mirror v2');
36 ok(!-d "$t2-fail", 'destination not created on failure');
37 lei_ok('ls-external');
38 unlike($lei_out, qr!\Q$t2-fail\E!, 'not added to ls-external');
41 ok($td->kill, 'killed -httpd');