allow GET with body test to fail on lighttpd
[catagits/Catalyst-Runtime.git] / t / optional_lighttpd-fastcgi.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 BEGIN {
6     plan skip_all => 'set TEST_LIGHTTPD to enable this test'
7         unless $ENV{TEST_LIGHTTPD};
8 }
9
10 use File::Path;
11 use FindBin;
12 use IO::Socket;
13 use Config ();
14
15 BEGIN {
16     eval "use FCGI";
17     plan skip_all => 'FCGI required' if $@;
18
19     eval "use File::Copy::Recursive";
20     plan skip_all => 'File::Copy::Recursive required' if $@;
21
22     eval "use Test::Harness";
23     plan skip_all => 'Test::Harness required' if $@;
24 }
25
26 use lib 't/lib';
27 use MakeTestApp;
28
29 my $lighttpd_bin = $ENV{LIGHTTPD_BIN} || `which lighttpd`;
30 chomp $lighttpd_bin;
31
32 plan skip_all => 'Please set LIGHTTPD_BIN to the path to lighttpd'
33     unless $lighttpd_bin && -x $lighttpd_bin;
34
35 plan tests => 1;
36
37 # this creates t/tmp/TestApp
38 make_test_app;
39
40 # Create a temporary lighttpd config
41 my $docroot = "$FindBin::Bin/../t/tmp";
42 my $port    = 8529;
43
44 # Clean up docroot path
45 $docroot =~ s{/t/\.\.}{};
46
47 my $perl5lib = join($Config::Config{path_sep}, "$docroot/../../lib", $ENV{PERL5LIB} || ());
48
49 my $conf = <<"END";
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
62 server.bind = "127.0.0.1"
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             "bin-environment" => (
76                 "PERL5LIB" => "$perl5lib"
77             )
78         )
79     )
80 )
81 END
82
83 open(my $lightconf, '>', "$docroot/lighttpd.conf")
84   or die "Can't open $docroot/lighttpd.conf: $!";
85 print {$lightconf} $conf or die "Write error: $!";
86 close $lightconf;
87
88 my $pid = open my $lighttpd, "$lighttpd_bin -D -f $docroot/lighttpd.conf 2>&1 |"
89     or die "Unable to spawn lighttpd: $!";
90
91 # wait for it to start
92 while ( check_port( 'localhost', $port ) != 1 ) {
93     diag "Waiting for server to start...";
94     sleep 1;
95 }
96
97 # run the testsuite against the server
98 $ENV{CATALYST_SERVER} = "http://localhost:$port";
99
100 my @tests = (shift) || glob('t/aggregate/live_*');
101 eval {
102     runtests(@tests);
103 };
104 ok(!$@, 'lighttpd tests ran OK');
105
106 # shut it down
107 kill 'INT', $pid;
108 close $lighttpd;
109
110 # clean up
111 rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
112
113 sub check_port {
114     my ( $host, $port ) = @_;
115
116     my $remote = IO::Socket::INET->new(
117         Proto    => "tcp",
118         PeerAddr => $host,
119         PeerPort => $port
120     );
121     if ($remote) {
122         close $remote;
123         return 1;
124     }
125     else {
126         return 0;
127     }
128 }