]> Sergey Matveev's repositories - public-inbox.git/blob - t/v2dupindex.t
xt/mem-imapd-tls: update aliases to DSdeflate subs
[public-inbox.git] / t / v2dupindex.t
1 #!perl -w
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
5 # we can index a message from a mirror which bypasses dedupe.
6 use strict;
7 use v5.10.1;
8 use PublicInbox::TestCommon;
9 use PublicInbox::Import;
10 use PublicInbox::Git;
11 require_git(2.6);
12 require_mods(qw(DBD::SQLite));
13 my ($tmpdir, $for_destroy) = tmpdir();
14 my $inboxdir = "$tmpdir/test";
15 my $ibx = create_inbox('test', indexlevel => 'basic', version => 2,
16                 tmpdir => $inboxdir, sub {
17         my ($im, $ibx) = @_;
18         $im->add(eml_load('t/plack-qp.eml'));
19         $im->add(eml_load('t/mda-mime.eml'));
20         $im->done;
21
22         # bypass duplicate filters (->header_set is optional)
23         my $git0 = PublicInbox::Git->new("$ibx->{inboxdir}/git/0.git");
24         $_[0] = undef;
25         $im = PublicInbox::Import->new($git0, undef, undef, $ibx);
26         $im->{path_type} = 'v2';
27         $im->{lock_path} = undef;
28
29         my $eml = eml_load('t/plack-qp.eml');
30         $eml->header_set('X-This-Is-Not-Checked-By-ContentHash', 'blah');
31         $im->add($eml) or BAIL_OUT 'add seen message directly';
32         $im->add(eml_load('t/mda-mime.eml')) or
33                 BAIL_OUT 'add another seen message directly';
34         $im->add(eml_load('t/iso-2202-jp.eml')) or
35                 BAIL_OUT 'add another new message';
36         $im->done;
37         # mimic a fresh clone by dropping indices
38         my $dir = $ibx->{inboxdir};
39         my @sqlite = (glob("$dir/*sqlite3*"), glob("$dir/xap*/*sqlite3*"));
40         unlink(@sqlite) == scalar(@sqlite) or
41                         BAIL_OUT 'did not unlink SQLite indices';
42         my @shards = glob("$dir/xap*/?");
43         scalar(@shards) == 0 or BAIL_OUT 'Xapian shards created unexpectedly';
44         open my $fh, '>', "$dir/empty" or BAIL_OUT;
45         rmdir($_) for glob("$dir/xap*");
46 });
47 my $env = { PI_CONFIG => "$inboxdir/empty" };
48 my $rdr = { 2 => \(my $err = '') };
49 ok(run_script([qw(-index -Lbasic), $inboxdir ], $env, $rdr), '-indexed');
50 my @n = $ibx->over->dbh->selectrow_array('SELECT COUNT(*) FROM over');
51 is_deeply(\@n, [ 3 ], 'identical message not re-indexed');
52 my $mm = $ibx->mm->{dbh}->selectall_arrayref(<<'');
53 SELECT num,mid FROM msgmap ORDER BY num ASC
54
55 is_deeply($mm, [
56         [ 1, 'qp@example.com' ],
57         [ 2, 'multipart-html-sucks@11' ],
58         [ 3, '199707281508.AAA24167@hoyogw.example' ]
59 ], 'msgmap omits redundant message');
60
61 done_testing;