1 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
8 require_mods(qw(DBD::SQLite));
9 require PublicInbox::SearchIdx;
10 my $delay = $ENV{TEST_DELAY_CONVERT} // '';
12 my $addr = 'test@example.com';
13 my $bad = PublicInbox::Eml->new(<<EOF);
14 Message-ID: <a\@example.com>
15 Message-ID: <b\@example.com>
22 my $good = PublicInbox::Eml->new(<<EOF);
23 Message-ID: <b\@example.com>
31 for my $order ([$bad, $good], [$good, $bad]) {
32 my ($tmpdir, $for_destroy) = tmpdir();
33 my $ibx = create_inbox "test$delay.$nr", indexlevel => 'basic', sub {
35 for my $eml (@$order) {
36 $im->add($eml) or BAIL_OUT;
37 sleep($delay) if $delay;
41 my $before = [ $ibx->mm->minmax ];
42 my @old = ($ibx->over->get_art(1), $ibx->over->get_art(2));
44 my $rdr = { 1 => \(my $out = ''), 2 => \(my $err = '') };
45 my $cmd = [ '-convert', $ibx->{inboxdir}, "$tmpdir/v2" ];
46 my $env = { PI_DIR => "$tmpdir/.public-inbox" };
47 ok(run_script($cmd, $env, $rdr), 'convert to v2');
48 $err =~ s!\AW: \Q$ibx->{inboxdir}\E not configured[^\n]+\n!!s;
49 is($err, '', 'no errors or warnings from -convert');
51 $ibx->{inboxdir} = "$tmpdir/v2";
52 is_deeply([$ibx->mm->minmax], $before,
53 'min, max article numbers unchanged');
55 my @v2 = ($ibx->over->get_art(1), $ibx->over->get_art(2));
56 is_deeply(\@v2, \@old, 'v2 conversion times match');
58 xsys(qw(git clone -sq --mirror), "$tmpdir/v2/git/0.git",
59 "$tmpdir/v2-clone/git/0.git") == 0 or die "clone: $?";
60 $cmd = [ '-init', '-Lbasic', '-V2', 'v2c', "$tmpdir/v2-clone",
61 'http://example.com/v2c', 'v2c@example.com' ];
62 ok(run_script($cmd, $env), 'init clone');
63 $cmd = [ qw(-index -j0), "$tmpdir/v2-clone" ];
64 sleep($delay) if $delay;
65 ok(run_script($cmd, $env), 'index the clone');
67 $ibx->{inboxdir} = "$tmpdir/v2-clone";
68 my @v2c = ($ibx->over->get_art(1), $ibx->over->get_art(2));
69 is_deeply(\@v2c, \@old, 'v2 clone times match');