X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fv2mda.t;h=8f2f335d96b8d834cfe5ffd38df13dfc6599595a;hb=d07ba9c30800225052d17ccca458afbfa05a8ff0;hp=4b1249ea14f0bc00e45fc78e273637a11e7e7ef3;hpb=3c313f9034aac96182e2efdc2f92c40803626f32;p=public-inbox.git
diff --git a/t/v2mda.t b/t/v2mda.t
index 4b1249ea..8f2f335d 100644
--- a/t/v2mda.t
+++ b/t/v2mda.t
@@ -1,19 +1,17 @@
-# Copyright (C) 2018-2019 all contributors
+#!perl -w
+# Copyright (C) all contributors
# License: AGPL-3.0+
+use v5.10.1;
use strict;
-use warnings;
use Test::More;
-use PublicInbox::MIME;
use Fcntl qw(SEEK_SET);
use Cwd;
use PublicInbox::TestCommon;
+use PublicInbox::Eml;
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 $@;
-}
+require_mods(qw(DBD::SQLite Search::Xapian));
use_ok 'PublicInbox::V2Writable';
my ($tmpdir, $for_destroy) = tmpdir();
my $ibx = {
@@ -21,18 +19,16 @@ my $ibx = {
name => 'test-v2writable',
address => [ 'test@example.com' ],
};
-my $mime = PublicInbox::MIME->create(
- header => [
- From => 'a@example.com',
- To => 'test@example.com',
- Subject => 'this is a subject',
- Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
- 'Message-ID' => '',
- 'List-ID' => '',
- ],
- body => "hello world\n",
-);
+my $mime = PublicInbox::Eml->new(<<'EOF');
+From: a@example.com
+To: test@example.com
+Subject: this is a subject
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+Message-ID:
+List-ID:
+hello world
+EOF
my $main_bin = getcwd()."/t/main-bin";
my $fail_bin = getcwd()."/t/fail-bin";
local $ENV{PI_DIR} = "$tmpdir/foo";
@@ -51,14 +47,10 @@ local $ENV{ORIGINAL_RECIPIENT} = 'test@example.com';
ok(run_script(['-mda'], undef, $rdr), 'mda delivered a message');
$ibx = PublicInbox::Inbox->new($ibx);
-
-if ($V == 1) {
- ok(run_script([ '-index', "$tmpdir/inbox" ]), 'v1 indexed');
-}
-my $msgs = $ibx->search->query('');
+my $msgs = $ibx->over->recent;
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 $eml = $ibx->smsg_eml($msgs->[0]);
+is($eml->as_string, $mime->as_string, 'injected message');
{
my @new = glob("$faildir/new/*");
@@ -69,19 +61,19 @@ is($saved->{mime}->as_string, $mime->as_string, 'injected message');
ok(run_script(['-mda'], 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('');
+ $msgs = $ibx->over->recent;
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,
+ is(xsys('git', 'config', "--file=$config", $k, 'none'), 0,
'disabled spamcheck for mda');
ok(run_script(['-mda'], 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('');
+ $msgs = $ibx->over->recent;
is(scalar(@$msgs), 2, 'new message added OK');
}
@@ -90,11 +82,18 @@ is($saved->{mime}->as_string, $mime->as_string, 'injected message');
open my $fh, '<', $patch or die "failed to open $patch: $!\n";
$rdr->{0} = \(do { local $/; <$fh> });
ok(run_script(['-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');
+ my $post = $ibx->search->reopen->mset('dfpost:6e006fd7');
+ is($post->size, 1, 'got one result for dfpost');
+ my $pre = $ibx->search->mset('dfpre:090d998');
+ is($pre->size, 1, 'got one result for dfpre');
+ $pre = $ibx->search->mset_to_smsg($ibx, $pre);
+ $post = $ibx->search->mset_to_smsg($ibx, $post);
is($post->[0]->{blob}, $pre->[0]->{blob}, 'same message in both cases');
+
+ # git patch-id --stable search->mset("patchid:$patchid");
+ is($mset->size, 1, 'patchid search works');
}
done_testing();