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