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