1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use PublicInbox::InboxWritable;
9 require_mods(qw(DBD::SQLite));
10 require PublicInbox::SearchIdx;
11 my $delay = $ENV{TEST_DELAY_CONVERT};
13 my $addr = 'test@example.com';
14 my $bad = PublicInbox::Eml->new(<<EOF);
15 Message-ID: <a\@example.com>
16 Message-ID: <b\@example.com>
23 my $good = PublicInbox::Eml->new(<<EOF);
24 Message-ID: <b\@example.com>
31 for my $order ([$bad, $good], [$good, $bad]) {
33 my ($tmpdir, $for_destroy) = tmpdir();
34 my $ibx = PublicInbox::InboxWritable->new({
35 inboxdir => "$tmpdir/v1",
37 indexlevel => 'basic',
38 -primary_address => $addr,
39 }, my $creat_opt = {});
41 if ('setup v1 inbox') {
42 my $im = $ibx->importer(0);
44 ok($im->add($_), 'added '.$_->header('Subject'));
45 sleep($delay) if $delay;
48 my $s = PublicInbox::SearchIdx->new($ibx, 1);
50 $before = [ $ibx->mm->minmax ];
51 @old = ($ibx->over->get_art(1), $ibx->over->get_art(2));
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');
61 $ibx->{inboxdir} = "$tmpdir/v2";
62 is_deeply([$ibx->mm->minmax], $before,
63 'min, max article numbers unchanged');
65 my @v2 = ($ibx->over->get_art(1), $ibx->over->get_art(2));
66 is_deeply(\@v2, \@old, 'v2 conversion times match');
68 xsys(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 = [ qw(-index -j0), "$tmpdir/v2-clone" ];
74 sleep($delay) if $delay;
75 ok(run_script($cmd, $env), 'index the clone');
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');