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