]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-import-maildir.t
5842e19efa6f652538c0d946151c4eeaa4709d41
[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         ok($lei->(qw(import), $md), 'import Maildir');
14         ok($lei->(qw(q s:boolean)), 'lei q');
15         my $res = json_utf8->decode($lei_out);
16         like($res->[0]->{'s'}, qr/use boolean/, 'got expected result');
17         is_deeply($res->[0]->{kw}, ['seen'], 'keyword set');
18         is($res->[1], undef, 'only got one result');
19
20         ok($lei->(qw(import), $md), 'import Maildir again');
21         ok($lei->(qw(q -d none s:boolean)), 'lei q w/o dedupe');
22         my $r2 = json_utf8->decode($lei_out);
23         is_deeply($r2, $res, 'idempotent import');
24
25         rename("$md/cur/x:2,S", "$md/cur/x:2,SR") or BAIL_OUT "rename: $!";
26         ok($lei->(qw(import), $md), 'import Maildir after +answered');
27         ok($lei->(qw(q -d none s:boolean)), 'lei q after +answered');
28         $res = json_utf8->decode($lei_out);
29         like($res->[0]->{'s'}, qr/use boolean/, 'got expected result');
30         is_deeply($res->[0]->{kw}, ['answered', 'seen'], 'keywords set');
31         is($res->[1], undef, 'only got one result');
32 });
33 done_testing;