fixed lighttpd tests
[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;
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
357cc417 17eval "use Test::Harness";
18plan skip_all => 'Test::Harness required' if $@;
19
381e2cab 20my $lighttpd_bin = $ENV{LIGHTTPD_BIN};
21plan skip_all => 'Please set LIGHTTPD_BIN to run this test'
22 unless $lighttpd_bin && -x $lighttpd_bin;
3b6a7b7f 23
24plan tests => 1;
25
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
3f5f2699 46my $conf = <<"END";
3b6a7b7f 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)
3f5f2699 75END
3b6a7b7f 76
357cc417 77open(my $lightconf, '>', "$docroot/lighttpd.conf")
78 or die "Can't open $docroot/lighttpd.conf: $!";
3f5f2699 79print {$lightconf} $conf or die "Write error: $!";
80close $lightconf;
3b6a7b7f 81
82my $pid = open my $lighttpd, "$lighttpd_bin -D -f $docroot/lighttpd.conf 2>&1 |"
83 or die "Unable to spawn lighttpd: $!";
84
85# wait for it to start
3b6a7b7f 86while ( check_port( 'localhost', $port ) != 1 ) {
357cc417 87 diag "Waiting for server to start...";
3b6a7b7f 88 sleep 1;
89}
90
91# run the testsuite against the server
92$ENV{CATALYST_SERVER} = "http://localhost:$port/deep/path";
357cc417 93
94my @tests = glob('t/live_*');
95eval {
96 runtests(@tests);
97};
98ok(!$@, 'lighttpd tests ran OK');
3b6a7b7f 99
100# shut it down
101kill 'INT', $pid;
102close $lighttpd;
103
104# clean up
105rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
106
3b6a7b7f 107sub check_port {
108 my ( $host, $port ) = @_;
109
110 my $remote = IO::Socket::INET->new(
111 Proto => "tcp",
112 PeerAddr => $host,
113 PeerPort => $port
114 );
115 if ($remote) {
116 close $remote;
117 return 1;
118 }
119 else {
120 return 0;
121 }
3f5f2699 122}