]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/altid.t
cleanup: use '$ibx' consistently when referring to Inbox refs
[public-inbox.git] / t / altid.t
index 7759bd6bc0aea14e5e164fc2e9ff0ac70e910a13..13a44a3b53221dcb1baacb63bd07dc0be69a823b 100644 (file)
--- a/t/altid.t
+++ b/t/altid.t
@@ -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');
 }
 
 {
@@ -40,22 +42,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);
+       my $ibx = PublicInbox::Inbox->new({mainrepo => $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 $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;