about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-04-26 08:30:52 +0000
committerEric Wong <e@80x24.org>2021-04-26 07:40:44 -0400
commit3f88776b8caeb7f58a99f065ba6650aed03c11ca (patch)
treebb07d5ccb352aa622ea93668400d3e1a53f27d30 /t
parent60196eedef969743a76f915825b741b69ed1c171 (diff)
downloadpublic-inbox-3f88776b8caeb7f58a99f065ba6650aed03c11ca.tar.gz
This gives "lei import", "lei tag", and similar commands
the ability to use URLs recognized by our PSGI frontend
directly.

This is more convenient than an equivalent shell pipeline
since "set -o pipefail" is not portable and errors may be
lost.
Diffstat (limited to 't')
-rw-r--r--t/lei-import-http.t43
1 files changed, 43 insertions, 0 deletions
diff --git a/t/lei-import-http.t b/t/lei-import-http.t
new file mode 100644
index 00000000..35cbf369
--- /dev/null
+++ b/t/lei-import-http.t
@@ -0,0 +1,43 @@
+#!perl -w
+# Copyright (C) 2021 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 PublicInbox::Spawn qw(which);
+require_mods(qw(lei -httpd));
+which('curl') or plan skip_all => "curl required for $0";
+my ($ro_home, $cfg_path) = setup_public_inboxes;
+my ($tmpdir, $for_destroy) = tmpdir;
+my $sock = tcp_server;
+my $cmd = [ '-httpd', '-W0', "--stdout=$tmpdir/1", "--stderr=$tmpdir/2" ];
+my $env = { PI_CONFIG => $cfg_path };
+my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-httpd $?");
+my $host_port = tcp_host_port($sock);
+undef $sock;
+test_lei({ tmpdir => $tmpdir }, sub {
+        my $url = "http://$host_port/t2";
+        for my $p (qw(bogus@x/t.mbox.gz bogus@x/raw ?q=noresultever)) {
+                ok(!lei('import', "$url/$p"), "/$p fails properly");
+        }
+        for my $p (qw(/ /T/ /t/ /t.atom)) {
+                ok(!lei('import', "$url/m\@example$p"), "/$p fails");
+                like($lei_err, qr/did you mean/, "gave hint for $p");
+        }
+        lei_ok 'import', "$url/testmessage\@example.com/raw";
+        lei_ok 'q', 'm:testmessage@example.com';
+        my $res = json_utf8->decode($lei_out);
+        is($res->[0]->{'m'}, 'testmessage@example.com', 'imported raw')
+                or diag explain($res);
+
+        lei_ok 'import', "$url/qp\@example.com/t.mbox.gz";
+        lei_ok 'q', 'm:qp@example.com';
+        $res = json_utf8->decode($lei_out);
+        is($res->[0]->{'m'}, 'qp@example.com', 'imported t.mbox.gz')
+                or diag explain($res);
+
+        lei_ok 'import', "$url/?q=s:boolean";
+        lei_ok 'q', 'm:20180720072141.GA15957@example';
+        $res = json_utf8->decode($lei_out);
+        is($res->[0]->{'m'}, '20180720072141.GA15957@example',
+                        'imported search result') or diag explain($res);
+});
+done_testing;