Commit | Line | Data |
600ade88 |
1 | use strict; |
2 | use warnings; |
3 | |
4853fb50 |
4 | use Test::More; |
5 | BEGIN { |
6 | plan skip_all => 'set TEST_LIGHTTPD to enable this test' |
7 | unless $ENV{TEST_LIGHTTPD}; |
8 | } |
9 | |
600ade88 |
10 | use File::Path; |
600ade88 |
11 | use FindBin; |
12 | use IO::Socket; |
600ade88 |
13 | |
ac30970a |
14 | eval "use FCGI"; |
15 | plan skip_all => 'FCGI required' if $@; |
ec904766 |
16 | |
600ade88 |
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; |
600ade88 |
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"; |
868a7cca |
40 | system "$^X -I$FindBin::Bin/../lib $FindBin::Bin/../script/catalyst.pl TestApp"; |
600ade88 |
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"; |
600ade88 |
55 | # basic lighttpd config file for testing fcgi+catalyst |
56 | server.modules = ( |
57 | "mod_access", |
58 | "mod_fastcgi", |
59 | "mod_accesslog" |
60 | ) |
61 | |
62 | server.document-root = "$docroot" |
63 | |
64 | server.errorlog = "$docroot/error.log" |
65 | accesslog.filename = "$docroot/access.log" |
66 | |
3fe34996 |
67 | server.bind = "127.0.0.1" |
600ade88 |
68 | server.port = $port |
69 | |
70 | # catalyst app specific fcgi setup |
71 | fastcgi.server = ( |
72 | "" => ( |
73 | "FastCgiTest" => ( |
43ebabf5 |
74 | "socket" => "$docroot/test.socket", |
75 | "check-local" => "disable", |
76 | "bin-path" => "$docroot/TestApp/script/testapp_fastcgi.pl", |
77 | "min-procs" => 1, |
78 | "max-procs" => 1, |
79 | "idle-timeout" => 20, |
80 | "bin-environment" => ( |
81 | "PERL5LIB" => "$docroot/../../lib" |
82 | ) |
600ade88 |
83 | ) |
84 | ) |
85 | ) |
3f5f2699 |
86 | END |
600ade88 |
87 | |
357cc417 |
88 | open(my $lightconf, '>', "$docroot/lighttpd.conf") |
89 | or die "Can't open $docroot/lighttpd.conf: $!"; |
3f5f2699 |
90 | print {$lightconf} $conf or die "Write error: $!"; |
91 | close $lightconf; |
600ade88 |
92 | |
93 | my $pid = open my $lighttpd, "$lighttpd_bin -D -f $docroot/lighttpd.conf 2>&1 |" |
94 | or die "Unable to spawn lighttpd: $!"; |
95 | |
96 | # wait for it to start |
600ade88 |
97 | while ( check_port( 'localhost', $port ) != 1 ) { |
357cc417 |
98 | diag "Waiting for server to start..."; |
600ade88 |
99 | sleep 1; |
100 | } |
101 | |
102 | # run the testsuite against the server |
103 | $ENV{CATALYST_SERVER} = "http://localhost:$port"; |
357cc417 |
104 | |
a68314c2 |
105 | my @tests = (shift) || glob('t/aggregate/live_*'); |
357cc417 |
106 | eval { |
107 | runtests(@tests); |
108 | }; |
109 | ok(!$@, 'lighttpd tests ran OK'); |
600ade88 |
110 | |
111 | # shut it down |
112 | kill 'INT', $pid; |
113 | close $lighttpd; |
114 | |
115 | # clean up |
116 | rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp"; |
117 | |
600ade88 |
118 | sub check_port { |
119 | my ( $host, $port ) = @_; |
120 | |
121 | my $remote = IO::Socket::INET->new( |
122 | Proto => "tcp", |
123 | PeerAddr => $host, |
124 | PeerPort => $port |
125 | ); |
126 | if ($remote) { |
127 | close $remote; |
128 | return 1; |
129 | } |
130 | else { |
131 | return 0; |
132 | } |
3f5f2699 |
133 | } |