]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/watch_maildir.t
watch: ensure HUP causes the scanner to be reloaded
[public-inbox.git] / t / watch_maildir.t
index e8c97406eb59e976aec3056af96ef57f027c07ed..3969c80d6ce6171720891b02f4fd7f4662302acb 100644 (file)
@@ -3,7 +3,13 @@
 use Test::More;
 use File::Temp qw/tempdir/;
 use Email::MIME;
+use Cwd;
 use PublicInbox::Config;
+my @mods = qw(Filesys::Notify::Simple);
+foreach my $mod (@mods) {
+       eval "require $mod";
+       plan skip_all => "$mod missing for watch_maildir.t" if $@;
+}
 
 my $tmpdir = tempdir('watch_maildir-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 my $git_dir = "$tmpdir/test.git";
@@ -81,4 +87,40 @@ More majordomo info at  http://vger.kernel.org/majordomo-info.html\n);
        is(scalar @list, 4, 'four revisions in rev-list');
 }
 
+{
+       my $fail_bin = getcwd()."/t/fail-bin";
+       ok(-x "$fail_bin/spamc", "mock spamc exists");
+       my $fail_path = "$fail_bin:$ENV{PATH}"; # for spamc ham mock
+       local $ENV{PATH} = $fail_path;
+       PublicInbox::Emergency->new($maildir)->prepare(\$msg);
+       $config->{'publicinboxwatch.spamcheck'} = 'spamc';
+       {
+               local $SIG{__WARN__} = sub {}; # quiet spam check warning
+               PublicInbox::WatchMaildir->new($config)->scan;
+       }
+       @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master));
+       is(scalar @list, 0, 'tree has no files spamc checked');
+       is(unlink(glob("$maildir/new/*")), 1);
+}
+
+{
+       my $main_bin = getcwd()."/t/main-bin";
+       ok(-x "$main_bin/spamc", "mock spamc exists");
+       my $main_path = "$main_bin:$ENV{PATH}"; # for spamc ham mock
+       local $ENV{PATH} = $main_path;
+       PublicInbox::Emergency->new($maildir)->prepare(\$msg);
+       $config->{'publicinboxwatch.spamcheck'} = 'spamc';
+       @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master));
+       PublicInbox::WatchMaildir->new($config)->scan;
+       @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master));
+       is(scalar @list, 1, 'tree has one file after spamc checked');
+
+       # XXX: workaround some weird caching/memoization in cat-file,
+       # shouldn't be an issue in real-world use, though...
+       $git = PublicInbox::Git->new($git_dir);
+
+       my $mref = $git->cat_file('refs/heads/master:'.$list[0]);
+       like($$mref, qr/something\n\z/s, 'message scrubbed on import');
+}
+
 done_testing;