1 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
8 require_mods(qw(DBD::SQLite Search::Xapian));
9 use_ok 'PublicInbox::Msgmap';
10 use_ok 'PublicInbox::SearchIdx';
11 use_ok 'PublicInbox::Import';
12 use_ok 'PublicInbox::Inbox';
13 my ($tmpdir, $for_destroy) = tmpdir();
14 my $git_dir = "$tmpdir/a.git";
15 my $alt_file = "$tmpdir/another-nntp.sqlite3";
16 my $altid = [ "serial:gmane:file=$alt_file" ];
20 my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
21 is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
22 ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
23 ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
27 my $git = PublicInbox::Git->new($git_dir);
28 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
30 $im->add(PublicInbox::Eml->new(<<'EOF'));
34 Message-ID: <a@example.com>
41 $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
42 $ibx->{altid} = $altid;
43 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
48 my $ro = PublicInbox::Search->new($ibx);
49 my $msgs = $ro->query("gmane:1234");
50 $msgs = [ map { $_->{mid} } @$msgs ];
51 is_deeply($msgs, ['a@example.com'], 'got one match');
53 $msgs = $ro->query("gmane:666");
54 is_deeply([], $msgs, 'body did NOT match');
58 my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
59 my ($min, $max) = $mm->minmax;
60 my $num = $mm->mid_insert('b@example.com');
61 ok($num > $max, 'auto-increment goes beyond mid_set');