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