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 $mm->mid_set(1234, 'a@example.com');
27 is(system(qw(git init -q --bare), $git_dir), 0, 'git init ok');
28 my $git = PublicInbox::Git->new($git_dir);
29 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
30 $im->add(Email::MIME->create(
32 From => 'a@example.com',
33 To => 'b@example.com',
34 'Content-Type' => 'text/plain',
36 'Message-ID' => '<a@example.com>',
38 body => "hello world gmane:666\n",
43 my $inbox = PublicInbox::Inbox->new({mainrepo=>$git_dir});
44 $inbox->{altid} = $altid;
45 my $rw = PublicInbox::SearchIdx->new($inbox, 1);
50 my $ro = PublicInbox::Search->new($git_dir, $altid);
51 my $res = $ro->query("gmane:1234");
52 is($res->{total}, 1, 'got one match');
53 is($res->{msgs}->[0]->mid, 'a@example.com');
55 $res = $ro->query("gmane:666");
56 is($res->{total}, 0, 'body did NOT match');