]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-import.t
tests: add test_lei wrapper, split out t/lei-import.t
[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
7 ok($lei->(qw(q s:boolean)), 'search miss before import');
8 unlike($lei_out, qr/boolean/i, 'no results, yet');
9 open my $fh, '<', 't/data/0001.patch' or BAIL_OUT $!;
10 ok($lei->([qw(import -f eml -)], undef, { %$lei_opt, 0 => $fh }),
11         'import single file from stdin');
12 close $fh;
13 ok($lei->(qw(q s:boolean)), 'search hit after import');
14 ok($lei->(qw(import -f eml), 't/data/message_embed.eml'),
15         'import single file by path');
16
17 my $str = <<'';
18 From: a@b
19 Message-ID: <x@y>
20 Status: RO
21
22 my $opt = { %$lei_opt, 0 => \$str };
23 ok($lei->([qw(import -f eml -)], undef, $opt),
24         'import single file with keywords from stdin');
25 $lei->(qw(q m:x@y));
26 my $res = json_utf8->decode($lei_out);
27 is($res->[1], undef, 'only one result');
28 is_deeply($res->[0]->{kw}, ['seen'], "message `seen' keyword set");
29
30 $str =~ tr/x/v/; # v@y
31 ok($lei->([qw(import --no-kw -f eml -)], undef, $opt),
32         'import single file with --no-kw from stdin');
33 $lei->(qw(q m:v@y));
34 $res = json_utf8->decode($lei_out);
35 is($res->[1], undef, 'only one result');
36 is_deeply($res->[0]->{kw}, [], 'no keywords set');
37
38 });
39 done_testing;