]> Sergey Matveev's repositories - public-inbox.git/blob - t/altid.t
update copyrights for 2018
[public-inbox.git] / t / altid.t
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>
3 use strict;
4 use warnings;
5 use Test::More;
6 use File::Temp qw/tempdir/;
7 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
8         eval "require $mod";
9         plan skip_all => "$mod missing for altid.t" if $@;
10 }
11
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" ];
20
21 {
22         my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
23         $mm->mid_set(1234, 'a@example.com');
24 }
25
26 {
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(
31                 header => [
32                         From => 'a@example.com',
33                         To => 'b@example.com',
34                         'Content-Type' => 'text/plain',
35                         Subject => 'boo!',
36                         'Message-ID' => '<a@example.com>',
37                 ],
38                 body => "hello world gmane:666\n",
39         ));
40         $im->done;
41 }
42 {
43         my $inbox = PublicInbox::Inbox->new({mainrepo=>$git_dir});
44         $inbox->{altid} = $altid;
45         my $rw = PublicInbox::SearchIdx->new($inbox, 1);
46         $rw->index_sync;
47 }
48
49 {
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');
54
55         $res = $ro->query("gmane:666");
56         is($res->{total}, 0, 'body did NOT match');
57 };
58
59 done_testing();
60
61 1;