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