]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/replace.t
search: replace ->query with ->mset
[public-inbox.git] / t / replace.t
index 2efa25f1457e685c7557477331694c88254cedb1..a1e2d63b6f8932aad5643473d833a787ff93f965 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 use Test::More;
-use PublicInbox::MIME;
+use PublicInbox::Eml;
 use PublicInbox::InboxWritable;
 use PublicInbox::TestCommon;
 use Cwd qw(abs_path);
@@ -24,7 +24,7 @@ sub test_replace ($$$) {
                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
@@ -33,7 +33,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 
 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};
 
@@ -49,7 +49,7 @@ EOF
        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);
@@ -61,7 +61,7 @@ EOF
 
        # 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');
@@ -80,7 +80,7 @@ EOF
        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');
 
@@ -106,8 +106,8 @@ EOF
 
        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}) {
@@ -119,8 +119,8 @@ EOF
                                '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");
                }
        }
 
@@ -145,10 +145,12 @@ EOF
                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 {
@@ -159,7 +161,7 @@ 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>