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