]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/search.t
update copyright headers and email addresses
[public-inbox.git] / t / search.t
index 0ad0886b7b859c2d018d7063374d6bbf65dda81c..b1c772893b4f4cfe16ff90fea460565e981fb0f1 100644 (file)
@@ -1,9 +1,9 @@
-# Copyright (C) 2015, all contributors <meta@public-inbox.org>
+# Copyright (C) 2015 all contributors <meta@public-inbox.org>
 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
 use strict;
 use warnings;
 use Test::More;
-eval { require PublicInbox::Search; };
+eval { require PublicInbox::SearchIdx; };
 plan skip_all => "Xapian missing for search" if $@;
 use File::Temp qw/tempdir/;
 use Email::MIME;
@@ -16,13 +16,55 @@ is(0, system(qw(git init -q --bare), $git_dir), "git init (main)");
 eval { PublicInbox::Search->new($git_dir) };
 ok($@, "exception raised on non-existent DB");
 
-my $rw = PublicInbox::Search->new($git_dir, 1);
+{
+       my $orig = "FOO " x 30;
+       my $summ = PublicInbox::Search::subject_summary($orig);
+
+       $summ = length($summ);
+       $orig = length($orig);
+       ok($summ < $orig && $summ > 0, "summary shortened ($orig => $summ)");
+
+       $orig = "FOO" x 30;
+       $summ = PublicInbox::Search::subject_summary($orig);
+
+       $summ = length($summ);
+       $orig = length($orig);
+       ok($summ < $orig && $summ > 0,
+          "summary shortened but not empty: $summ");
+}
+
+my $rw = PublicInbox::SearchIdx->new($git_dir, 1);
 my $ro = PublicInbox::Search->new($git_dir);
 my $rw_commit = sub {
        $rw = undef;
-       $rw = PublicInbox::Search->new($git_dir, 1);
+       $rw = PublicInbox::SearchIdx->new($git_dir, 1);
 };
 
+{
+       # git repository perms
+       is(PublicInbox::SearchIdx->_git_config_perm(undef),
+          &PublicInbox::SearchIdx::PERM_GROUP,
+          "undefined permission is group");
+       is(PublicInbox::SearchIdx::_umask_for(
+            PublicInbox::SearchIdx->_git_config_perm('0644')),
+          0022, "644 => umask(0022)");
+       is(PublicInbox::SearchIdx::_umask_for(
+            PublicInbox::SearchIdx->_git_config_perm('0600')),
+          0077, "600 => umask(0077)");
+       is(PublicInbox::SearchIdx::_umask_for(
+            PublicInbox::SearchIdx->_git_config_perm('0640')),
+          0027, "640 => umask(0027)");
+       is(PublicInbox::SearchIdx::_umask_for(
+            PublicInbox::SearchIdx->_git_config_perm('group')),
+          0007, 'group => umask(0007)');
+       is(PublicInbox::SearchIdx::_umask_for(
+            PublicInbox::SearchIdx->_git_config_perm('everybody')),
+          0002, 'everybody => umask(0002)');
+       is(PublicInbox::SearchIdx::_umask_for(
+            PublicInbox::SearchIdx->_git_config_perm('umask')),
+          umask, 'umask => existing umask');
+}
+
 {
        my $root = Email::MIME->create(
                header_str => [
@@ -73,7 +115,7 @@ sub filter_mids {
 
        foreach my $p (qw(hello hello_ hello_world2 hello_world_)) {
                $res = $ro->query("path:$p");
-               is($res->{count}, 0, "path variant `$p' does not match");
+               is($res->{total}, 0, "path variant `$p' does not match");
        }
 
        $res = $ro->query('subject:(Hello world)');
@@ -93,15 +135,6 @@ sub filter_mids {
        my $second = $res->{msgs}->[0];
 
        isnt($first, $second, "offset returned different result from limit");
-
-       foreach my $f (qw(inreplyto references)) {
-               $res = $ro->query($f . ':root@s');
-               @res = filter_mids($res);
-               is_deeply(\@res, [ 'last@s' ],
-                         "got expected results for $f: match");
-               $res = $ro->query($f . ':root');
-               is($res->{count}, 0, "no partial mid match");
-       }
 }
 
 # ghost vivication
@@ -159,7 +192,6 @@ sub filter_mids {
        $rw_commit->();
        $ro->reopen;
        my $long_mid = 'last' . ('x' x 60). '@s';
-       my $long_midc = Digest::SHA::sha1_hex($long_mid);
 
        my $long = Email::MIME->create(
                header_str => [
@@ -177,14 +209,8 @@ sub filter_mids {
 
        $rw_commit->();
        $ro->reopen;
-       my $res = $ro->query('references:root@s');
-       my @res = filter_mids($res);
-       is_deeply(\@res, [ sort('last@s', $long_midc) ],
-                 "got expected results for references: match");
-
-       my $followups = $ro->get_followups('root@s');
-       $followups = [ filter_mids($followups) ];
-       is_deeply($followups, [ filter_mids($res) ], "get_followups matches");
+       my $res;
+       my @res;
 
        my $long_reply_mid = 'reply-to-long@1';
        my $long_reply = Email::MIME->create(
@@ -204,8 +230,8 @@ sub filter_mids {
        $rw_commit->();
        $ro->reopen;
        my $t = $ro->get_thread('root@s');
-       is($t->{count}, 4, "got all 4 mesages in thread");
-       my @exp = sort($long_reply_mid, 'root@s', 'last@s', $long_midc);
+       is($t->{total}, 4, "got all 4 mesages in thread");
+       my @exp = sort($long_reply_mid, 'root@s', 'last@s', $long_mid);
        @res = filter_mids($t);
        is_deeply(\@res, \@exp, "get_thread works");
 }
@@ -233,16 +259,35 @@ sub filter_mids {
                ],
                body => "theatre\nfade\n"));
        my $res = $rw->query("theatre");
-       is($res->{count}, 2, "got both matches");
+       is($res->{total}, 2, "got both matches");
        is($res->{msgs}->[0]->mid, 'nquote@a', "non-quoted scores higher");
        is($res->{msgs}->[1]->mid, 'quote@a', "quoted result still returned");
 
        $res = $rw->query("illusions");
-       is($res->{count}, 1, "got a match for quoted text");
+       is($res->{total}, 1, "got a match for quoted text");
        is($res->{msgs}->[0]->mid, 'quote@a',
                "quoted result returned if nothing else");
 }
 
+# circular references
+{
+       my $doc_id = $rw->add_message(Email::MIME->create(
+               header_str => [
+                       Date => 'Sat, 02 Oct 2010 00:00:01 +0000',
+                       Subject => 'Circle',
+                       'Message-ID' => '<circle@a>',
+                       'References' => '<circle@a>',
+                       'In-Reply-To' => '<circle@a>',
+                       From => 'Circle <circle@example.com>',
+                       To => 'list@example.com',
+               ],
+               body => "LOOP!\n"));
+       ok($doc_id > 0, "doc_id defined with circular reference");
+       my $smsg = $rw->lookup_message('circle@a');
+       $smsg->ensure_metadata;
+       is($smsg->references_sorted, '', "no references created");
+}
+
 done_testing();
 
 1;