]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-watch.t
lei: start implementing inotify Maildir support
[public-inbox.git] / t / lei-watch.t
1 #!perl -w
2 # Copyright 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 File::Path qw(make_path);
6 require_mods('lei');
7 my $have_fast_inotify = eval { require Linux::Inotify2 } ||
8         eval { require IO::KQueue };
9
10 $have_fast_inotify or
11         diag("$0 IO::KQueue or Linux::Inotify2 missing, test will be slow");
12
13 my ($ro_home, $cfg_path) = setup_public_inboxes;
14 test_lei(sub {
15         my $md = "$ENV{HOME}/md";
16         my $md2 = $md.'2';
17         lei_ok 'ls-watch';
18         is($lei_out, '', 'nothing in ls-watch, yet');
19         if (0) { # TODO
20                 my $url = 'imaps://example.com/foo.bar.0';
21                 lei_ok([qw(add-watch --state=pause), $url], undef, {});
22                 lei_ok 'ls-watch';
23                 is($lei_out, "$url\n", 'ls-watch shows added watch');
24                 ok(!lei(qw(add-watch --state=pause), 'bogus'.$url),
25                         'bogus URL rejected');
26         }
27
28         # first, make sure tag-ro works
29         make_path("$md/new", "$md/cur", "$md/tmp");
30         lei_ok qw(add-watch --state=tag-ro), $md;
31         lei_ok 'ls-watch';
32         like($lei_out, qr/^\Qmaildir:$md\E$/sm, 'maildir shown');
33         lei_ok qw(q mid:testmessage@example.com -o), $md, '-I', "$ro_home/t1";
34         my @f = glob("$md/cur/*:2,");
35         is(scalar(@f), 1, 'got populated maildir with one result');
36         rename($f[0], "$f[0]S") or xbail "rename $!"; # set (S)een
37         $have_fast_inotify or tick(2);
38         lei_ok qw(note-event done); # flushes immediately (instead of 5s)
39
40         lei_ok qw(q mid:testmessage@example.com -o), $md2, '-I', "$ro_home/t1";
41         my @f2 = glob("$md2/*/*");
42         is(scalar(@f2), 1, 'got one result');
43         like($f2[0], qr/S\z/, 'seen set from rename');
44         my $e2 = eml_load($f2[0]);
45         my $e1 = eml_load("$f[0]S");
46         is_deeply($e2, $e1, 'results match');
47 });
48
49 done_testing;