]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/search.t
search: move permissions handling to InboxWritable
[public-inbox.git] / t / search.t
index cce3b9e28417fc5d470055c7a6e813a231031ff7..9ab15f77d17f1b1b72eaeae8c4060a334ccf3d2c 100644 (file)
@@ -1,5 +1,5 @@
-# Copyright (C) 2015 all contributors <meta@public-inbox.org>
-# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+# Copyright (C) 2015-2018 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;
@@ -15,26 +15,10 @@ 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 $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);
 $rw->_xdb_acquire;
 $rw->_xdb_release;
+my $ibx = $rw->{-inbox};
 $rw = undef;
 my $ro = PublicInbox::Search->new($git_dir);
 my $rw_commit = sub {
@@ -45,26 +29,25 @@ my $rw_commit = sub {
 
 {
        # git repository perms
-       is(PublicInbox::SearchIdx->_git_config_perm(undef),
-          &PublicInbox::SearchIdx::PERM_GROUP,
+       is($ibx->_git_config_perm(), &PublicInbox::InboxWritable::PERM_GROUP,
           "undefined permission is group");
-       is(PublicInbox::SearchIdx::_umask_for(
-            PublicInbox::SearchIdx->_git_config_perm('0644')),
+       is(PublicInbox::InboxWritable::_umask_for(
+            PublicInbox::InboxWritable->_git_config_perm('0644')),
           0022, "644 => umask(0022)");
-       is(PublicInbox::SearchIdx::_umask_for(
-            PublicInbox::SearchIdx->_git_config_perm('0600')),
+       is(PublicInbox::InboxWritable::_umask_for(
+            PublicInbox::InboxWritable->_git_config_perm('0600')),
           0077, "600 => umask(0077)");
-       is(PublicInbox::SearchIdx::_umask_for(
-            PublicInbox::SearchIdx->_git_config_perm('0640')),
+       is(PublicInbox::InboxWritable::_umask_for(
+            PublicInbox::InboxWritable->_git_config_perm('0640')),
           0027, "640 => umask(0027)");
-       is(PublicInbox::SearchIdx::_umask_for(
-            PublicInbox::SearchIdx->_git_config_perm('group')),
+       is(PublicInbox::InboxWritable::_umask_for(
+            PublicInbox::InboxWritable->_git_config_perm('group')),
           0007, 'group => umask(0007)');
-       is(PublicInbox::SearchIdx::_umask_for(
-            PublicInbox::SearchIdx->_git_config_perm('everybody')),
+       is(PublicInbox::InboxWritable::_umask_for(
+            PublicInbox::InboxWritable->_git_config_perm('everybody')),
           0002, 'everybody => umask(0002)');
-       is(PublicInbox::SearchIdx::_umask_for(
-            PublicInbox::SearchIdx->_git_config_perm('umask')),
+       is(PublicInbox::InboxWritable::_umask_for(
+            PublicInbox::InboxWritable->_git_config_perm('umask')),
           umask, 'umask => existing umask');
 }
 
@@ -106,22 +89,14 @@ sub filter_mids {
 {
        $rw_commit->();
        $ro->reopen;
-       my $found = $ro->lookup_message('<root@s>');
+       my $found = $ro->first_smsg_by_mid('root@s');
        ok($found, "message found");
        is($root_id, $found->{doc_id}, 'doc_id set correctly');
-       $found->ensure_metadata;
        is($found->mid, 'root@s', 'mid set correctly');
        ok(int($found->thread_id) > 0, 'thread_id is an integer');
 
+       my ($res, @res);
        my @exp = sort qw(root@s last@s);
-       my $res = $ro->query("path:hello_world");
-       my @res = filter_mids($res);
-       is_deeply(\@res, \@exp, 'got expected results for path: match');
-
-       foreach my $p (qw(hello hello_ hello_world2 hello_world_)) {
-               $res = $ro->query("path:$p");
-               is($res->{total}, 0, "path variant `$p' does not match");
-       }
 
        $res = $ro->query('s:(Hello world)');
        @res = filter_mids($res);
@@ -289,11 +264,10 @@ sub filter_mids {
                ],
                body => "LOOP!\n"));
        ok($doc_id > 0, "doc_id defined with circular reference");
-       my $smsg = $rw->lookup_message('circle@a');
-       $smsg->ensure_metadata;
+       my $smsg = $rw->first_smsg_by_mid('circle@a');
        is($smsg->references, '', "no references created");
        my $msg = PublicInbox::SearchMsg->load_doc($smsg->{doc});
-       is($s, $msg->mini_mime->header('Subject'), 'long subject not rewritten');
+       is($s, $msg->subject, 'long subject not rewritten');
 }
 
 {
@@ -307,13 +281,10 @@ sub filter_mids {
        my $mime = Email::MIME->new($str);
        my $doc_id = $rw->add_message($mime);
        ok($doc_id > 0, 'message indexed doc_id with UTF-8');
-       my $smsg = $rw->lookup_message('testmessage@example.com');
+       my $smsg = $rw->first_smsg_by_mid('testmessage@example.com');
        my $msg = PublicInbox::SearchMsg->load_doc($smsg->{doc});
 
-       # mini_mime technically not valid (I think),
-       # but good enough for displaying HTML:
-       is($mime->header('Subject'), $msg->mini_mime->header('Subject'),
-               'UTF-8 subject preserved');
+       is($mime->header('Subject'), $msg->subject, 'UTF-8 subject preserved');
 }
 
 {