1 # Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use Compress::Zlib qw(compress);
7 use PublicInbox::TestCommon;
8 require_mods('DBD::SQLite');
9 use_ok 'PublicInbox::OverIdx';
10 my ($tmpdir, $for_destroy) = tmpdir();
11 my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
13 my $x = $over->next_tid;
14 is(int($x), $x, 'integer tid');
15 my $y = $over->next_tid;
16 is($y, $x+1, 'tid increases');
18 $x = $over->sid('hello-world');
19 is(int($x), $x, 'integer sid');
20 $y = $over->sid('hello-WORLD');
21 is($y, $x+1, 'sid increases');
22 is($over->sid('hello-world'), $x, 'idempotent');
23 ok(!$over->{dbh}->{ReadOnly}, 'OverIdx is not ReadOnly');
26 $over = PublicInbox::Over->new("$tmpdir/over.sqlite3");
28 ok($over->{dbh}->{ReadOnly}, 'Over is ReadOnly');
30 $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
32 is($over->sid('hello-world'), $x, 'idempotent across reopen');
33 $over->each_by_mid('never', sub { fail('should not be called') });
35 $x = $over->create_ghost('never');
36 is(int($x), $x, 'integer tid for ghost');
37 $y = $over->create_ghost('NEVAR');
38 is($y, $x + 1, 'integer tid for ghost increases');
40 my $ddd = compress('');
41 foreach my $s ('', undef) {
42 $over->add_over([0, 0, 98, [ 'a' ], [], $s, $ddd]);
43 $over->add_over([0, 0, 99, [ 'b' ], [], $s, $ddd]);
44 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
45 is_deeply([98], $msgs,
46 'messages not linked by empty subject');
49 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
50 $over->add_over([0, 0, 99, [ 'b' ], [], 's', $ddd]);
51 foreach my $mid (qw(a b)) {
52 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
53 is_deeply([98, 99], $msgs, 'linked messages by subject');
55 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
56 $over->add_over([0, 0, 99, [ 'b' ], ['a'], 'diff', $ddd]);
57 foreach my $mid (qw(a b)) {
58 my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ];
59 is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>");