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;
7 require_mods(qw(DBD::SQLite Search::Xapian));
8 use_ok 'PublicInbox::Msgmap';
9 use_ok 'PublicInbox::SearchIdx';
10 use_ok 'PublicInbox::Import';
11 use_ok 'PublicInbox::Inbox';
12 my ($tmpdir, $for_destroy) = tmpdir();
13 my $git_dir = "$tmpdir/a.git";
14 my $alt_file = "$tmpdir/another-nntp.sqlite3";
15 my $altid = [ "serial:gmane:file=$alt_file" ];
19 my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
20 is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
21 ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
22 ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
26 is(system(qw(git init -q --bare), $git_dir), 0, 'git init ok');
27 my $git = PublicInbox::Git->new($git_dir);
28 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
29 $im->add(Email::MIME->create(
31 From => 'a@example.com',
32 To => 'b@example.com',
33 'Content-Type' => 'text/plain',
35 'Message-ID' => '<a@example.com>',
37 body => "hello world gmane:666\n",
42 $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
43 $ibx->{altid} = $altid;
44 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
49 my $ro = PublicInbox::Search->new($ibx);
50 my $msgs = $ro->query("gmane:1234");
51 is_deeply([map { $_->mid } @$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');