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