Switched to Module::Install
[catagits/Catalyst-Runtime.git] / t / optional_apache-fastcgi.pl
CommitLineData
58f5682a 1#!perl
2
3# Run all tests against FastCGI mode under Apache
4#
5# Note, to get this to run properly, you may need to give it the path to your
6# httpd.conf:
7#
8# perl t/optional/apache-fastcgi.pl -httpd_conf /etc/apache/httpd.conf
9
10use strict;
11use warnings;
12
13use Apache::Test;
14use Apache::TestRun ();
15
16use File::Path;
17use File::Copy::Recursive;
18use FindBin;
e2a24892 19use IO::Socket;
58f5682a 20
21# clean up
10bdcbe8 22rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
58f5682a 23
24# create a TestApp and copy the test libs into it
10bdcbe8 25mkdir "$FindBin::Bin/../../t/tmp";
26chdir "$FindBin::Bin/../../t/tmp";
58f5682a 27system "$FindBin::Bin/../../script/catalyst.pl TestApp";
28chdir "$FindBin::Bin/../..";
10bdcbe8 29File::Copy::Recursive::dircopy( 't/live/lib', 't/tmp/TestApp/lib' );
58f5682a 30
31# remove TestApp's tests so Apache::Test doesn't try to run them
10bdcbe8 32rmtree 't/tmp/TestApp/t';
58f5682a 33
dd3af04e 34$ENV{CATALYST_SERVER} = 'http://localhost:8529/fastcgi';
58f5682a 35
36Apache::TestRun->new->run(@ARGV);
37
e2a24892 38# clean up if the server has shut down
39# this allows the test files to stay around if the user ran -start-httpd
40if ( ! check_port( 'localhost', 8529 ) ) {
41 rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
42}
43
44sub check_port {
45 my ( $host, $port ) = @_;
46
47 my $remote = IO::Socket::INET->new(
48 Proto => "tcp",
49 PeerAddr => $host,
50 PeerPort => $port
51 );
52 if ($remote) {
53 close $remote;
54 return 1;
55 }
56 else {
57 return 0;
58 }
59}