]> Sergey Matveev's repositories - public-inbox.git/blob - t/altid_v2.t
public-inbox 1.1.0-pre1
[public-inbox.git] / t / altid_v2.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_v2.t" if $@;
10 }
11
12 use_ok 'PublicInbox::V2Writable';
13 use_ok 'PublicInbox::Inbox';
14 my $tmpdir = tempdir('pi-altidv2-XXXXXX', TMPDIR => 1, CLEANUP => 1);
15 my $mainrepo = "$tmpdir/inbox";
16 my $full = "$tmpdir/inbox/another-nntp.sqlite3";
17 my $altid = [ 'serial:gmane:file=another-nntp.sqlite3' ];
18
19 {
20         ok(mkdir($mainrepo), 'created repo for msgmap');
21         my $mm = PublicInbox::Msgmap->new_file($full, 1);
22         is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
23         ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
24         ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
25 }
26
27 my $ibx = {
28         mainrepo => $mainrepo,
29         name => 'test-v2writable',
30         version => 2,
31         -primary_address => 'test@example.com',
32         altid => $altid,
33 };
34 $ibx = PublicInbox::Inbox->new($ibx);
35 my $v2w = PublicInbox::V2Writable->new($ibx, 1);
36 $v2w->add(Email::MIME->create(
37                 header => [
38                         From => 'a@example.com',
39                         To => 'b@example.com',
40                         'Content-Type' => 'text/plain',
41                         Subject => 'boo!',
42                         'Message-ID' => '<a@example.com>',
43                 ],
44                 body => "hello world gmane:666\n",
45         ));
46 $v2w->done;
47
48 my $msgs = $ibx->search->reopen->query("gmane:1234");
49 is_deeply([map { $_->mid } @$msgs], ['a@example.com'], 'got one match');
50 $msgs = $ibx->search->query("gmane:666");
51 is_deeply([], $msgs, 'body did NOT match');
52
53 done_testing();
54
55 1;