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>
6 use PublicInbox::TestCommon;
8 require_mods(qw(DBD::SQLite Search::Xapian));
9 use_ok 'PublicInbox::Msgmap';
10 use_ok 'PublicInbox::SearchIdx';
11 my ($tmpdir, $for_destroy) = tmpdir();
12 my $git_dir = "$tmpdir/a.git";
13 my $alt_file = "$tmpdir/another-nntp.sqlite3";
14 my $altid = [ "serial:gmane:file=$alt_file" ];
18 my $mm = PublicInbox::Msgmap->new_file($alt_file, 2);
19 is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
20 ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
21 ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
25 $ibx = create_inbox 'testbox', tmpdir => $git_dir, sub {
27 $im->add(PublicInbox::Eml->new(<<'EOF'));
31 Message-ID: <a@example.com>
36 $ibx->{altid} = $altid;
37 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
41 my $mset = $ibx->search->mset("gmane:1234");
42 my $msgs = $ibx->search->mset_to_smsg($ibx, $mset);
43 $msgs = [ map { $_->{mid} } @$msgs ];
44 is_deeply($msgs, ['a@example.com'], 'got one match');
46 $mset = $ibx->search->mset('gmane:666');
47 is($mset->size, 0, 'body did NOT match');
51 my $mm = PublicInbox::Msgmap->new_file($alt_file, 2);
52 my ($min, $max) = $mm->minmax;
53 my $num = $mm->mid_insert('b@example.com');
54 ok($num > $max, 'auto-increment goes beyond mid_set');