X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fhttpd.t;h=f4fbd5330be2e0b874c579216eeff56ed7f7f12c;hb=e39585ee2bdcbeaab7b6bd33b3568021042d0879;hp=e7527ed64f2ae6815ccc87e2aec8bae5fb219621;hpb=5e76c9b79f8dd42c2ac989d8c67341637fe00553;p=public-inbox.git
diff --git a/t/httpd.t b/t/httpd.t
index e7527ed6..f4fbd533 100644
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -1,19 +1,15 @@
-# Copyright (C) 2016-2019 all contributors
+# Copyright (C) 2016-2020 all contributors
# License: AGPL-3.0+
use strict;
use warnings;
use Test::More;
-
-foreach my $mod (qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status)) {
- eval "require $mod";
- plan skip_all => "$mod missing for httpd.t" if $@;
-}
-use File::Temp qw/tempdir/;
+use PublicInbox::TestCommon;
+use PublicInbox::MIME;
use Socket qw(IPPROTO_TCP SOL_SOCKET);
-require './t/common.perl';
+require_mods(qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status));
# FIXME: too much setup
-my $tmpdir = tempdir('pi-httpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my ($tmpdir, $for_destroy) = tmpdir();
my $home = "$tmpdir/pi-home";
my $err = "$tmpdir/stderr.log";
my $out = "$tmpdir/stdout.log";
@@ -21,13 +17,10 @@ my $maindir = "$tmpdir/main.git";
my $group = 'test-httpd';
my $addr = $group . '@example.com';
my $cfgpfx = "publicinbox.$group";
-my $httpd = 'blib/script/public-inbox-httpd';
my $sock = tcp_server();
-my $pid;
+my $td;
use_ok 'PublicInbox::Git';
use_ok 'PublicInbox::Import';
-use_ok 'Email::MIME';
-END { kill 'TERM', $pid if defined $pid };
{
local $ENV{HOME} = $home;
my $cmd = [ '-init', $group, $maindir, 'http://example.com/', $addr ];
@@ -35,7 +28,7 @@ END { kill 'TERM', $pid if defined $pid };
# ensure successful message delivery
{
- my $mime = Email::MIME->new(<new(<
To: You
Cc: $addr
@@ -52,10 +45,15 @@ EOF
$im->done($mime);
}
ok($sock, 'sock created');
- $cmd = [ $httpd, '-W0', "--stdout=$out", "--stderr=$err" ];
- $pid = spawn_listener(undef, $cmd, [$sock]);
+ $cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err" ];
+ $td = start_script($cmd, undef, { 3 => $sock });
my $host = $sock->sockhost;
my $port = $sock->sockport;
+ {
+ my $bad = tcp_connect($sock);
+ print $bad "GETT / HTTP/1.0\r\n\r\n" or die;
+ like(<$bad>, qr!\AHTTP/1\.[01] 405\b!, 'got 405 on bad req');
+ }
my $conn = tcp_connect($sock);
ok($conn, 'connected');
ok($conn->write("GET / HTTP/1.0\r\n\r\n"), 'wrote data to socket');
@@ -66,30 +64,29 @@ EOF
is($conn->read($buf, 1), 0, "EOF");
}
- is(system(qw(git clone -q --mirror),
+ is(xsys(qw(git clone -q --mirror),
"http://$host:$port/$group", "$tmpdir/clone.git"),
0, 'smart clone successful');
# ensure dumb cloning works, too:
- is(system('git', "--git-dir=$maindir",
+ is(xsys('git', "--git-dir=$maindir",
qw(config http.uploadpack false)),
0, 'disable http.uploadpack');
- is(system(qw(git clone -q --mirror),
+ is(xsys(qw(git clone -q --mirror),
"http://$host:$port/$group", "$tmpdir/dumb.git"),
0, 'clone successful');
- ok(kill('TERM', $pid), 'killed httpd');
- $pid = undef;
- waitpid(-1, 0);
+ ok($td->kill, 'killed httpd');
+ $td->join;
- is(system('git', "--git-dir=$tmpdir/clone.git",
+ is(xsys('git', "--git-dir=$tmpdir/clone.git",
qw(fsck --no-verbose)), 0,
'fsck on cloned directory successful');
}
SKIP: {
skip 'TCP_DEFER_ACCEPT is Linux-only', 1 if $^O ne 'linux';
- my $var = Socket::TCP_DEFER_ACCEPT();
+ my $var = eval { Socket::TCP_DEFER_ACCEPT() } // 9;
defined(my $x = getsockopt($sock, IPPROTO_TCP, $var)) or die;
ok(unpack('i', $x) > 0, 'TCP_DEFER_ACCEPT set');
};