-# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use warnings;
use Test::More;
-use PublicInbox::MIME;
+use PublicInbox::Eml;
use PublicInbox::InboxWritable;
-require './t/common.perl';
+use PublicInbox::TestCommon;
+use Cwd qw(abs_path);
require_git(2.6); # replace is v2 only, for now...
-foreach my $mod (qw(DBD::SQLite)) {
- eval "require $mod";
- plan skip_all => "$mod missing for $0" if $@;
-}
+require_mods(qw(DBD::SQLite));
+local $ENV{HOME} = abs_path('t');
sub test_replace ($$$) {
my ($v, $level, $opt) = @_;
inboxdir => "$tmpdir/testbox",
name => $this,
version => $v,
+ -no_fsync => 1,
-primary_address => 'test@example.com',
indexlevel => $level,
});
- my $orig = PublicInbox::MIME->new(<<'EOF');
+ my $orig = PublicInbox::Eml->new(<<'EOF');
From: Barbra Streisand <effect@example.com>
To: test@example.com
Subject: confidential
Top secret info about my house in Malibu...
EOF
- my $im = PublicInbox::InboxWritable->new($ibx, {nproc=>1})->importer;
+ my $im = PublicInbox::InboxWritable->new($ibx, {nproc=>1})->importer(0);
# fake a bunch of epochs
$im->{rotate_bytes} = $opt->{rotate_bytes} if $opt->{rotate_bytes};
my $thread_a = $ibx->over->get_thread('replace@example.com');
my %before = map {; delete($_->{blob}) => $_ } @{$ibx->recent};
- my $reject = PublicInbox::MIME->new($orig->as_string);
+ my $reject = PublicInbox::Eml->new($orig->as_string);
foreach my $mid (['<replace@example.com>', '<extra@example.com>'],
[], ['<replaced@example.com>']) {
$reject->header_set('Message-ID', @$mid);
# prepare the replacement
my $expect = "Move along, nothing to see here\n";
- my $repl = PublicInbox::MIME->new($orig->as_string);
+ my $repl = PublicInbox::Eml->new($orig->as_string);
$repl->header_set('From', '<redactor@example.com>');
$repl->header_set('Subject', 'redacted');
$repl->header_set('Date', 'Sat, 02 Oct 2010 00:00:00 +0000');
for my $tip (@$cmts) {
next if !defined $tip;
$changed_epochs++;
- like($tip, qr/\A[a-f0-9]{40}\z/,
+ like($tip, qr/\A[a-f0-9]{40,}\z/,
'replace returned current commit');
}
is($changed_epochs, 1, 'only one epoch changed');
$im->done;
- my $m = PublicInbox::MIME->new($ibx->msg_by_mid('replace@example.com'));
+ my $m = PublicInbox::Eml->new($ibx->msg_by_mid('replace@example.com'));
is($m->body, $expect, 'replaced message');
is_deeply(\@warn, [], 'no warnings on noop');
for my $dir (glob("$ibx->{inboxdir}/git/*.git")) {
my ($bn) = ($dir =~ m!([^/]+)\z!);
- is(system(qw(git --git-dir), $dir, qw(fsck --strict)), 0,
- "git fsck is clean in epoch $bn");
+ is(xsys(qw(git --git-dir), $dir,
+ qw(fsck --strict --no-progress)),
+ 0, "git fsck is clean in epoch $bn");
}
my $thread_b = $ibx->over->get_thread('replace@example.com');
if (my $srch = $ibx->search) {
for my $q ('f:streisand', 's:confidential', 'malibu') {
- my $msgs = $srch->query($q);
- is_deeply($msgs, [], "no match for $q");
+ my $mset = $srch->mset($q);
+ is($mset->size, 0, "no match for $q");
}
my @ok = ('f:redactor', 's:redacted', 'nothing to see');
if ($opt->{pre}) {
's:message3', 's:message4';
}
for my $q (@ok) {
- my $msgs = $srch->query($q);
- ok($msgs->[0], "got match for $q");
+ my $mset = $srch->mset($q);
+ ok($mset->size, "got match for $q");
}
}
is($smsg->{subject}, 'redacted', 'after subject');
is($smsg->{mid}, 'replace@example.com', 'before MID');
}
+ # $git->cleanup; # needed if $im->{parallel};
@warn = ();
is($im->replace($orig, $repl), undef, 'no-op replace returns undef');
is($im->purge($orig), undef, 'no-op purge returns undef');
is_deeply(\@warn, [], 'no warnings on noop');
+ # $im->done; # needed if $im->{parallel}
}
sub pad_msgs {
($i, $irt) = each %$i;
}
my $sec = sprintf('%0d', $i);
- my $mime = PublicInbox::MIME->new(<<EOF);
+ my $mime = PublicInbox::Eml->new(<<EOF);
From: foo\@example.com
To: test\@example.com
Message-ID: <$i\@example.com>
}
}
-my $opt = { pre => *pad_msgs };
+my $opt = { pre => \&pad_msgs };
test_replace(2, 'basic', {});
test_replace(2, 'basic', $opt);
-test_replace(2, 'basic', $opt = { %$opt, post => *pad_msgs });
+test_replace(2, 'basic', $opt = { %$opt, post => \&pad_msgs });
test_replace(2, 'basic', $opt = { %$opt, rotate_bytes => 1 });
SKIP: {
- require PublicInbox::Search;
- PublicInbox::Search::load_xapian() or skip 'Search::Xapian missing', 8;
+ require_mods(qw(Search::Xapian), 8);
for my $l (qw(medium)) {
test_replace(2, $l, {});
- $opt = { pre => *pad_msgs };
+ $opt = { pre => \&pad_msgs };
test_replace(2, $l, $opt);
- test_replace(2, $l, $opt = { %$opt, post => *pad_msgs });
+ test_replace(2, $l, $opt = { %$opt, post => \&pad_msgs });
test_replace(2, $l, $opt = { %$opt, rotate_bytes => 1 });
}
};