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