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