1 # Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 require './t/common.perl';
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, $for_destroy) = tmpdir();
17 my $git_dir = "$tmpdir/a.git";
18 my $alt_file = "$tmpdir/another-nntp.sqlite3";
19 my $altid = [ "serial:gmane:file=$alt_file" ];
23 my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
24 is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
25 ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
26 ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
30 is(system(qw(git init -q --bare), $git_dir), 0, 'git init ok');
31 my $git = PublicInbox::Git->new($git_dir);
32 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
33 $im->add(Email::MIME->create(
35 From => 'a@example.com',
36 To => 'b@example.com',
37 'Content-Type' => 'text/plain',
39 'Message-ID' => '<a@example.com>',
41 body => "hello world gmane:666\n",
46 $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
47 $ibx->{altid} = $altid;
48 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
53 my $ro = PublicInbox::Search->new($ibx);
54 my $msgs = $ro->query("gmane:1234");
55 is_deeply([map { $_->mid } @$msgs], ['a@example.com'], 'got one match');
57 $msgs = $ro->query("gmane:666");
58 is_deeply([], $msgs, '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');