1 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
7 use File::Temp qw/tempdir/;
11 my $mda = "blib/script/public-inbox-mda";
12 my $tmpdir = tempdir(CLEANUP => 1);
13 my $home = "$tmpdir/pi-home";
14 my $pi_home = "$home/.public-inbox";
15 my $pi_config = "$pi_home/config";
16 my $maindir = "$tmpdir/main.git";
17 my $main_bin = getcwd()."/t/main-bin";
18 my $main_path = "$main_bin:$ENV{PATH}"; # for spamc ham mock
19 my $fail_bin = getcwd()."/t/fail-bin";
20 my $fail_path = "$fail_bin:$ENV{PATH}"; # for spamc spam mock
21 my $addr = 'test-public@example.com';
22 my $cfgpfx = "publicinbox.test";
25 ok(-x "$main_bin/spamc",
26 "spamc ham mock found (run in top of source tree");
27 ok(-x "$fail_bin/spamc",
28 "spamc mock found (run in top of source tree");
29 ok(-x $mda, "$mda is executable");
30 is(1, mkdir($home, 0755), "setup ~/ for testing");
31 is(1, mkdir($pi_home, 0755), "setup ~/.public-inbox");
32 is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
35 "$cfgpfx.address" => $addr,
36 "$cfgpfx.mainrepo" => $maindir,
38 while (my ($k,$v) = each %cfg) {
39 is(0, system(qw(git config --file), $pi_config, $k, $v),
45 my $failbox = "$home/fail.mbox";
46 local $ENV{PI_FAILBOX} = $failbox;
47 local $ENV{HOME} = $home;
48 local $ENV{RECIPIENT} = $addr;
49 my $simple = Email::Simple->new(<<EOF);
50 From: Me <me\@example.com>
51 To: You <you\@example.com>
53 Message-Id: <blah\@example.com>
55 Date: Thu, 01 Jan 1970 00:00:00 +0000
58 my $in = $simple->as_string;
60 # ensure successful message delivery
62 local $ENV{PATH} = $main_path;
64 local $ENV{GIT_DIR} = $maindir;
65 my $rev = `git rev-list HEAD`;
66 like($rev, qr/\A[a-f0-9]{40}/, "good revision committed");
69 # ensure failures work
71 ok(!-e $failbox, "nothing in PI_FAILBOX before");
72 local $ENV{PATH} = $fail_path;
74 local $ENV{GIT_DIR} = $maindir;
75 my @revs = `git rev-list HEAD`;
76 is(scalar @revs, 1, "bad revision not committed");
77 ok(-s $failbox > 0, "PI_FAILBOX is written to");