Skip the live_stats test on remote servers
[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",
159eb4bb 59 "mod_rewrite",
3b6a7b7f 60 "mod_accesslog"
61)
62
63server.document-root = "$docroot"
64
65server.errorlog = "$docroot/error.log"
66accesslog.filename = "$docroot/access.log"
67
68server.bind = "127.0.0.1"
69server.port = $port
70
159eb4bb 71# Work around inability to hit http://localhost/deep/path
72# without a trailing slash
73url.rewrite = ( "deep/path\$" => "deep/path/" )
74
3b6a7b7f 75# catalyst app specific fcgi setup
76fastcgi.server = (
77 "/deep/path" => (
78 "FastCgiTest" => (
79 "socket" => "$docroot/test.socket",
80 "check-local" => "disable",
81 "bin-path" => "$docroot/TestApp/script/testapp_fastcgi.pl",
82 "min-procs" => 1,
83 "max-procs" => 1,
84 "idle-timeout" => 20
85 )
86 )
87)
3f5f2699 88END
3b6a7b7f 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;
3b6a7b7f 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
3b6a7b7f 99while ( check_port( 'localhost', $port ) != 1 ) {
357cc417 100 diag "Waiting for server to start...";
3b6a7b7f 101 sleep 1;
102}
103
104# run the testsuite against the server
105$ENV{CATALYST_SERVER} = "http://localhost:$port/deep/path";
357cc417 106
07871986 107my @tests = (shift) || glob('t/live_*');
357cc417 108eval {
109 runtests(@tests);
110};
111ok(!$@, 'lighttpd tests ran OK');
3b6a7b7f 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
3b6a7b7f 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}