]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
tests: consolidate repobrowse + httpd integration
authorEric Wong <e@80x24.org>
Tue, 8 Mar 2016 04:36:17 +0000 (04:36 +0000)
committerEric Wong <e@80x24.org>
Tue, 5 Apr 2016 18:58:27 +0000 (18:58 +0000)
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.

t/repobrowse_git_httpd.t [moved from t/repobrowse_git_fallback.t with 67% similarity]

similarity index 67%
rename from t/repobrowse_git_fallback.t
rename to t/repobrowse_git_httpd.t
index 99f2ee705879949e054ed18142523518c3f3a151..a9eb0aabe99a09b8e62259abe6fae7da1eefa1a5 100644 (file)
@@ -1,19 +1,24 @@
 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+#
+# 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);