]> Sergey Matveev's repositories - public-inbox.git/blob - t/mda_filter_rubylang.t
t/mda_filter_rubylang: drop IPC::Run dependency
[public-inbox.git] / t / mda_filter_rubylang.t
1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use File::Temp qw/tempdir/;
7 use PublicInbox::MIME;
8 use PublicInbox::Config;
9 require './t/common.perl';
10 require_git(2.6);
11 my @mods = qw(DBD::SQLite Search::Xapian);
12 foreach my $mod (@mods) {
13         eval "require $mod";
14         plan skip_all => "$mod missing for mda_filter_rubylang.t" if $@;
15 }
16
17 use_ok 'PublicInbox::V2Writable';
18 my $tmpdir = tempdir('mda-XXXXXX', TMPDIR => 1, CLEANUP => 1);
19 my $pi_config = "$tmpdir/pi_config";
20 local $ENV{PI_CONFIG} = $pi_config;
21 local $ENV{PI_EMERGENCY} = "$tmpdir/emergency";
22 my @cfg = ('git', 'config', "--file=$pi_config");
23 is(system(@cfg, 'publicinboxmda.spamcheck', 'none'), 0);
24
25 for my $v (qw(V1 V2)) {
26         my @warn;
27         $SIG{__WARN__} = sub { push @warn, @_ };
28         my $cfgpfx = "publicinbox.$v";
29         my $inboxdir = "$tmpdir/$v";
30         my $addr = "test-$v\@example.com";
31         my $cmd = [ '-init', "-$v", $v, $inboxdir,
32                 "http://example.com/$v", $addr ];
33         ok(run_script($cmd), 'public-inbox-init');
34         ok(run_script(['-index', $inboxdir]), 'public-inbox-index');
35         is(system(@cfg, "$cfgpfx.filter", 'PublicInbox::Filter::RubyLang'), 0);
36         is(system(@cfg, "$cfgpfx.altid",
37                 'serial:alerts:file=msgmap.sqlite3'), 0);
38
39         for my $i (1..2) {
40                 my $env = { ORIGINAL_RECIPIENT => $addr };
41                 my $opt = { 0 => \(<<EOF) };
42 From: user\@example.com
43 To: $addr
44 Subject: blah $i
45 X-Mail-Count: $i
46 Message-Id: <a.$i\@b.com>
47 Date: Sat, 05 Jan 2019 04:19:17 +0000
48
49 something
50 EOF
51                 ok(run_script(['-mda'], $env, $opt), 'message delivered');
52         }
53         my $config = PublicInbox::Config->new;
54         my $ibx = $config->lookup_name($v);
55
56         # make sure all serials are searchable:
57         my ($tot, $msgs);
58         for my $i (1..2) {
59                 ($tot, $msgs) = $ibx->search->query("alerts:$i");
60                 is($tot, 1, "got one result for alerts:$i");
61                 is($msgs->[0]->{mid}, "a.$i\@b.com", "got expected MID for $i");
62         }
63         is_deeply([], \@warn, 'no warnings');
64
65         # TODO: public-inbox-learn doesn't know about filters
66         # (but -watch does)
67 }
68
69 done_testing();