diff options
Diffstat (limited to 't')
-rw-r--r-- | t/import.t | 6 | ||||
-rw-r--r-- | t/watch_maildir.t | 34 |
2 files changed, 39 insertions, 1 deletions
@@ -30,7 +30,7 @@ is(scalar @revs, 1, 'one revision created'); $mime->header_set('Message-ID', '<b@example.com>'); $mime->header_set('Subject', 'msg2'); -like($im->add($mime), qr/\A:\d+\z/, 'added 2nd message'); +like($im->add($mime, sub { $mime }), qr/\A:\d+\z/, 'added 2nd message'); $im->done; @revs = $git->qx(qw(rev-list HEAD)); is(scalar @revs, 2, '2 revisions exist'); @@ -61,5 +61,9 @@ is($mark, 'MISMATCH', 'mark == MISMATCH on mismatch'); is($msg->header('Message-ID'), '<a@example.com>', 'Message-ID matches'); isnt($msg->header('Subject'), $mime->header('Subject'), 'subject mismatch'); +$mime->header_set('Message-Id', '<failcheck@example.com>'); +is($im->add($mime, sub { undef }), undef, 'check callback fails'); +is($im->remove($mime), undef, 'message not added, so not removed'); + $im->done; done_testing(); diff --git a/t/watch_maildir.t b/t/watch_maildir.t index be1a3128..21389638 100644 --- a/t/watch_maildir.t +++ b/t/watch_maildir.t @@ -3,6 +3,7 @@ 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) { @@ -86,4 +87,37 @@ 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'; + 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; |