1 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
8 require_mods(qw(DBD::SQLite));
9 use Cwd qw(abs_path); # we need this since we chdir below
10 local $ENV{HOME} = abs_path('t');
11 my $purge = abs_path('blib/script/public-inbox-purge');
12 my ($tmpdir, $for_destroy) = tmpdir();
13 use_ok 'PublicInbox::V2Writable';
14 my $inboxdir = "$tmpdir/v2";
15 my $ibx = PublicInbox::Inbox->new({
16 inboxdir => $inboxdir,
17 name => 'test-v2purge',
20 -primary_address => 'test@example.com',
21 indexlevel => 'basic',
27 Subject: this is a subject
29 Date: Fri, 02 Oct 1993 00:00:00 +0000
35 my $cfgfile = "$tmpdir/config";
36 local $ENV{PI_CONFIG} = $cfgfile;
37 open my $cfg_fh, '>', $cfgfile or die "open: $!";
39 my $v2w = PublicInbox::V2Writable->new($ibx, {nproc => 1});
40 my $mime = PublicInbox::Eml->new($raw);
41 ok($v2w->add($mime), 'add message to be purged');
44 # failing cases, first:
45 my $in = "$raw\nMOAR\n";
46 my ($out, $err) = ('', '');
47 my $opt = { 0 => \$in, 1 => \$out, 2 => \$err };
48 ok(run_script([$purge, '-f', $inboxdir], undef, $opt), 'purge -f OK');
51 ok(!run_script([$purge, $inboxdir], undef, $opt), 'mismatch fails without -f');
52 is($? >> 8, 1, 'missed purge exits with 1');
56 ok(run_script([$purge, $inboxdir], undef, $opt), 'match OK');
57 like($out, qr/\b[a-f0-9]{40,}/m, 'removed commit noted');
59 # add (old) vger filter to config file
60 print $cfg_fh <<EOF or die "print $!";
61 [publicinbox "test-v2purge"]
63 address = test\@example.com
65 filter = PublicInbox::Filter::Vger
67 close $cfg_fh or die "close: $!";
69 ok($v2w->add($mime), 'add vger-signatured message to be purged');
72 my $pre_scrub = $raw . <<'EOF';
75 To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
76 the body of a message to majordomo@vger.kernel.org
77 More majordomo info at http://vger.kernel.org/majordomo-info.html
78 Please read the FAQ at http://www.tux.org/lkml/
82 ok(chdir('/'), "chdir / OK for --all test");
83 $opt->{0} = \$pre_scrub;
84 ok(run_script([$purge, '--all'], undef, $opt), 'scrub purge OK');
85 like($out, qr/\b[a-f0-9]{40,}/m, 'removed commit noted');
86 # diag "out: $out"; diag "err: $err";
89 ok(!run_script([$purge, '--all' ], undef, $opt),
90 'scrub purge not idempotent without -f');
91 # diag "out: $out"; diag "err: $err";