]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-auto-watch.t
e5e132eb3bfdfcf1879669cb854063e687d696aa
[public-inbox.git] / t / lei-auto-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::Basename qw(basename);
6 my $have_fast_inotify = eval { require Linux::Inotify2 } ||
7         eval { require IO::KQueue };
8 $have_fast_inotify or
9         diag("$0 IO::KQueue or Linux::Inotify2 missing, test will be slow");
10
11 test_lei(sub {
12         my ($ro_home, $cfg_path) = setup_public_inboxes;
13         my $x = "$ENV{HOME}/x";
14         my $y = "$ENV{HOME}/y";
15         lei_ok qw(add-external), "$ro_home/t1";
16         lei_ok qw(q mid:testmessage@example.com -o), $x;
17         lei_ok qw(q mid:testmessage@example.com -o), $y;
18         my @x = glob("$x/cur/*");
19         my @y = glob("$y/cur/*");
20         scalar(@x) == 1 or xbail 'expected 1 file', \@x;
21         scalar(@y) == 1 or xbail 'expected 1 file', \@y;
22
23         my $oid = '9bf1002c49eb075df47247b74d69bcd555e23422';
24         lei_ok qw(inspect), "blob:$oid";
25         my $ins = json_utf8->decode($lei_out);
26         my $exp = { "maildir:$x" => [ map { basename($_) } @x ],
27                 "maildir:$y" => [ map { basename($_) } @y ] };
28         is_deeply($ins->{'mail-sync'}, $exp, 'inspect as expected');
29         lei_ok qw(add-watch), $x;
30         my $dst = $x[0] . 'S';
31         rename($x[0], $dst) or xbail "rename($x[0], $dst): $!";
32         my $ys = "$y[0]S";
33         for (0..50) {
34                 last if -f $ys;
35                 tick; # wait for inotify or kevent
36         }
37         my @y2 = glob("$y/*/*");
38         is_deeply(\@y2, [ $ys ], "`seen' kw propagated to `y' dir");
39         lei_ok qw(note-event done);
40         lei_ok qw(inspect), "blob:$oid";
41         $ins = json_utf8->decode($lei_out);
42         $exp = { "maildir:$x" => [ map { basename($_) } glob("$x/*/*") ],
43                 "maildir:$y" => [ map { basename($_) } glob("$y/*/*") ] };
44         is_deeply($ins->{'mail-sync'}, $exp, 'mail_sync matches FS');
45 });
46
47 done_testing;