1 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use File::Temp qw/tempdir/;
7 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
9 plan skip_all => "$mod missing for altid.t" if $@;
12 use_ok 'PublicInbox::Msgmap';
13 use_ok 'PublicInbox::SearchIdx';
14 use_ok 'PublicInbox::Import';
15 use_ok 'PublicInbox::Inbox';
16 my $tmpdir = tempdir('pi-altid-XXXXXX', TMPDIR => 1, CLEANUP => 1);
17 my $git_dir = "$tmpdir/a.git";
18 my $alt_file = "$tmpdir/another-nntp.sqlite3";
19 my $altid = [ "serial:gmane:file=$alt_file" ];
22 my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
23 is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
24 ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
25 ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
29 is(system(qw(git init -q --bare), $git_dir), 0, 'git init ok');
30 my $git = PublicInbox::Git->new($git_dir);
31 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
32 $im->add(Email::MIME->create(
34 From => 'a@example.com',
35 To => 'b@example.com',
36 'Content-Type' => 'text/plain',
38 'Message-ID' => '<a@example.com>',
40 body => "hello world gmane:666\n",
45 my $inbox = PublicInbox::Inbox->new({mainrepo=>$git_dir});
46 $inbox->{altid} = $altid;
47 my $rw = PublicInbox::SearchIdx->new($inbox, 1);
52 my $ro = PublicInbox::Search->new($git_dir, $altid);
53 my $res = $ro->query("gmane:1234");
54 is($res->{total}, 1, 'got one match');
55 is($res->{msgs}->[0]->mid, 'a@example.com');
57 $res = $ro->query("gmane:666");
58 is($res->{total}, 0, 'body did NOT match');
62 my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
63 my ($min, $max) = $mm->minmax;
64 my $num = $mm->mid_insert('b@example.com');
65 ok($num > $max, 'auto-increment goes beyond mid_set');