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