1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use File::Temp qw/tempdir/;
7 require './t/common.perl';
9 my @mods = qw(IPC::Run DBI DBD::SQLite);
10 foreach my $mod (@mods) {
12 plan skip_all => "missing $mod for t/purge.t" if $@;
15 my $purge = abs_path('blib/script/public-inbox-purge');
16 my $tmpdir = tempdir('pi-purge-XXXXXX', TMPDIR => 1, CLEANUP => 1);
17 use_ok 'PublicInbox::V2Writable';
18 my $mainrepo = "$tmpdir/v2";
19 my $ibx = PublicInbox::Inbox->new({
20 mainrepo => $mainrepo,
21 name => 'test-v2purge',
23 -primary_address => 'test@example.com',
24 indexlevel => 'basic',
30 Subject: this is a subject
32 Date: Fri, 02 Oct 1993 00:00:00 +0000
38 my $cfgfile = "$tmpdir/config";
39 local $ENV{PI_CONFIG} = $cfgfile;
40 open my $cfg_fh, '>', $cfgfile or die "open: $!";
42 my $v2w = PublicInbox::V2Writable->new($ibx, {nproc => 1});
43 my $mime = PublicInbox::MIME->new($raw);
44 ok($v2w->add($mime), 'add message to be purged');
47 # failing cases, first:
48 my $in = "$raw\nMOAR\n";
49 my ($out, $err) = ('', '');
50 ok(IPC::Run::run([$purge, '-f', $mainrepo], \$in, \$out, \$err),
54 ok(!IPC::Run::run([$purge, $mainrepo], \$in, \$out, \$err),
55 'mismatch fails without -f');
56 is($? >> 8, 1, 'missed purge exits with 1');
59 ok(IPC::Run::run([$purge, $mainrepo], \$raw, \$out, \$err), 'match OK');
60 like($out, qr/\b[a-f0-9]{40,}/m, 'removed commit noted');
62 # add (old) vger filter to config file
63 print $cfg_fh <<EOF or die "print $!";
64 [publicinbox "test-v2purge"]
66 address = test\@example.com
68 filter = PublicInbox::Filter::Vger
70 close $cfg_fh or die "close: $!";
72 ok($v2w->add($mime), 'add vger-signatured message to be purged');
75 my $pre_scrub = $raw . <<'EOF';
78 To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
79 the body of a message to majordomo@vger.kernel.org
80 More majordomo info at http://vger.kernel.org/majordomo-info.html
81 Please read the FAQ at http://www.tux.org/lkml/
85 ok(chdir('/'), "chdir / OK for --all test");
86 ok(IPC::Run::run([$purge, '--all'], \$pre_scrub, \$out, \$err),
88 like($out, qr/\b[a-f0-9]{40,}/m, 'removed commit noted');
89 # diag "out: $out"; diag "err: $err";
92 ok(!IPC::Run::run([$purge, '--all' ], \$pre_scrub, \$out, \$err),
93 'scrub purge not idempotent without -f');
94 # diag "out: $out"; diag "err: $err";