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