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