1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
use strict;
use warnings;
use Test::More;
use Plack;
use Test::TCP;
use LWP::UserAgent;
use FindBin;
use Plack::Test::Suite;
plan skip_all => "TEST_APACHE2 is not set"
unless $ENV{TEST_APACHE2};
# Note: you need to load 64bit lib to test Apache2 on OS X 10.5 or later
Plack::Test::Suite->run_server_tests(run_httpd(\&_render_conf));
local $ENV{PLACK_TEST_SCRIPT_NAME} = '/foo/bar/baz';
Plack::Test::Suite->run_server_tests( run_httpd(\&_render_conf_location),);
Plack::Test::Suite->run_server_tests( run_httpd(\&_render_conf_location_match),);
done_testing();
sub run_httpd {
my $render_conf = shift;
sub {
my $port = shift;
my $tmpdir = $ENV{APACHE2_TMP_DIR} || File::Temp::tempdir( CLEANUP => 1 );
write_file("$tmpdir/app.psgi", _render_psgi());
write_file("$tmpdir/httpd.conf", $render_conf->($tmpdir, $port, "$tmpdir/app.psgi"));
# This is required for failing tests.
# Apache2 peep real filesystem to make SCRIPT_NAME and PATH_INFO.
mkdir "$tmpdir/foo";
exec "httpd -X -D FOREGROUND -f $tmpdir/httpd.conf";
};
}
sub write_file {
my($path, $content) = @_;
open my $out, ">", $path or die "$path: $!";
print $out $content;
}
sub _render_psgi {
return <<'EOF';
use lib "lib";
use Plack::Test::Suite;
Plack::Test::Suite->test_app_handler;
EOF
}
sub _render_conf {
my ($tmpdir, $port, $psgi_path) = @_;
<<"END";
LoadModule perl_module libexec/apache2/mod_perl.so
ServerRoot $tmpdir
DocumentRoot $tmpdir
PidFile $tmpdir/httpd.pid
LockFile $tmpdir/httpd.lock
ErrorLog $tmpdir/error_log
Listen $port
<Perl>
use Plack::Handler::Apache2;
Plack::Handler::Apache2->preload("$tmpdir/app.psgi");
</Perl>
<Location />
SetHandler perl-script
PerlHandler Plack::Handler::Apache2
PerlSetVar psgi_app $tmpdir/app.psgi
</Location>
END
}
sub _render_conf_location {
my ($tmpdir, $port, $psgi_path) = @_;
<<"END";
LoadModule perl_module libexec/apache2/mod_perl.so
ServerRoot $tmpdir
DocumentRoot $tmpdir
PidFile $tmpdir/httpd.pid
LockFile $tmpdir/httpd.lock
ErrorLog $tmpdir/error_log
Listen $port
<Perl>
use Plack::Handler::Apache2;
Plack::Handler::Apache2->preload("$tmpdir/app.psgi");
</Perl>
<Location /foo/bar/baz>
SetHandler perl-script
PerlHandler Plack::Handler::Apache2
PerlSetVar psgi_app $tmpdir/app.psgi
</Location>
END
}
sub _render_conf_location_match {
my ($tmpdir, $port, $psgi_path) = @_;
<<"END";
LoadModule perl_module libexec/apache2/mod_perl.so
ServerRoot $tmpdir
DocumentRoot $tmpdir
PidFile $tmpdir/httpd.pid
LockFile $tmpdir/httpd.lock
ErrorLog $tmpdir/error_log
Listen $port
<Perl>
use Plack::Handler::Apache2;
Plack::Handler::Apache2->preload("$tmpdir/app.psgi");
</Perl>
<LocationMatch /foo/bar/(baz)>
SetHandler perl-script
PerlHandler Plack::Handler::Apache2
PerlSetVar psgi_app $tmpdir/app.psgi
</LocationMatch>
END
}
|