]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/v1reindex.t
remove most internal Email::MIME usage
[public-inbox.git] / t / v1reindex.t
index 402ecd783ade4adf44a6ae0d62751189909eba99..13605f8bd6ce5de1915fe7bc58b1a03756377486 100644 (file)
@@ -1,38 +1,31 @@
-# Copyright (C) 2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2020 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::ContentId qw(content_digest);
-use File::Temp qw/tempdir/;
 use File::Path qw(remove_tree);
-require './t/common.perl';
+use PublicInbox::TestCommon;
+use PublicInbox::Eml;
 require_git(2.6);
-
-foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
-       eval "require $mod";
-       plan skip_all => "$mod missing for v1reindex.t" if $@;
-}
+require_mods(qw(DBD::SQLite Search::Xapian));
 use_ok 'PublicInbox::SearchIdx';
 use_ok 'PublicInbox::Import';
-my $mainrepo = tempdir('pi-v1reindex-XXXXXX', TMPDIR => 1, CLEANUP => 1);
-is(system(qw(git init -q --bare), $mainrepo), 0);
+my ($inboxdir, $for_destroy) = tmpdir();
 my $ibx_config = {
-       mainrepo => $mainrepo,
+       inboxdir => $inboxdir,
        name => 'test-v1reindex',
        -primary_address => 'test@example.com',
        indexlevel => 'full',
 };
-my $mime = PublicInbox::MIME->create(
-       header => [
-               From => 'a@example.com',
-               To => 'test@example.com',
-               Subject => 'this is a subject',
-               Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
-       ],
-       body => "hello world\n",
-);
+my $mime = PublicInbox::Eml->new(<<'EOF');
+From: a@example.com
+To: test@example.com
+Subject: this is a subject
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+
+hello world
+EOF
 my $minmax;
 my $msgmap;
 my ($mark1, $mark2, $mark3, $mark4);
@@ -40,6 +33,7 @@ my ($mark1, $mark2, $mark3, $mark4);
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
+       $im->init_bare;
        foreach my $i (1..10) {
                $mime->header_set('Message-Id', "<$i\@example.com>");
                ok($im->add($mime), "message $i added");
@@ -96,7 +90,7 @@ my ($mark1, $mark2, $mark3, $mark4);
        is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
 }
 
-my $xap = "$mainrepo/public-inbox/xapian".PublicInbox::Search::SCHEMA_VERSION();
+my $xap = "$inboxdir/public-inbox/xapian".PublicInbox::Search::SCHEMA_VERSION();
 remove_tree($xap);
 ok(!-d $xap, 'Xapian directories removed');
 {
@@ -118,7 +112,7 @@ ok(!-d $xap, 'Xapian directories removed');
        is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
 }
 
-ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
+ok(unlink "$inboxdir/public-inbox/msgmap.sqlite3", 'remove msgmap');
 remove_tree($xap);
 ok(!-d $xap, 'Xapian directories removed again');
 {
@@ -141,7 +135,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
 }
 
-ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
+ok(unlink "$inboxdir/public-inbox/msgmap.sqlite3", 'remove msgmap');
 remove_tree($xap);
 ok(!-d $xap, 'Xapian directories removed again');
 {
@@ -164,7 +158,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
 }
 
-ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
+ok(unlink "$inboxdir/public-inbox/msgmap.sqlite3", 'remove msgmap');
 remove_tree($xap);
 ok(!-d $xap, 'Xapian directories removed again');
 {
@@ -190,7 +184,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
 }
 
-ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
+ok(unlink "$inboxdir/public-inbox/msgmap.sqlite3", 'remove msgmap');
 remove_tree($xap);
 ok(!-d $xap, 'Xapian directories removed again');
 {
@@ -223,7 +217,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my @warn;
        local $SIG{__WARN__} = sub { push @warn, @_ };
        my %config = %$ibx_config;
-       $config{indexleve} = 'medium';
+       $config{indexlevel} = 'medium';
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $rw = PublicInbox::SearchIdx->new($ibx, 1);
        eval { $rw->index_sync };
@@ -239,7 +233,7 @@ ok(!-d $xap, 'Xapian directories removed again');
 }
 
 # An incremental indexing test
-ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
+ok(unlink "$inboxdir/public-inbox/msgmap.sqlite3", 'remove msgmap');
 remove_tree($xap);
 ok(!-d $xap, 'Xapian directories removed again');
 {
@@ -349,7 +343,7 @@ ok(!-d $xap, 'Xapian directories removed again');
 
 
 # Another incremental indexing test
-ok(unlink "$mainrepo/public-inbox/msgmap.sqlite3", 'remove msgmap');
+ok(unlink "$inboxdir/public-inbox/msgmap.sqlite3", 'remove msgmap');
 remove_tree($xap);
 ok(!-d $xap, 'Xapian directories removed again');
 {