]> Sergey Matveev's repositories - public-inbox.git/blob - t/altid_v2.t
No ext_urls
[public-inbox.git] / t / altid_v2.t
1 #!perl -w
2 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use PublicInbox::TestCommon;
7 use PublicInbox::Eml;
8 require_git(2.6);
9 require_mods(qw(DBD::SQLite Search::Xapian));
10 require PublicInbox::Msgmap;
11 my $another = 'another-nntp.sqlite3';
12 my $altid = [ "serial:gmane:file=$another" ];
13 my $ibx = create_inbox 'v2', version => 2, indexlevel => 'medium',
14                         altid => $altid, sub {
15         my ($im, $ibx) = @_;
16         my $mm = PublicInbox::Msgmap->new_file("$ibx->{inboxdir}/$another", 2);
17         $mm->mid_set(1234, 'a@example.com') == 1 or BAIL_OUT 'mid_set once';
18         ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
19         ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
20         $im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
21 From: a@example.com
22 To: b@example.com
23 Subject: boo!
24 Message-ID: <a@example.com>
25
26 hello world gmane:666
27 EOF
28 };
29 my $mm = PublicInbox::Msgmap->new_file("$ibx->{inboxdir}/$another", 2);
30 ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
31 ok(0 ==  $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
32 my $mset = $ibx->search->mset('gmane:1234');
33 my $msgs = $ibx->search->mset_to_smsg($ibx, $mset);
34 $msgs = [ map { $_->{mid} } @$msgs ];
35 is_deeply($msgs, ['a@example.com'], 'got one match');
36 $mset = $ibx->search->mset('gmane:666');
37 is($mset->size, 0, 'body did NOT match');
38
39 done_testing();