again
[catagits/Catalyst-Runtime.git] / t / optional_lighttpd-fastcgi-non-root.t
CommitLineData
3b6a7b7f 1#!perl
2
3use strict;
4use warnings;
5
6use File::Path;
7use File::Slurp qw(write_file);
8use FindBin;
9use IO::Socket;
10use Test::More;
11
12eval "use Catalyst::Devel 1.0";
13plan skip_all => 'Catalyst::Devel required' if $@;
14
15eval "use File::Copy::Recursive";
16plan skip_all => 'File::Copy::Recursive required' if $@;
17
18my $lighttpd_bin = $ENV{LIGHTTPD_BIN} || 'lighttpd';
19plan skip_all => 'Cannot find lighttpd, please set LIGHTTPD_BIN'
20 unless -x $lighttpd_bin;
21
22plan tests => 1;
23
24# clean up
25rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
26
27# create a TestApp and copy the test libs into it
28mkdir "$FindBin::Bin/../t/tmp";
29chdir "$FindBin::Bin/../t/tmp";
30system "perl -I$FindBin::Bin/../lib $FindBin::Bin/../script/catalyst.pl TestApp";
31chdir "$FindBin::Bin/..";
32File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
33
34# remove TestApp's tests
35rmtree 't/tmp/TestApp/t';
36
37# Create a temporary lighttpd config
38my $docroot = "$FindBin::Bin/../t/tmp";
39my $port = 8529;
40
41# Clean up docroot path
42$docroot =~ s{/t/..}{};
43
44my $conf = qq{
45# basic lighttpd config file for testing fcgi+catalyst
46server.modules = (
47 "mod_access",
48 "mod_fastcgi",
49 "mod_accesslog"
50)
51
52server.document-root = "$docroot"
53
54server.errorlog = "$docroot/error.log"
55accesslog.filename = "$docroot/access.log"
56
57server.bind = "127.0.0.1"
58server.port = $port
59
60# catalyst app specific fcgi setup
61fastcgi.server = (
62 "/deep/path" => (
63 "FastCgiTest" => (
64 "socket" => "$docroot/test.socket",
65 "check-local" => "disable",
66 "bin-path" => "$docroot/TestApp/script/testapp_fastcgi.pl",
67 "min-procs" => 1,
68 "max-procs" => 1,
69 "idle-timeout" => 20
70 )
71 )
72)
73};
74
75write_file "$docroot/lighttpd.conf", $conf;
76
77my $pid = open my $lighttpd, "$lighttpd_bin -D -f $docroot/lighttpd.conf 2>&1 |"
78 or die "Unable to spawn lighttpd: $!";
79
80# wait for it to start
81print "Waiting for server to start...\n";
82while ( check_port( 'localhost', $port ) != 1 ) {
83 sleep 1;
84}
85
86# run the testsuite against the server
87$ENV{CATALYST_SERVER} = "http://localhost:$port/deep/path";
88system( 'prove -r -Ilib/ t/live_*' );
89
90# shut it down
91kill 'INT', $pid;
92close $lighttpd;
93
94# clean up
95rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
96
97ok( 'done' );
98
99sub check_port {
100 my ( $host, $port ) = @_;
101
102 my $remote = IO::Socket::INET->new(
103 Proto => "tcp",
104 PeerAddr => $host,
105 PeerPort => $port
106 );
107 if ($remote) {
108 close $remote;
109 return 1;
110 }
111 else {
112 return 0;
113 }
114}