X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fmsgmap.t;h=dce98f46b6f57e48a90653ceba659a3665db247d;hb=69329215485cf2ab9d8cd1fa7faf65d8ec42dc0b;hp=a34fd712ce3c7db90095f3e781af32175514a25d;hpb=a94b930f4804cd2019b69e1371753810e6e97ff8;p=public-inbox.git diff --git a/t/msgmap.t b/t/msgmap.t index a34fd712..dce98f46 100644 --- a/t/msgmap.t +++ b/t/msgmap.t @@ -1,17 +1,24 @@ -# Copyright (C) 2015 all contributors -# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) +# Copyright (C) 2015-2018 all contributors +# License: AGPL-3.0+ use strict; use warnings; use Test::More; use File::Temp qw/tempdir/; +foreach my $mod (qw(DBD::SQLite)) { + eval "require $mod"; + plan skip_all => "$mod missing for nntpd.t" if $@; +} + use_ok 'PublicInbox::Msgmap'; -my $tmpdir = tempdir(CLEANUP => 1); +my $tmpdir = tempdir('pi-msgmap-XXXXXX', TMPDIR => 1, CLEANUP => 1); my $d = PublicInbox::Msgmap->new($tmpdir, 1); my %mid2num; my %num2mid; my @mids = qw(a@b c@d e@f g@h aa@bb aa@cc); +is_deeply([$d->minmax], [undef,undef], "empty min max on new DB"); + foreach my $mid (@mids) { my $n = $d->mid_insert($mid); ok($n, "mid $mid inserted"); @@ -20,8 +27,9 @@ foreach my $mid (@mids) { } $@ = undef; -eval { $d->mid_insert('a@b') }; -ok($@, 'error raised when attempting duplicate message ID'); +my $ret = $d->mid_insert('a@b'); +is($ret, undef, 'duplicate mid_insert in undef result'); +is($d->num_for('a@b'), $mid2num{'a@b'}, 'existing number not clobbered'); foreach my $n (keys %num2mid) { is($d->mid_for($n), $num2mid{$n}, "num:$n maps correctly"); @@ -47,7 +55,18 @@ is($d->mid_delete('a@b') + 0, 0, 'delete again returns zero'); is(undef, $d->num_for('a@b'), 'num_for fails on deleted msg'); $d = undef; -# idempotent -ok(PublicInbox::Msgmap->new($tmpdir, 1), 'idempotent DB creation'); +ok($d = PublicInbox::Msgmap->new($tmpdir, 1), 'idempotent DB creation'); +my ($min, $max) = $d->minmax; +ok($min > 0, "article min OK"); +ok($max > 0 && $max < 10, "article max OK"); +ok($min < $max, "article counts OK"); + +my $orig = $d->mid_insert('spam@1'); +$d->mid_delete('spam@1'); +is($d->mid_insert('spam@2'), 1 + $orig, "last number not recycled"); + +my $tmp = $d->tmp_clone; +is_deeply([$d->minmax], [$tmp->minmax], 'Cloned temporary DB matches'); +ok($tmp->mid_delete('spam@2'), 'temporary DB is writable'); done_testing();