X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Faltid.t;h=6c34cdd65bbddcdd7b22722159c00541be2419b1;hb=6ebcec3add4d6aeff6e3b3eb019a404528c079ec;hp=7759bd6bc0aea14e5e164fc2e9ff0ac70e910a13;hpb=3d41aa23f35501ca92aab8aa42980fa73f7fa74f;p=public-inbox.git
diff --git a/t/altid.t b/t/altid.t
index 7759bd6b..6c34cdd6 100644
--- a/t/altid.t
+++ b/t/altid.t
@@ -1,26 +1,25 @@
-# Copyright (C) 2016-2018 all contributors
+# Copyright (C) 2016-2020 all contributors
# License: AGPL-3.0+
use strict;
use warnings;
use Test::More;
-use File::Temp qw/tempdir/;
-foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
- eval "require $mod";
- plan skip_all => "$mod missing for altid.t" if $@;
-}
-
+use PublicInbox::TestCommon;
+require_mods(qw(DBD::SQLite Search::Xapian));
use_ok 'PublicInbox::Msgmap';
use_ok 'PublicInbox::SearchIdx';
use_ok 'PublicInbox::Import';
use_ok 'PublicInbox::Inbox';
-my $tmpdir = tempdir('pi-altid-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my ($tmpdir, $for_destroy) = tmpdir();
my $git_dir = "$tmpdir/a.git";
my $alt_file = "$tmpdir/another-nntp.sqlite3";
my $altid = [ "serial:gmane:file=$alt_file" ];
+my $ibx;
{
my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
- $mm->mid_set(1234, 'a@example.com');
+ is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
+ ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
+ ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
}
{
@@ -40,22 +39,28 @@ my $altid = [ "serial:gmane:file=$alt_file" ];
$im->done;
}
{
- my $inbox = PublicInbox::Inbox->new({mainrepo=>$git_dir});
- $inbox->{altid} = $altid;
- my $rw = PublicInbox::SearchIdx->new($inbox, 1);
+ $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
+ $ibx->{altid} = $altid;
+ my $rw = PublicInbox::SearchIdx->new($ibx, 1);
$rw->index_sync;
}
{
- my $ro = PublicInbox::Search->new($git_dir, $altid);
- my $res = $ro->query("gmane:1234");
- is($res->{total}, 1, 'got one match');
- is($res->{msgs}->[0]->mid, 'a@example.com');
+ my $ro = PublicInbox::Search->new($ibx);
+ my $msgs = $ro->query("gmane:1234");
+ is_deeply([map { $_->mid } @$msgs], ['a@example.com'], 'got one match');
- $res = $ro->query("gmane:666");
- is($res->{total}, 0, 'body did NOT match');
+ $msgs = $ro->query("gmane:666");
+ is_deeply([], $msgs, 'body did NOT match');
};
+{
+ my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
+ my ($min, $max) = $mm->minmax;
+ my $num = $mm->mid_insert('b@example.com');
+ ok($num > $max, 'auto-increment goes beyond mid_set');
+}
+
done_testing();
1;