fix uri_for class method tests
[catagits/Catalyst-Runtime.git] / t / optional_lighttpd-fastcgi.t
CommitLineData
600ade88 1use strict;
2use warnings;
3
4853fb50 4use Test::More;
5BEGIN {
6 plan skip_all => 'set TEST_LIGHTTPD to enable this test'
7 unless $ENV{TEST_LIGHTTPD};
8}
9
600ade88 10use File::Path;
600ade88 11use FindBin;
12use IO::Socket;
f3d2ec61 13use Config ();
600ade88 14
8ae46e98 15BEGIN {
16 eval "use FCGI";
17 plan skip_all => 'FCGI required' if $@;
ec904766 18
8ae46e98 19 eval "use File::Copy::Recursive";
20 plan skip_all => 'File::Copy::Recursive required' if $@;
600ade88 21
8ae46e98 22 eval "use Test::Harness";
23 plan skip_all => 'Test::Harness required' if $@;
24}
600ade88 25
8ae46e98 26use lib 't/lib';
27use MakeTestApp;
357cc417 28
b71fcc0f 29my $lighttpd_bin = $ENV{LIGHTTPD_BIN} || `which lighttpd`;
30chomp $lighttpd_bin;
31
ec904766 32plan skip_all => 'Please set LIGHTTPD_BIN to the path to lighttpd'
381e2cab 33 unless $lighttpd_bin && -x $lighttpd_bin;
600ade88 34
35plan tests => 1;
36
8ae46e98 37# this creates t/tmp/TestApp
38make_test_app;
600ade88 39
40# Create a temporary lighttpd config
41my $docroot = "$FindBin::Bin/../t/tmp";
42my $port = 8529;
43
44# Clean up docroot path
f3d2ec61 45$docroot =~ s{/t/\.\.}{};
46
47my $perl5lib = join($Config::Config{path_sep}, "$docroot/../../lib", $ENV{PERL5LIB} || ());
600ade88 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" => (
43ebabf5 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 "bin-environment" => (
f3d2ec61 76 "PERL5LIB" => "$perl5lib"
43ebabf5 77 )
600ade88 78 )
79 )
80)
3f5f2699 81END
600ade88 82
88e5a8b0 83open(my $lightconf, '>', "$docroot/lighttpd.conf")
357cc417 84 or die "Can't open $docroot/lighttpd.conf: $!";
3f5f2699 85print {$lightconf} $conf or die "Write error: $!";
86close $lightconf;
600ade88 87
88e5a8b0 88my $pid = open my $lighttpd, "$lighttpd_bin -D -f $docroot/lighttpd.conf 2>&1 |"
600ade88 89 or die "Unable to spawn lighttpd: $!";
88e5a8b0 90
600ade88 91# wait for it to start
600ade88 92while ( check_port( 'localhost', $port ) != 1 ) {
357cc417 93 diag "Waiting for server to start...";
600ade88 94 sleep 1;
95}
96
97# run the testsuite against the server
98$ENV{CATALYST_SERVER} = "http://localhost:$port";
357cc417 99
a68314c2 100my @tests = (shift) || glob('t/aggregate/live_*');
357cc417 101eval {
102 runtests(@tests);
103};
104ok(!$@, 'lighttpd tests ran OK');
600ade88 105
106# shut it down
107kill 'INT', $pid;
108close $lighttpd;
109
110# clean up
111rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
112
600ade88 113sub check_port {
114 my ( $host, $port ) = @_;
115
116 my $remote = IO::Socket::INET->new(
117 Proto => "tcp",
118 PeerAddr => $host,
119 PeerPort => $port
120 );
121 if ($remote) {
122 close $remote;
123 return 1;
124 }
125 else {
126 return 0;
127 }
3f5f2699 128}