]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-import.t
lei import: use --in-format/-F for consistency
[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 lei_ok(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 lei_ok([qw(import -F eml -)], undef, { %$lei_opt, 0 => $fh },
13         \'import single file from stdin') or diag $lei_err;
14 close $fh;
15 lei_ok(qw(q s:boolean), \'search hit after import');
16 lei_ok(qw(q s:boolean -f mboxrd), \'blob accessible after import');
17 {
18         my $expect = [ eml_load('t/data/0001.patch') ];
19         require PublicInbox::MboxReader;
20         my @cmp;
21         open my $fh, '<', \$lei_out or BAIL_OUT "open :scalar: $!";
22         PublicInbox::MboxReader->mboxrd($fh, sub {
23                 my ($eml) = @_;
24                 $eml->header_set('Status');
25                 push @cmp, $eml;
26         });
27         is_deeply(\@cmp, $expect, 'got expected message in mboxrd');
28 }
29 lei_ok(qw(import -F eml), 't/data/message_embed.eml',
30         \'import single file by path');
31
32 my $str = <<'';
33 From: a@b
34 Message-ID: <x@y>
35 Status: RO
36
37 my $opt = { %$lei_opt, 0 => \$str };
38 lei_ok([qw(import -F eml -)], undef, $opt,
39         \'import single file with keywords from stdin');
40 lei_ok(qw(q m:x@y));
41 my $res = json_utf8->decode($lei_out);
42 is($res->[1], undef, 'only one result');
43 is_deeply($res->[0]->{kw}, ['seen'], "message `seen' keyword set");
44
45 $str =~ tr/x/v/; # v@y
46 lei_ok([qw(import --no-kw -F eml -)], undef, $opt,
47         \'import single file with --no-kw from stdin');
48 lei(qw(q m:v@y));
49 $res = json_utf8->decode($lei_out);
50 is($res->[1], undef, 'only one result');
51 is_deeply($res->[0]->{kw}, [], 'no keywords set');
52
53 # see t/lei_to_mail.t for "import -F mbox*"
54 });
55 done_testing;