]> Sergey Matveev's repositories - public-inbox.git/blob - t/multi-mid.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / multi-mid.t
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>
3 use strict;
4 use Test::More;
5 use PublicInbox::Eml;
6 use PublicInbox::TestCommon;
7 require_git(2.6);
8 require_mods(qw(DBD::SQLite));
9 require PublicInbox::SearchIdx;
10 my $delay = $ENV{TEST_DELAY_CONVERT} // '';
11
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>
16 From: a\@example.com
17 To: $addr
18 Subject: bad
19
20 EOF
21
22 my $good = PublicInbox::Eml->new(<<EOF);
23 Message-ID: <b\@example.com>
24 From: b\@example.com
25 To: $addr
26 Subject: good
27
28 EOF
29
30 my $nr = 0;
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 {
34                 my ($im) = @_;
35                 for my $eml (@$order) {
36                         $im->add($eml) or BAIL_OUT;
37                         sleep($delay) if $delay;
38                 }
39         };
40         ++$nr;
41         my $before = [ $ibx->mm->minmax ];
42         my @old = ($ibx->over->get_art(1), $ibx->over->get_art(2));
43         $ibx->cleanup;
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');
50         $ibx->{version} = 2;
51         $ibx->{inboxdir} = "$tmpdir/v2";
52         is_deeply([$ibx->mm->minmax], $before,
53                 'min, max article numbers unchanged');
54
55         my @v2 = ($ibx->over->get_art(1), $ibx->over->get_art(2));
56         is_deeply(\@v2, \@old, 'v2 conversion times match');
57
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');
66         $ibx->cleanup;
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');
70 }
71
72 done_testing();