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