]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/altid.t
public-inbox 1.1.0-pre1
[public-inbox.git] / t / altid.t
index 887d548f4b668a6c32a53e16f12acdb363767be9..d4f6152e302651e34825d2e65a6c6dde5da5eb6a 100644 (file)
--- a/t/altid.t
+++ b/t/altid.t
@@ -1,4 +1,4 @@
-# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
@@ -20,7 +20,9 @@ my $altid = [ "serial:gmane:file=$alt_file" ];
 
 {
        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');
 }
 
 {
@@ -48,14 +50,20 @@ my $altid = [ "serial:gmane:file=$alt_file" ];
 
 {
        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 $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;