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 require './t/common.perl';
8 my @mods = qw(DBI DBD::SQLite);
9 foreach my $mod (@mods) {
11 plan skip_all => "missing $mod for t/purge.t" if $@;
13 use Cwd qw(abs_path); # we need this since we chdir below
14 my $purge = abs_path('blib/script/public-inbox-purge');
15 my ($tmpdir, $for_destroy) = tmpdir();
16 use_ok 'PublicInbox::V2Writable';
17 my $inboxdir = "$tmpdir/v2";
18 my $ibx = PublicInbox::Inbox->new({
19 inboxdir => $inboxdir,
20 name => 'test-v2purge',
22 -primary_address => 'test@example.com',
23 indexlevel => 'basic',
29 Subject: this is a subject
31 Date: Fri, 02 Oct 1993 00:00:00 +0000
37 my $cfgfile = "$tmpdir/config";
38 local $ENV{PI_CONFIG} = $cfgfile;
39 open my $cfg_fh, '>', $cfgfile or die "open: $!";
41 my $v2w = PublicInbox::V2Writable->new($ibx, {nproc => 1});
42 my $mime = PublicInbox::MIME->new($raw);
43 ok($v2w->add($mime), 'add message to be purged');
46 # failing cases, first:
47 my $in = "$raw\nMOAR\n";
48 my ($out, $err) = ('', '');
49 my $opt = { 0 => \$in, 1 => \$out, 2 => \$err };
50 ok(run_script([$purge, '-f', $inboxdir], undef, $opt), 'purge -f OK');
53 ok(!run_script([$purge, $inboxdir], undef, $opt), 'mismatch fails without -f');
54 is($? >> 8, 1, 'missed purge exits with 1');
58 ok(run_script([$purge, $inboxdir], undef, $opt), 'match OK');
59 like($out, qr/\b[a-f0-9]{40,}/m, 'removed commit noted');
61 # add (old) vger filter to config file
62 print $cfg_fh <<EOF or die "print $!";
63 [publicinbox "test-v2purge"]
65 address = test\@example.com
67 filter = PublicInbox::Filter::Vger
69 close $cfg_fh or die "close: $!";
71 ok($v2w->add($mime), 'add vger-signatured message to be purged');
74 my $pre_scrub = $raw . <<'EOF';
77 To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
78 the body of a message to majordomo@vger.kernel.org
79 More majordomo info at http://vger.kernel.org/majordomo-info.html
80 Please read the FAQ at http://www.tux.org/lkml/
84 ok(chdir('/'), "chdir / OK for --all test");
85 $opt->{0} = \$pre_scrub;
86 ok(run_script([$purge, '--all'], undef, $opt), 'scrub purge OK');
87 like($out, qr/\b[a-f0-9]{40,}/m, 'removed commit noted');
88 # diag "out: $out"; diag "err: $err";
91 ok(!run_script([$purge, '--all' ], undef, $opt),
92 'scrub purge not idempotent without -f');
93 # diag "out: $out"; diag "err: $err";