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