about summary refs log tree commit homepage
path: root/t/lei-index.t
diff options
context:
space:
mode:
Diffstat (limited to 't/lei-index.t')
-rw-r--r--t/lei-index.t50
1 files changed, 36 insertions, 14 deletions
diff --git a/t/lei-index.t b/t/lei-index.t
index eeda5196..2b28f1be 100644
--- a/t/lei-index.t
+++ b/t/lei-index.t
@@ -1,23 +1,32 @@
 #!perl -w
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use File::Spec;
-require_mods(qw(lei -nntpd));
+require_mods(qw(lei));
 my ($ro_home, $cfg_path) = setup_public_inboxes;
 my ($tmpdir, $for_destroy) = tmpdir;
 my $env = { PI_CONFIG => $cfg_path };
+my $srv = {};
 
-my $sock = tcp_server;
-my $cmd = [ '-nntpd', '-W0', "--stdout=$tmpdir/n1", "--stderr=$tmpdir/n2" ];
-my $nntpd = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-nntpd $?");
-my $nntp_host_port = tcp_host_port($sock);
+SKIP: {
+        require_mods(qw(-nntpd Net::NNTP), 1);
+        my $rdr = { 3 => tcp_server };
+        $srv->{nntpd} = start_script(
+                [qw(-nntpd -W0), "--stdout=$tmpdir/n1", "--stderr=$tmpdir/n2"],
+                $env, $rdr) or xbail "nntpd: $?";
+        $srv->{nntp_host_port} = tcp_host_port($rdr->{3});
+}
+
+SKIP: {
+        require_mods(qw(-imapd Mail::IMAPClient), 1);
+        my $rdr = { 3 => tcp_server };
+        $srv->{imapd} = start_script(
+                [qw(-imapd -W0), "--stdout=$tmpdir/i1", "--stderr=$tmpdir/i2"],
+                $env, $rdr) or xbail("-imapd $?");
+        $srv->{imap_host_port} = tcp_host_port($rdr->{3});
+}
 
-$sock = tcp_server;
-$cmd = [ '-imapd', '-W0', "--stdout=$tmpdir/i1", "--stderr=$tmpdir/i2" ];
-my $imapd = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-imapd $?");
-my $imap_host_port = tcp_host_port($sock);
-undef $sock;
 for ('', qw(cur new)) {
         mkdir "$tmpdir/md/$_" or xbail "mkdir: $!";
         mkdir "$tmpdir/md1/$_" or xbail "mkdir: $!";
@@ -39,9 +48,10 @@ symlink(File::Spec->rel2abs('t/mda-mime.eml'), "$tmpdir/md1/cur/x:2,S") or
 test_lei({ tmpdir => $tmpdir }, sub {
         my $store_path = "$ENV{HOME}/.local/share/lei/store/";
 
-        lei_ok('index', "$tmpdir/md");
+        lei_ok qw(index +L:md), "$tmpdir/md";
         lei_ok(qw(q mid:qp@example.com));
         my $res_a = json_utf8->decode($lei_out);
+        is_deeply $res_a->[0]->{L}, [ 'md' ], 'label set on index';
         my $blob = $res_a->[0]->{'blob'};
         like($blob, qr/\A[0-9a-f]{40,}\z/, 'got blob from qp@example');
         lei_ok(qw(-C / blob), $blob);
@@ -76,9 +86,15 @@ test_lei({ tmpdir => $tmpdir }, sub {
         lei_ok qw(q m:multipart-html-sucks@11);
         is_deeply(json_utf8->decode($lei_out)->[0]->{'kw'},
                 ['seen'], 'keyword set');
+        lei_ok 'reindex';
+        lei_ok qw(q m:multipart-html-sucks@11);
+        is_deeply(json_utf8->decode($lei_out)->[0]->{'kw'},
+                ['seen'], 'keyword still set after reindex');
 
-        lei_ok('index', "nntp://$nntp_host_port/t.v2");
-        lei_ok('index', "imap://$imap_host_port/t.v2.0");
+        $srv->{nntpd} and
+                lei_ok('index', "nntp://$srv->{nntp_host_port}/t.v2");
+        $srv->{imapd} and
+                lei_ok('index', "imap://$srv->{imap_host_port}/t.v2.0");
         is_deeply([xqx($all_obj)], \@objs, 'no new objects from NNTP+IMAP');
 
         lei_ok qw(q m:multipart-html-sucks@11);
@@ -93,6 +109,12 @@ test_lei({ tmpdir => $tmpdir }, sub {
         my $t = xqx(['git', "--git-dir=$store_path/ALL.git",
                         qw(cat-file -t), $res_b->{blob}]);
         is($t, "blob\n", 'got blob');
+
+        lei_ok('reindex');
+        lei_ok qw(q m:multipart-html-sucks@11);
+        $res_a = json_utf8->decode($lei_out)->[0];
+        is_deeply($res_a->{'kw'}, ['seen'],
+                'keywords still set after reindex');
 });
 
 done_testing;