eliminate file::slurp dependency
[catagits/Catalyst-Runtime.git] / t / optional_lighttpd-fastcgi.t
CommitLineData
600ade88 1#!perl
2
3use strict;
4use warnings;
5
6use File::Path;
600ade88 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
381e2cab 17my $lighttpd_bin = $ENV{LIGHTTPD_BIN};
18plan skip_all => 'Please set LIGHTTPD_BIN to run this test'
19 unless $lighttpd_bin && -x $lighttpd_bin;
600ade88 20
21plan tests => 1;
22
23# clean up
24rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
25
26# create a TestApp and copy the test libs into it
27mkdir "$FindBin::Bin/../t/tmp";
28chdir "$FindBin::Bin/../t/tmp";
29system "perl -I$FindBin::Bin/../lib $FindBin::Bin/../script/catalyst.pl TestApp";
30chdir "$FindBin::Bin/..";
31File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
32
33# remove TestApp's tests
34rmtree 't/tmp/TestApp/t';
35
36# Create a temporary lighttpd config
37my $docroot = "$FindBin::Bin/../t/tmp";
38my $port = 8529;
39
40# Clean up docroot path
41$docroot =~ s{/t/..}{};
42
3f5f2699 43my $conf = <<"END";
600ade88 44# basic lighttpd config file for testing fcgi+catalyst
45server.modules = (
46 "mod_access",
47 "mod_fastcgi",
48 "mod_accesslog"
49)
50
51server.document-root = "$docroot"
52
53server.errorlog = "$docroot/error.log"
54accesslog.filename = "$docroot/access.log"
55
3fe34996 56server.bind = "127.0.0.1"
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)
3f5f2699 72END
600ade88 73
3f5f2699 74open(my $lightconf, '>', "$docroot/lighttpd.conf") or die "Can't open $docroot/lighttpd.conf: $!";
75print {$lightconf} $conf or die "Write error: $!";
76close $lightconf;
600ade88 77
78my $pid = open my $lighttpd, "$lighttpd_bin -D -f $docroot/lighttpd.conf 2>&1 |"
79 or die "Unable to spawn lighttpd: $!";
80
81# wait for it to start
82print "Waiting for server to start...\n";
83while ( check_port( 'localhost', $port ) != 1 ) {
84 sleep 1;
85}
86
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 }
3f5f2699 115}