X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fhttpd.t;h=880c69e62f601d9d54b48bd7624e6ff98f898f83;hb=d62d98b9a7f502da65673f0b83a6d06312c060d9;hp=e0a2bf44164a0f79d6be8b6a34471337645352b0;hpb=3eb26fe04dae68612c841e749abd2848ce78ae59;p=public-inbox.git diff --git a/t/httpd.t b/t/httpd.t index e0a2bf44..880c69e6 100644 --- a/t/httpd.t +++ b/t/httpd.t @@ -1,20 +1,14 @@ -# Copyright (C) 2016-2018 all contributors +# Copyright (C) 2016-2019 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 IO::Socket::INET; -use Socket qw(IPPROTO_TCP); -require './t/common.perl'; +use PublicInbox::TestCommon; +use Socket qw(IPPROTO_TCP SOL_SOCKET); +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"; @@ -22,18 +16,15 @@ 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 $init = 'blib/script/public-inbox-init'; 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; - ok(!system($init, $group, $maindir, 'http://example.com/', $addr), - 'init ran properly'); + my $cmd = [ '-init', $group, $maindir, 'http://example.com/', $addr ]; + ok(run_script($cmd), 'init ran properly'); # ensure successful message delivery { @@ -54,14 +45,11 @@ EOF $im->done($mime); } ok($sock, 'sock created'); - my $cmd = [ $httpd, "--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 $conn = IO::Socket::INET->new(PeerAddr => $host, - PeerPort => $port, - Proto => 'tcp', - Type => SOCK_STREAM); + my $conn = tcp_connect($sock); ok($conn, 'connected'); ok($conn->write("GET / HTTP/1.0\r\n\r\n"), 'wrote data to socket'); { @@ -83,9 +71,8 @@ EOF "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", qw(fsck --no-verbose)), 0,