]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-import-maildir.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / lei-import-maildir.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 use Cwd qw(abs_path);
6 test_lei(sub {
7         my $md = "$ENV{HOME}/md";
8         for ($md, "$md/new", "$md/cur", "$md/tmp") {
9                 mkdir($_) or BAIL_OUT("mkdir $_: $!");
10         }
11         symlink(abs_path('t/data/0001.patch'), "$md/cur/x:2,S") or
12                 BAIL_OUT "symlink $md $!";
13         lei_ok(qw(import), "$md/", \'import Maildir');
14         my $imp_err = $lei_err;
15
16         my %i;
17         lei_ok('inspect', $md); $i{no_type} = $lei_out;
18         lei_ok('inspect', "$md/"); $i{no_type_tslash} = $lei_out;
19         lei_ok('inspect', "maildir:$md"), $i{with_type} = $lei_out;
20         lei_ok('inspect', "maildir:$md/"), $i{with_type_tslash} = $lei_out;
21         lei_ok('inspect', "MAILDIR:$md"), $i{ALLCAPS} = $lei_out;
22         lei_ok(['inspect', $md], undef, { -C => $ENV{HOME}, %$lei_opt });
23         $i{rel_no_type} = $lei_out;
24         lei_ok(['inspect', "maildir:$md"], undef,
25                 { -C => $ENV{HOME}, %$lei_opt });
26         $i{rel_with_type} = $lei_out;
27         my %v = map { $_ => 1 } values %i;
28         is(scalar(keys %v), 1, 'inspect handles relative and absolute paths');
29         my $inspect = json_utf8->decode([ keys %v ]->[0]);
30         is_deeply($inspect, {"maildir:$md" => { 'name.count' => 1 }},
31                 'inspect maildir: path had expected output') or xbail($inspect);
32
33         lei_ok(qw(q s:boolean));
34         my $res = json_utf8->decode($lei_out);
35         like($res->[0]->{'s'}, qr/use boolean/, 'got expected result')
36                         or diag explain($imp_err, $res);
37         is_deeply($res->[0]->{kw}, ['seen'], 'keyword set');
38         is($res->[1], undef, 'only got one result');
39
40         lei_ok('inspect', "blob:$res->[0]->{blob}");
41         $inspect = json_utf8->decode($lei_out);
42         is(ref(delete $inspect->{"lei/store"}), 'ARRAY', 'lei/store IDs');
43         is_deeply($inspect, { 'mail-sync' => { "maildir:$md" => [ 'x:2,S' ] } },
44                 'maildir sync info as expected');
45
46         lei_ok qw(ls-mail-sync);
47         is($lei_out, "maildir:$md\n", 'ls-mail-sync as expected');
48
49         lei_ok(qw(import), $md, \'import Maildir again');
50         $imp_err = $lei_err;
51         lei_ok(qw(q -d none s:boolean), \'lei q w/o dedupe');
52         my $r2 = json_utf8->decode($lei_out);
53         is_deeply($r2, $res, 'idempotent import')
54                         or diag explain($imp_err, $res);
55         rename("$md/cur/x:2,S", "$md/cur/x:2,RS") or BAIL_OUT "rename: $!";
56         lei_ok('import', "maildir:$md", \'import Maildir after +answered');
57         lei_ok(qw(q -d none s:boolean), \'lei q after +answered');
58         $res = json_utf8->decode($lei_out);
59         like($res->[0]->{'s'}, qr/use boolean/, 'got expected result');
60         is_deeply($res->[0]->{kw}, ['answered', 'seen'], 'keywords set');
61         is($res->[1], undef, 'only got one result');
62
63         symlink(abs_path('t/utf8.eml'), "$md/cur/u:2,ST") or
64                 BAIL_OUT "symlink $md $!";
65         lei_ok('import', "maildir:$md", \'import Maildir w/ trashed message');
66         $imp_err = $lei_err;
67         lei_ok(qw(q -d none m:testmessage@example.com));
68         $res = json_utf8->decode($lei_out);
69         is_deeply($res, [ undef ], 'trashed message not imported')
70                         or diag explain($imp_err, $res);
71
72         lei_ok qw(rm t/data/0001.patch);
73         lei_ok(qw(q s:boolean));
74         is($lei_out, "[null]\n", 'removed message gone from results');
75         my $g0 = "$ENV{HOME}/.local/share/lei/store/local/0.git";
76         my $x = xqx(['git', "--git-dir=$g0", qw(cat-file blob HEAD:d)]);
77         is($?, 0, "git cat-file shows file is `d'");
78 });
79 done_testing;