From: Eric Wong Date: Tue, 8 Mar 2016 04:36:17 +0000 (+0000) Subject: tests: consolidate repobrowse + httpd integration X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=278706bf0ab1ce134e0f742791fa904692660ab8;p=thirdparty%2Fpublic-inbox.git tests: consolidate repobrowse + httpd integration Use Plack::Test::ExternalServer to simplify our test code and prepare to add more tests for future changes. Add a check for patch generation while we're at it, since patch generation may use our internal "pi.async" API. --- diff --git a/t/repobrowse_git_fallback.t b/t/repobrowse_git_httpd.t similarity index 67% rename from t/repobrowse_git_fallback.t rename to t/repobrowse_git_httpd.t index 99f2ee705..a9eb0aabe 100644 --- a/t/repobrowse_git_fallback.t +++ b/t/repobrowse_git_httpd.t @@ -1,19 +1,24 @@ # Copyright (C) 2016 all contributors # License: AGPL-3.0+ +# +# Integration test for public-inbox-httpd and (git) repobrowse +# since we may use some special APIs not available in other servers use strict; use warnings; use Test::More; -my $test = require './t/repobrowse_common_git.perl'; -foreach my $mod (qw(Danga::Socket HTTP::Parser::XS HTTP::Date HTTP::Status)) { +foreach my $mod (qw(Danga::Socket HTTP::Parser::XS HTTP::Date HTTP::Status + Plack::Test::ExternalServer)) { eval "require $mod"; - plan skip_all => "$mod missing for repobrowse_git_fallback.t" if $@; + plan skip_all => "$mod missing for repobrowse_git_httpd.t" if $@; } +my $test = require './t/repobrowse_common_git.perl'; +$Plack::Test::Impl = 'ExternalServer'; use File::Temp qw/tempdir/; use Cwd qw/getcwd/; use IO::Socket; use Fcntl qw(F_SETFD); use POSIX qw(dup2); -my $tmpdir = tempdir('repobrowse_git_fallback-XXXXXX', TMPDIR => 1, CLEANUP => 1); +my $tmpdir = tempdir('repobrowse_git_httpd-XXXXXX', TMPDIR => 1, CLEANUP => 1); my $err = "$tmpdir/stderr.log"; my $out = "$tmpdir/stdout.log"; my $httpd = 'blib/script/public-inbox-httpd'; @@ -26,6 +31,9 @@ my %opts = ( Listen => 1024, ); my $sock = IO::Socket::INET->new(%opts); +my $host = $sock->sockhost; +my $port = $sock->sockport; +my $uri = "http://$host:$port/"; my $pid; END { kill 'TERM', $pid if defined $pid }; my $spawn_httpd = sub { @@ -47,22 +55,43 @@ my $spawn_httpd = sub { $spawn_httpd->(); -{ - my $host = $sock->sockhost; - my $port = $sock->sockport; - my $url = "http://$host:$port/test.git"; +{ # git clone tests + my $url = $uri . 'test.git'; is(system(qw(git clone -q --mirror), $url, "$tmpdir/smart.git"), 0, 'smart clone successful'); is(system('git', "--git-dir=$tmpdir/smart.git", 'fsck'), 0, 'fsck OK'); - is(system('git', "--git-dir=$test->{git_dir}", qw(config http.uploadpack 0)), 0, 'disabled smart HTTP'); is(system('git', "--git-dir=$test->{git_dir}", qw(update-server-info)), 0, 'enable dumb HTTP'); is(system(qw(git clone -q --mirror), $url, "$tmpdir/dumb.git"), 0, 'dumb clone successful'); - is(system('git', "--git-dir=$tmpdir/dumb.git", 'fsck'), 0, 'fsck dumb OK'); + is(system('git', "--git-dir=$tmpdir/dumb.git", 'fsck'), + 0, 'fsck dumb OK'); +} +test_psgi(uri => $uri, client => sub { + my ($cb) = @_; + my $res = $cb->(GET($uri . 'test.git/info/refs')); + is(200, $res->code, 'got info/refs'); + + $res = $cb->(GET($uri . 'best.git/info/refs')); + is(404, $res->code, 'bad request fails'); + + $res = $cb->(GET($uri . 'test.git/patch')); + is(200, $res->code, 'got patch'); + is('text/plain; charset=UTF-8', $res->header('Content-Type'), + 'got proper content-type with patch'); + + # ignore signature from git-format-patch: + my ($patch, undef) = split(/\n-- \n/s, $res->content); + my ($exp, undef) = split(/\n-- \n/s, + `cd "$test->{git_dir}" && \ + git format-patch -1 -M --stdout HEAD`); + is($patch, $exp, 'patch content matches expected'); +}); + +{ # allow reading description file my %conn = ( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Type => SOCK_STREAM);