]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-import.t
lei: split out MdirReader package, lazy-require earlier
[public-inbox.git] / t / lei-import.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 use strict; use v5.10.1; use PublicInbox::TestCommon;
5 test_lei(sub {
6 ok(!$lei->(qw(import -f bogus), 't/plack-qp.eml'), 'fails with bogus format');
7 like($lei_err, qr/\bbogus unrecognized/, 'gave error message');
8
9 ok($lei->(qw(q s:boolean)), 'search miss before import');
10 unlike($lei_out, qr/boolean/i, 'no results, yet');
11 open my $fh, '<', 't/data/0001.patch' or BAIL_OUT $!;
12 ok($lei->([qw(import -f eml -)], undef, { %$lei_opt, 0 => $fh }),
13         'import single file from stdin') or diag $lei_err;
14 close $fh;
15 ok($lei->(qw(q s:boolean)), 'search hit after import');
16 ok($lei->(qw(import -f eml), 't/data/message_embed.eml'),
17         'import single file by path');
18
19 my $str = <<'';
20 From: a@b
21 Message-ID: <x@y>
22 Status: RO
23
24 my $opt = { %$lei_opt, 0 => \$str };
25 ok($lei->([qw(import -f eml -)], undef, $opt),
26         'import single file with keywords from stdin');
27 $lei->(qw(q m:x@y));
28 my $res = json_utf8->decode($lei_out);
29 is($res->[1], undef, 'only one result');
30 is_deeply($res->[0]->{kw}, ['seen'], "message `seen' keyword set");
31
32 $str =~ tr/x/v/; # v@y
33 ok($lei->([qw(import --no-kw -f eml -)], undef, $opt),
34         'import single file with --no-kw from stdin');
35 $lei->(qw(q m:v@y));
36 $res = json_utf8->decode($lei_out);
37 is($res->[1], undef, 'only one result');
38 is_deeply($res->[0]->{kw}, [], 'no keywords set');
39
40 # see t/lei_to_mail.t for "import -f mbox*"
41 });
42 done_testing;