]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/over.t
imap: STATUS/EXAMINE: rely on SQLite overview
[public-inbox.git] / t / over.t
index c0d9d5e54e58a475026ffed20a3d71d0ad962d76..734fdaa3604a55dd1da7df9ddb67ad48bd52c345 100644 (file)
--- a/t/over.t
+++ b/t/over.t
@@ -1,19 +1,17 @@
-# Copyright (C) 2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
 use Test::More;
-use File::Temp qw/tempdir/;
 use Compress::Zlib qw(compress);
-foreach my $mod (qw(DBD::SQLite)) {
-       eval "require $mod";
-       plan skip_all => "$mod missing for over.t" if $@;
-}
-
+use PublicInbox::TestCommon;
+require_mods('DBD::SQLite');
 use_ok 'PublicInbox::OverIdx';
-my $tmpdir = tempdir('pi-over-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my ($tmpdir, $for_destroy) = tmpdir();
 my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
 $over->connect;
+is($over->max, 0, 'max is zero on new DB (scalar context)');
+is_deeply([$over->max], [0], 'max is zero on new DB (list context)');
 my $x = $over->next_tid;
 is(int($x), $x, 'integer tid');
 my $y = $over->next_tid;
@@ -22,10 +20,15 @@ is($y, $x+1, 'tid increases');
 $x = $over->sid('hello-world');
 is(int($x), $x, 'integer sid');
 $y = $over->sid('hello-WORLD');
-is($y, $x+1, 'sid ncreases');
+is($y, $x+1, 'sid increases');
 is($over->sid('hello-world'), $x, 'idempotent');
+ok(!$over->{dbh}->{ReadOnly}, 'OverIdx is not ReadOnly');
 $over->disconnect;
 
+$over = PublicInbox::Over->new("$tmpdir/over.sqlite3");
+$over->connect;
+ok($over->{dbh}->{ReadOnly}, 'Over is ReadOnly');
+
 $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
 $over->connect;
 is($over->sid('hello-world'), $x, 'idempotent across reopen');
@@ -57,6 +60,7 @@ foreach my $mid (qw(a b)) {
        my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ];
        is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>");
 }
+isnt($over->max, 0, 'max is non-zero');
 
 $over->rollback_lazy;