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