]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-index.t
lei index: new command to index mail w/o git storage
[public-inbox.git] / t / lei-index.t
1 #!perl -w
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;
5 use File::Spec;
6 require_mods(qw(lei -nntpd));
7 my ($ro_home, $cfg_path) = setup_public_inboxes;
8 my ($tmpdir, $for_destroy) = tmpdir;
9 my $env = { PI_CONFIG => $cfg_path };
10
11 my $sock = tcp_server;
12 my $cmd = [ '-nntpd', '-W0', "--stdout=$tmpdir/n1", "--stderr=$tmpdir/n2" ];
13 my $nntpd = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-nntpd $?");
14 my $nntp_host_port = tcp_host_port($sock);
15
16 $sock = tcp_server;
17 $cmd = [ '-imapd', '-W0', "--stdout=$tmpdir/i1", "--stderr=$tmpdir/i2" ];
18 my $imapd = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-imapd $?");
19 my $imap_host_port = tcp_host_port($sock);
20 undef $sock;
21 for ('', qw(cur new)) {
22         mkdir "$tmpdir/md/$_" or xbail "mkdir: $!";
23 }
24 symlink(File::Spec->rel2abs('t/plack-qp.eml'), "$tmpdir/md/cur/x:2,");
25 my $expect = do {
26         open my $fh, '<', 't/plack-qp.eml' or xbail $!;
27         local $/;
28         <$fh>;
29 };
30 test_lei({ tmpdir => $tmpdir }, sub {
31         my $store_path = "$ENV{HOME}/.local/share/lei/store/";
32
33         lei_ok('index', "$tmpdir/md");
34         lei_ok(qw(q mid:qp@example.com));
35         my $res_a = json_utf8->decode($lei_out);
36         my $blob = $res_a->[0]->{'blob'};
37         like($blob, qr/\A[0-9a-f]{40,}\z/, 'got blob from qp@example');
38         lei_ok('blob', $blob);
39         is($lei_out, $expect, 'got expected blob via Maildir');
40         lei_ok(qw(q mid:qp@example.com -f text));
41         like($lei_out, qr/^hi = bye/sm, 'lei2mail fallback');
42
43         my $all_obj = ['git', "--git-dir=$store_path/ALL.git",
44                         qw(cat-file --batch-check --batch-all-objects)];
45         is_deeply([xqx($all_obj)], [], 'no git objects');
46         lei_ok('import', 't/plack-qp.eml');
47         ok(grep(/\A$blob blob /, my @objs = xqx($all_obj)),
48                 'imported blob');
49         lei_ok(qw(q z:0.. --dedupe=none));
50         my $res_b = json_utf8->decode($lei_out);
51         is_deeply($res_b, $res_a, 'no extra DB entries');
52
53         lei_ok('index', "nntp://$nntp_host_port/t.v2");
54         lei_ok('index', "imap://$imap_host_port/t.v2.0");
55         is_deeply([xqx($all_obj)], \@objs, 'no new objects from NNTP+IMAP');
56 });
57
58 done_testing;