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_v2.t" if $@;
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' ];
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');
28 mainrepo => $mainrepo,
29 name => 'test-v2writable',
31 -primary_address => 'test@example.com',
34 $ibx = PublicInbox::Inbox->new($ibx);
35 my $v2w = PublicInbox::V2Writable->new($ibx, 1);
36 $v2w->add(Email::MIME->create(
38 From => 'a@example.com',
39 To => 'b@example.com',
40 'Content-Type' => 'text/plain',
42 'Message-ID' => '<a@example.com>',
44 body => "hello world gmane:666\n",
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');