about summary refs log tree commit homepage
path: root/lib/PublicInbox/TestCommon.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-16 23:02:15 -0800
committerEric Wong <e@80x24.org>2021-03-17 19:03:12 +0000
commitbe940983157a1f8bd353cb1891f6971645c73e5d (patch)
treea101284395b2c81f9956c629f96353b8e7dd8ee7 /lib/PublicInbox/TestCommon.pm
parent0a14f0a22c7d7ce35a740df574878269c0d947f5 (diff)
downloadpublic-inbox-be940983157a1f8bd353cb1891f6971645c73e5d.tar.gz
We'll try to share a bit more configuration with
extindex entries for WWW PSGI usage.
Diffstat (limited to 'lib/PublicInbox/TestCommon.pm')
-rw-r--r--lib/PublicInbox/TestCommon.pm28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index c2d07e59..0d15514e 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -15,7 +15,8 @@ BEGIN {
         @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
                 run_script start_script key2sub xsys xsys_e xqx eml_load tick
                 have_xapian_compact json_utf8 setup_public_inboxes create_inbox
-                tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt);
+                tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
+                test_httpd);
         require Test::More;
         my @methods = grep(!/\W/, @Test::More::EXPORT);
         eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
@@ -636,6 +637,31 @@ sub create_inbox ($$;@) {
         $ibx;
 }
 
+sub test_httpd ($$;$) {
+        my ($env, $client, $skip) = @_;
+        for (qw(PI_CONFIG TMPDIR)) {
+                $env->{$_} or BAIL_OUT "$_ unset";
+        }
+        SKIP: {
+                require_mods(qw(Plack::Test::ExternalServer), $skip // 1);
+                my $sock = tcp_server() or die;
+                my ($out, $err) = map { "$env->{TMPDIR}/std$_.log" } qw(out err);
+                my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
+                my $td = start_script($cmd, $env, { 3 => $sock });
+                my ($h, $p) = tcp_host_port($sock);
+                local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
+                Plack::Test::ExternalServer::test_psgi(client => $client);
+                $td->join('TERM');
+                open my $fh, '<', $err or BAIL_OUT $!;
+                my $e = do { local $/; <$fh> };
+                if ($e =~ s/^Plack::Middleware::ReverseProxy missing,\n//gms) {
+                        $e =~ s/^URL generation for redirects .*\n//gms;
+                }
+                is($e, '', 'no errors');
+        }
+};
+
+
 package PublicInboxTestProcess;
 use strict;