2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
9 require_mods(qw(DBD::SQLite Search::Xapian));
10 use_ok 'PublicInbox::ExtSearch';
11 use_ok 'PublicInbox::ExtSearchIdx';
12 my ($home, $for_destroy) = tmpdir();
13 local $ENV{HOME} = $home;
14 mkdir "$home/.public-inbox" or BAIL_OUT $!;
15 open my $fh, '>', "$home/.public-inbox/config" or BAIL_OUT $!;
16 print $fh <<EOF or BAIL_OUT $!;
20 close $fh or BAIL_OUT $!;
21 my $v2addr = 'v2test@example.com';
22 my $v1addr = 'v1test@example.com';
23 ok(run_script([qw(-init -V2 v2test --newsgroup v2.example), "$home/v2test",
24 'http://example.com/v2test', $v2addr ]), 'v2test init');
25 my $env = { ORIGINAL_RECIPIENT => $v2addr };
26 open($fh, '<', 't/utf8.eml') or BAIL_OUT("open t/utf8.eml: $!");
27 run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
29 ok(run_script([qw(-init -V1 v1test), "$home/v1test",
30 'http://example.com/v1test', $v1addr ]), 'v1test init');
31 $env = { ORIGINAL_RECIPIENT => $v1addr };
32 seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
33 run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
34 run_script(['-index', "$home/v1test"]) or BAIL_OUT "index $?";
36 ok(run_script([qw(-eindex --all), "$home/eindex"]), 'eindex init');
39 my $es = PublicInbox::ExtSearch->new("$home/eindex");
40 my $smsg = $es->over->get_art(1);
41 ok($smsg, 'got first article');
42 is($es->over->get_art(2), undef, 'only one added');
43 my $xref3 = $es->over->get_xref3(1);
44 like($xref3->[0], qr/\A\Qv2.example\E:1:/, 'order preserved 1');
45 like($xref3->[1], qr!\A\Q$home/v1test\E:1:!, 'order preserved 2');
46 is(scalar(@$xref3), 2, 'only to entries');