]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/over.t
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / t / over.t
index 1d3f9b37ac2b5acc6c91c5207f40725a2717f6e9..5586aa310e6b2318946e25b0c4823e19d3069781 100644 (file)
--- a/t/over.t
+++ b/t/over.t
@@ -1,16 +1,13 @@
-# 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/;
-foreach my $mod (qw(DBD::SQLite)) {
-       eval "require $mod";
-       plan skip_all => "$mod missing for over.t" if $@;
-}
-
+use Compress::Zlib qw(compress);
+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;
 my $x = $over->next_tid;
@@ -21,10 +18,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');
@@ -35,4 +37,28 @@ is(int($x), $x, 'integer tid for ghost');
 $y = $over->create_ghost('NEVAR');
 is($y, $x + 1, 'integer tid for ghost increases');
 
+my $ddd = compress('');
+foreach my $s ('', undef) {
+       $over->add_over([0, 0, 98, [ 'a' ], [], $s, $ddd]);
+       $over->add_over([0, 0, 99, [ 'b' ], [], $s, $ddd]);
+       my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
+       is_deeply([98], $msgs,
+               'messages not linked by empty subject');
+}
+
+$over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
+$over->add_over([0, 0, 99, [ 'b' ], [], 's', $ddd]);
+foreach my $mid (qw(a b)) {
+       my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
+       is_deeply([98, 99], $msgs, 'linked messages by subject');
+}
+$over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
+$over->add_over([0, 0, 99, [ 'b' ], ['a'], 'diff', $ddd]);
+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>");
+}
+
+$over->rollback_lazy;
+
 done_testing();