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 require './t/common.perl';
9 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
11 plan skip_all => "$mod missing for altid_v2.t" if $@;
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' ];
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');
30 mainrepo => $mainrepo,
31 name => 'test-v2writable',
33 -primary_address => 'test@example.com',
36 $ibx = PublicInbox::Inbox->new($ibx);
37 my $v2w = PublicInbox::V2Writable->new($ibx, 1);
38 $v2w->add(Email::MIME->create(
40 From => 'a@example.com',
41 To => 'b@example.com',
42 'Content-Type' => 'text/plain',
44 'Message-ID' => '<a@example.com>',
46 body => "hello world gmane:666\n",
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');