]> Sergey Matveev's repositories - public-inbox.git/blob - t/over.t
fix tests to run without Xapian installed
[public-inbox.git] / t / over.t
1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use File::Temp qw/tempdir/;
7 use Compress::Zlib qw(compress);
8 # FIXME: allow using Over w/o Xapian
9 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
10         eval "require $mod";
11         plan skip_all => "$mod missing for over.t" if $@;
12 }
13
14 use_ok 'PublicInbox::OverIdx';
15 my $tmpdir = tempdir('pi-over-XXXXXX', TMPDIR => 1, CLEANUP => 1);
16 my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
17 $over->connect;
18 my $x = $over->next_tid;
19 is(int($x), $x, 'integer tid');
20 my $y = $over->next_tid;
21 is($y, $x+1, 'tid increases');
22
23 $x = $over->sid('hello-world');
24 is(int($x), $x, 'integer sid');
25 $y = $over->sid('hello-WORLD');
26 is($y, $x+1, 'sid ncreases');
27 is($over->sid('hello-world'), $x, 'idempotent');
28 $over->disconnect;
29
30 $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
31 $over->connect;
32 is($over->sid('hello-world'), $x, 'idempotent across reopen');
33 $over->each_by_mid('never', sub { fail('should not be called') });
34
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');
39
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');
47 }
48
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');
54 }
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>");
60 }
61
62 $over->rollback_lazy;
63
64 done_testing();