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 $faildir = "$tmpdir/fail.git";
18 my $main_bin = getcwd()."/t/main-bin";
19 my $main_path = "$main_bin:$ENV{PATH}"; # for spamc ham mock
20 my $fail_bin = getcwd()."/t/fail-bin";
21 my $fail_path = "$fail_bin:$ENV{PATH}"; # for spamc spam mock
22 my $addr = 'test-public@example.com';
23 my $cfgpfx = "publicinbox.test";
26 ok(-x "$main_bin/spamc",
27 "spamc ham mock found (run in top of source tree");
28 ok(-x "$fail_bin/spamc",
29 "spamc mock found (run in top of source tree");
30 ok(-x $mda, "$mda is executable");
31 is(1, mkdir($home, 0755), "setup ~/ for testing");
32 is(1, mkdir($pi_home, 0755), "setup ~/.public-inbox");
33 is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
34 is(0, system(qw(git init -q --bare), $faildir), "git init (fail)");
37 "$cfgpfx.address" => $addr,
38 "$cfgpfx.mainrepo" => $maindir,
39 "$cfgpfx.failrepo" => $faildir,
41 while (my ($k,$v) = each %cfg) {
42 is(0, system(qw(git config --file), $pi_config, $k, $v),
48 my $failbox = "$home/fail.mbox";
49 local $ENV{PI_FAILBOX} = $failbox;
50 local $ENV{HOME} = $home;
51 local $ENV{RECIPIENT} = $addr;
52 my $simple = Email::Simple->new(<<EOF);
53 From: Me <me\@example.com>
54 To: You <you\@example.com>
56 Message-Id: <blah\@example.com>
58 Date: Thu, 01 Jan 1970 00:00:00 +0000
61 my $in = $simple->as_string;
63 # ensure successful message delivery
65 local $ENV{PATH} = $main_path;
67 local $ENV{GIT_DIR} = $maindir;
68 my $rev = `git rev-list HEAD`;
69 like($rev, qr/\A[a-f0-9]{40}/, "good revision committed");
72 # ensure failures work
74 local $ENV{PATH} = $fail_path;
76 local $ENV{GIT_DIR} = $faildir;
77 my $rev = `git rev-list HEAD`;
78 like($rev, qr/\A[a-f0-9]{40}/, "bad revision committed");
80 ok(!-e $failbox, "nothing in PI_FAILBOX");