Skip local %2F tests on remote servers
[catagits/Catalyst-Runtime.git] / t / optional_lighttpd-fastcgi.t
CommitLineData
600ade88 1#!perl
2
3use strict;
4use warnings;
5
6use File::Path;
7use File::Slurp qw(write_file);
8use FindBin;
9use IO::Socket;
10use Test::More;
11
12eval "use Catalyst::Devel 1.0";
13plan skip_all => 'Catalyst::Devel required' if $@;
14
15eval "use File::Copy::Recursive";
16plan skip_all => 'File::Copy::Recursive required' if $@;
17
18my $lighttpd_bin = $ENV{LIGHTTPD_BIN} || 'lighttpd';
19plan skip_all => 'Cannot find lighttpd, please set LIGHTTPD_BIN'
20 unless -x $lighttpd_bin;
21
22plan tests => 1;
23
24# clean up
25rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
26
27# create a TestApp and copy the test libs into it
28mkdir "$FindBin::Bin/../t/tmp";
29chdir "$FindBin::Bin/../t/tmp";
30system "perl -I$FindBin::Bin/../lib $FindBin::Bin/../script/catalyst.pl TestApp";
31chdir "$FindBin::Bin/..";
32File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
33
34# remove TestApp's tests
35rmtree 't/tmp/TestApp/t';
36
37# Create a temporary lighttpd config
38my $docroot = "$FindBin::Bin/../t/tmp";
39my $port = 8529;
40
41# Clean up docroot path
42$docroot =~ s{/t/..}{};
43
44my $conf = qq{
45# basic lighttpd config file for testing fcgi+catalyst
46server.modules = (
47 "mod_access",
48 "mod_fastcgi",
49 "mod_accesslog"
50)
51
52server.document-root = "$docroot"
53
54server.errorlog = "$docroot/error.log"
55accesslog.filename = "$docroot/access.log"
56
600ade88 57server.port = $port
58
59# catalyst app specific fcgi setup
60fastcgi.server = (
61 "" => (
62 "FastCgiTest" => (
63 "socket" => "$docroot/test.socket",
64 "check-local" => "disable",
65 "bin-path" => "$docroot/TestApp/script/testapp_fastcgi.pl",
66 "min-procs" => 1,
67 "max-procs" => 1,
68 "idle-timeout" => 20
69 )
70 )
71)
72};
73
74write_file "$docroot/lighttpd.conf", $conf;
75
76my $pid = open my $lighttpd, "$lighttpd_bin -D -f $docroot/lighttpd.conf 2>&1 |"
77 or die "Unable to spawn lighttpd: $!";
78
79# wait for it to start
80print "Waiting for server to start...\n";
81while ( check_port( 'localhost', $port ) != 1 ) {
82 sleep 1;
83}
84
5884ba38 85exit;
86
600ade88 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}