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