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