]> Sergey Matveev's repositories - public-inbox.git/blob - t/extsearch.t
extsearch: fix remaining "eindex" references
[public-inbox.git] / t / extsearch.t
1 #!perl -w
2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use Test::More;
6 use PublicInbox::TestCommon;
7 use PublicInbox::Config;
8 use Fcntl qw(:seek);
9 my $json = PublicInbox::Config::json() or plan skip_all => 'JSON missing';
10 require_git(2.6);
11 require_mods(qw(DBD::SQLite Search::Xapian));
12 use_ok 'PublicInbox::ExtSearch';
13 use_ok 'PublicInbox::ExtSearchIdx';
14 my ($home, $for_destroy) = tmpdir();
15 local $ENV{HOME} = $home;
16 mkdir "$home/.public-inbox" or BAIL_OUT $!;
17 open my $fh, '>', "$home/.public-inbox/config" or BAIL_OUT $!;
18 print $fh <<EOF or BAIL_OUT $!;
19 [publicinboxMda]
20         spamcheck = none
21 EOF
22 close $fh or BAIL_OUT $!;
23 my $v2addr = 'v2test@example.com';
24 my $v1addr = 'v1test@example.com';
25 ok(run_script([qw(-init -V2 v2test --newsgroup v2.example), "$home/v2test",
26         'http://example.com/v2test', $v2addr ]), 'v2test init');
27 my $env = { ORIGINAL_RECIPIENT => $v2addr };
28 open($fh, '<', 't/utf8.eml') or BAIL_OUT("open t/utf8.eml: $!");
29 run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
30
31 ok(run_script([qw(-init -V1 v1test), "$home/v1test",
32         'http://example.com/v1test', $v1addr ]), 'v1test init');
33 $env = { ORIGINAL_RECIPIENT => $v1addr };
34 seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
35 run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
36 run_script(['-index', "$home/v1test"]) or BAIL_OUT "index $?";
37
38 ok(run_script([qw(-extindex --all), "$home/extindex"]), 'extindex init');
39
40 my $es = PublicInbox::ExtSearch->new("$home/extindex");
41 {
42         my $smsg = $es->over->get_art(1);
43         ok($smsg, 'got first article');
44         is($es->over->get_art(2), undef, 'only one added');
45         my $xref3 = $es->over->get_xref3(1);
46         like($xref3->[0], qr/\A\Qv2.example\E:1:/, 'order preserved 1');
47         like($xref3->[1], qr!\A\Q$home/v1test\E:1:!, 'order preserved 2');
48         is(scalar(@$xref3), 2, 'only to entries');
49 }
50
51 {
52         my ($in, $out, $err);
53         $in = $out = $err = '';
54         my $opt = { 0 => \$in, 1 => \$out, 2 => \$err };
55         my $env = { MAIL_EDITOR => "$^X -i -p -e 's/test message/BEST MSG/'" };
56         my $cmd = [ qw(-edit -Ft/utf8.eml), "$home/v2test" ];
57         ok(run_script($cmd, $env, $opt), '-edit');
58         ok(run_script([qw(-extindex --all), "$home/extindex"], undef, $opt),
59                 'extindex again');
60         like($err, qr/discontiguous range/, 'warned about discontiguous range');
61         my $msg1 = $es->over->get_art(1) or BAIL_OUT 'msg1 missing';
62         my $msg2 = $es->over->get_art(2) or BAIL_OUT 'msg2 missing';
63         is($msg1->{mid}, $msg2->{mid}, 'edited message indexed');
64         isnt($msg1->{blob}, $msg2->{blob}, 'blobs differ');
65         my $eml2 = $es->smsg_eml($msg2);
66         like($eml2->body, qr/BEST MSG/, 'edited body in #2');
67         unlike($eml2->body, qr/test message/, 'old body discarded in #2');
68         my $eml1 = $es->smsg_eml($msg1);
69         like($eml1->body, qr/test message/, 'original body in #1');
70         my $x1 = $es->over->get_xref3(1);
71         my $x2 = $es->over->get_xref3(2);
72         is(scalar(@$x1), 1, 'original only has one xref3');
73         is(scalar(@$x2), 1, 'new message has one xref3');
74         isnt($x1->[0], $x2->[0], 'xref3 differs');
75 }
76
77 my $misc = $es->misc;
78 my @it = $misc->mset('')->items;
79 is(scalar(@it), 2, 'two inboxes');
80 like($it[0]->get_document->get_data, qr/v2test/, 'docdata matched v2');
81 like($it[1]->get_document->get_data, qr/v1test/, 'docdata matched v1');
82
83 done_testing;