]> Sergey Matveev's repositories - public-inbox.git/blob - t/multi-mid.t
31a8fd74cf29caf77708f2a3e8882fc8f0a3200a
[public-inbox.git] / t / multi-mid.t
1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use Test::More;
5 use PublicInbox::MIME;
6 use PublicInbox::TestCommon;
7 use PublicInbox::InboxWritable;
8 require_git(2.6);
9 require_mods(qw(DBD::SQLite));
10 require PublicInbox::SearchIdx;
11 my $delay = $ENV{TEST_DELAY_CONVERT};
12
13 my $addr = 'test@example.com';
14 my $bad = PublicInbox::MIME->new(<<EOF);
15 Message-ID: <a\@example.com>
16 Message-ID: <b\@example.com>
17 From: a\@example.com
18 To: $addr
19 Subject: bad
20
21 EOF
22
23 my $good = PublicInbox::MIME->new(<<EOF);
24 Message-ID: <b\@example.com>
25 From: b\@example.com
26 To: $addr
27 Subject: good
28
29 EOF
30
31 for my $order ([$bad, $good], [$good, $bad]) {
32         my $before;
33         my ($tmpdir, $for_destroy) = tmpdir();
34         my $ibx = PublicInbox::InboxWritable->new({
35                 inboxdir => "$tmpdir/v1",
36                 name => 'test-v1',
37                 indexlevel => 'basic',
38                 -primary_address => $addr,
39         }, my $creat_opt = {});
40         my @old;
41         if ('setup v1 inbox') {
42                 my $im = $ibx->importer(0);
43                 for (@$order) {
44                         ok($im->add($_), 'added '.$_->header('Subject'));
45                         sleep($delay) if $delay;
46                 }
47                 $im->done;
48                 my $s = PublicInbox::SearchIdx->new($ibx, 1);
49                 $s->index_sync;
50                 $before = [ $ibx->mm->minmax ];
51                 @old = ($ibx->over->get_art(1), $ibx->over->get_art(2));
52                 $ibx->cleanup;
53         }
54         my $rdr = { 1 => \(my $out = ''), 2 => \(my $err = '') };
55         my $cmd = [ '-convert', $ibx->{inboxdir}, "$tmpdir/v2" ];
56         my $env = { PI_DIR => "$tmpdir/.public-inbox" };
57         ok(run_script($cmd, $env, $rdr), 'convert to v2');
58         $err =~ s!\AW: $tmpdir/v1 not configured[^\n]+\n!!s;
59         is($err, '', 'no errors or warnings from -convert');
60         $ibx->{version} = 2;
61         $ibx->{inboxdir} = "$tmpdir/v2";
62         is_deeply([$ibx->mm->minmax], $before,
63                 'min, max article numbers unchanged');
64
65         my @v2 = ($ibx->over->get_art(1), $ibx->over->get_art(2));
66         is_deeply(\@v2, \@old, 'v2 conversion times match');
67
68         system(qw(git clone -sq --mirror), "$tmpdir/v2/git/0.git",
69                 "$tmpdir/v2-clone/git/0.git") == 0 or die "clone: $?";
70         $cmd = [ '-init', '-Lbasic', '-V2', 'v2c', "$tmpdir/v2-clone",
71                 'http://example.com/v2c', 'v2c@example.com' ];
72         ok(run_script($cmd, $env), 'init clone');
73         $cmd = [ '-index', "$tmpdir/v2-clone" ];
74         sleep($delay) if $delay;
75         ok(run_script($cmd, $env), 'index the clone');
76         $ibx->cleanup;
77         $ibx->{inboxdir} = "$tmpdir/v2-clone";
78         my @v2c = ($ibx->over->get_art(1), $ibx->over->get_art(2));
79         is_deeply(\@v2c, \@old, 'v2 clone times match');
80 }
81
82 done_testing();