]> Sergey Matveev's repositories - public-inbox.git/blob - t/altid_v2.t
run update-copyrights from gnulib for 2019
[public-inbox.git] / t / altid_v2.t
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>
3 use strict;
4 use warnings;
5 use Test::More;
6 use File::Temp qw/tempdir/;
7 require './t/common.perl';
8 require_git(2.6);
9 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
10         eval "require $mod";
11         plan skip_all => "$mod missing for altid_v2.t" if $@;
12 }
13
14 use_ok 'PublicInbox::V2Writable';
15 use_ok 'PublicInbox::Inbox';
16 my $tmpdir = tempdir('pi-altidv2-XXXXXX', TMPDIR => 1, CLEANUP => 1);
17 my $mainrepo = "$tmpdir/inbox";
18 my $full = "$tmpdir/inbox/another-nntp.sqlite3";
19 my $altid = [ 'serial:gmane:file=another-nntp.sqlite3' ];
20
21 {
22         ok(mkdir($mainrepo), 'created repo for msgmap');
23         my $mm = PublicInbox::Msgmap->new_file($full, 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');
27 }
28
29 my $ibx = {
30         mainrepo => $mainrepo,
31         name => 'test-v2writable',
32         version => 2,
33         -primary_address => 'test@example.com',
34         altid => $altid,
35 };
36 $ibx = PublicInbox::Inbox->new($ibx);
37 my $v2w = PublicInbox::V2Writable->new($ibx, 1);
38 $v2w->add(Email::MIME->create(
39                 header => [
40                         From => 'a@example.com',
41                         To => 'b@example.com',
42                         'Content-Type' => 'text/plain',
43                         Subject => 'boo!',
44                         'Message-ID' => '<a@example.com>',
45                 ],
46                 body => "hello world gmane:666\n",
47         ));
48 $v2w->done;
49
50 my $msgs = $ibx->search->reopen->query("gmane:1234");
51 is_deeply([map { $_->mid } @$msgs], ['a@example.com'], 'got one match');
52 $msgs = $ibx->search->query("gmane:666");
53 is_deeply([], $msgs, 'body did NOT match');
54
55 done_testing();
56
57 1;