X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fv2mda.t;h=ebcbd1f4dde040047601a790ca1f2bf0caae80e6;hb=3c39f9c942a6975245fda878e9b957d8d3367662;hp=f386289ad1664c19401ce4160c5f5b5060a395a4;hpb=38802cb8f2f9bf8f8c72c592bcc9407681fd8360;p=public-inbox.git diff --git a/t/v2mda.t b/t/v2mda.t index f386289a..ebcbd1f4 100644 --- a/t/v2mda.t +++ b/t/v2mda.t @@ -1,4 +1,4 @@ -# Copyright (C) 2018 all contributors +# Copyright (C) 2018-2019 all contributors # License: AGPL-3.0+ use strict; use warnings; @@ -7,7 +7,10 @@ use PublicInbox::MIME; use File::Temp qw/tempdir/; use Fcntl qw(SEEK_SET); use Cwd; +require './t/common.perl'; +require_git(2.6); +my $V = 2; foreach my $mod (qw(DBD::SQLite Search::Xapian)) { eval "require $mod"; plan skip_all => "$mod missing for v2mda.t" if $@; @@ -15,7 +18,7 @@ foreach my $mod (qw(DBD::SQLite Search::Xapian)) { use_ok 'PublicInbox::V2Writable'; my $tmpdir = tempdir('pi-v2mda-XXXXXX', TMPDIR => 1, CLEANUP => 1); my $ibx = { - mainrepo => "$tmpdir/inbox", + inboxdir => "$tmpdir/inbox", name => 'test-v2writable', address => [ 'test@example.com' ], }; @@ -34,12 +37,15 @@ my $mime = PublicInbox::MIME->create( my $mda = "blib/script/public-inbox-mda"; ok(-f "blib/script/public-inbox-mda", '-mda exists'); my $main_bin = getcwd()."/t/main-bin"; +my $fail_bin = getcwd()."/t/fail-bin"; local $ENV{PI_DIR} = "$tmpdir/foo"; +my $fail_path = "$fail_bin:blib/script:$ENV{PATH}"; local $ENV{PATH} = "$main_bin:blib/script:$ENV{PATH}"; -local $ENV{PI_EMERGENCY} = "$tmpdir/fail"; -ok(mkdir "$tmpdir/fail"); -my @cmd = (qw(public-inbox-init -V2), $ibx->{name}, - $ibx->{mainrepo}, 'http://localhost/test', +my $faildir = "$tmpdir/fail"; +local $ENV{PI_EMERGENCY} = $faildir; +ok(mkdir $faildir); +my @cmd = (qw(public-inbox-init), "-V$V", $ibx->{name}, + $ibx->{inboxdir}, 'http://localhost/test', $ibx->{address}->[0]); ok(PublicInbox::Import::run_die(\@cmd), 'initialized v2 inbox'); @@ -54,8 +60,60 @@ ok(PublicInbox::Import::run_die(['public-inbox-mda'], undef, $rdr), 'mda delivered a message'); $ibx = PublicInbox::Inbox->new($ibx); + +if ($V == 1) { + my $cmd = [ 'public-inbox-index', "$tmpdir/inbox" ]; + ok(PublicInbox::Import::run_die($cmd, undef, $rdr), 'v1 indexed'); +} my $msgs = $ibx->search->query(''); +is(scalar(@$msgs), 1, 'only got one message'); my $saved = $ibx->smsg_mime($msgs->[0]); is($saved->{mime}->as_string, $mime->as_string, 'injected message'); +{ + my @new = glob("$faildir/new/*"); + is_deeply(\@new, [], 'nothing in faildir'); + local $ENV{PATH} = $fail_path; + $mime->header_set('Message-ID', ''); + ok($tmp->sysseek(0, SEEK_SET) && + $tmp->truncate(0) && + $tmp->print($mime->as_string) && + $tmp->flush && + $tmp->sysseek(0, SEEK_SET), + 'rewound and rewrite temporary file'); + my $cmd = ['public-inbox-mda']; + ok(PublicInbox::Import::run_die($cmd, undef, $rdr), + 'mda did not die on "spam"'); + @new = glob("$faildir/new/*"); + is(scalar(@new), 1, 'got a message in faildir'); + $msgs = $ibx->search->reopen->query(''); + is(scalar(@$msgs), 1, 'no new message'); + + my $config = "$ENV{PI_DIR}/config"; + ok(-f $config, 'config exists'); + my $k = 'publicinboxmda.spamcheck'; + is(system('git', 'config', "--file=$config", $k, 'none'), 0, + 'disabled spamcheck for mda'); + ok($tmp->sysseek(0, SEEK_SET), 'rewound input file'); + + ok(PublicInbox::Import::run_die($cmd, undef, $rdr), 'mda did not die'); + my @again = glob("$faildir/new/*"); + is_deeply(\@again, \@new, 'no new message in faildir'); + $msgs = $ibx->search->reopen->query(''); + is(scalar(@$msgs), 2, 'new message added OK'); +} + +{ + my $patch = 't/data/0001.patch'; + open my $fh, '<', $patch or die "failed to open $patch: $!\n"; + $rdr = { 0 => fileno($fh) }; + ok(PublicInbox::Import::run_die(['public-inbox-mda'], undef, $rdr), + 'mda delivered a patch'); + my $post = $ibx->search->reopen->query('dfpost:6e006fd7'); + is(scalar(@$post), 1, 'got one result for dfpost'); + my $pre = $ibx->search->query('dfpre:090d998'); + is(scalar(@$pre), 1, 'got one result for dfpre'); + is($post->[0]->{blob}, $pre->[0]->{blob}, 'same message in both cases'); +} + done_testing();