2 # Copyright (C) 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(json DBD::SQLite Search::Xapian));
7 use PublicInbox::MboxReader;
8 my ($ro_home, $cfg_path) = setup_public_inboxes;
10 my ($tmpdir, $for_destroy) = tmpdir;
11 my $cmd = [ '-httpd', '-W0', "--stdout=$tmpdir/1", "--stderr=$tmpdir/2" ];
12 my $env = { PI_CONFIG => $cfg_path };
13 my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-httpd: $?");
14 my $host_port = tcp_host_port($sock);
15 my $url = "http://$host_port/t2/";
16 my $exp1 = [ eml_load('t/plack-qp.eml') ];
17 my $exp2 = [ eml_load('t/iso-2202-jp.eml') ];
18 my $slurp_emls = sub {
19 open my $fh, '<', $_[0] or BAIL_OUT "open: $!";
21 PublicInbox::MboxReader->mboxrd($fh, sub {
23 $eml->header_set('Status');
29 test_lei({ tmpdir => $tmpdir }, sub {
30 my $o = "$ENV{HOME}/o.mboxrd";
31 my @cmd = ('q', '-o', "mboxrd:$o", 'm:qp@example.com');
33 ok(-f $o && !-s _, 'output exists but is empty');
34 unlink $o or BAIL_OUT $!;
35 lei_ok(@cmd, '-I', $url);
36 is_deeply($slurp_emls->($o), $exp1, 'got results after remote search');
37 unlink $o or BAIL_OUT $!;
39 ok(-f $o && -s _, 'output exists after import but is not empty');
40 is_deeply($slurp_emls->($o), $exp1, 'got results w/o remote search');
41 unlink $o or BAIL_OUT $!;
43 $cmd[-1] = 'm:199707281508.AAA24167@hoyogw.example';
44 lei_ok(@cmd, '-I', $url, '--no-import-remote');
45 is_deeply($slurp_emls->($o), $exp2, 'got another after remote search');
46 unlink $o or BAIL_OUT $!;
48 ok(-f $o && !-s _, '--no-import-remote did not memoize');
50 open my $fh, '>', "$o.lock";
51 $cmd[-1] = 'm:qp@example.com';
52 unlink $o or BAIL_OUT $!;
53 lei_ok(@cmd, '--lock=none');
54 ok(-f $o && -s _, '--lock=none respected');
55 unlink $o or BAIL_OUT $!;
56 ok(!lei(@cmd, '--lock=dotlock,timeout=0.000001'), 'dotlock fails');
57 ok(-f $o && !-s _, 'nothing output on lock failure');
58 unlink "$o.lock" or BAIL_OUT $!;
59 lei_ok(@cmd, '--lock=dotlock,timeout=0.000001',
60 \'succeeds after lock removal');