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