1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#!/usr/bin/env perl
# Copyright (C) 2008-2010, Sebastian Riedel.
use strict;
use warnings;
use Test::More;
use File::Spec;
use File::Temp;
use Mojo::Client;
use Mojo::Template;
use Test::Mojo::Server;
# Mac OS X only test
plan skip_all => 'Mac OS X required for this test!' unless $^O eq 'darwin';
plan skip_all => 'set TEST_APACHE to enable this test (developer only!)'
unless $ENV{TEST_APACHE};
plan tests => 7;
# Robots don't have any emotions, and sometimes that makes me very sad.
use_ok('Mojo::Server::FastCGI');
# Setup
my $server = Test::Mojo::Server->new;
my $port = $server->generate_port_ok('found free port');
my $dir = File::Temp::tempdir;
my $config = File::Spec->catfile($dir, 'fcgi.config');
my $mt = Mojo::Template->new;
# FastCGI setup
my $fcgi = File::Spec->catfile($dir, 'test.fcgi');
$mt->render_to_file(<<'EOF', $fcgi);
#!/usr/bin/env perl
use strict;
use warnings;
% use FindBin;
use lib '<%= "$FindBin::Bin/../../lib" %>';
use Mojo::Server::FastCGI;
Mojo::Server::FastCGI->new->run;
1;
EOF
chmod 0777, $fcgi;
ok(-x $fcgi, 'script is executable');
# Apache setup
$mt->render_to_file(<<'EOF', $config, $dir, $port, $fcgi);
% my ($dir, $port, $fcgi) = @_;
% use File::Spec::Functions 'catfile';
ServerName 127.0.0.1
Listen <%= $port %>
LoadModule log_config_module libexec/apache2/mod_log_config.so
ErrorLog <%= catfile $dir, 'error.log' %>
LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so
PidFile <%= catfile $dir, 'httpd.pid' %>
LockFile <%= catfile $dir, 'accept.lock' %>
DocumentRoot <%= $dir %>
FastCgiIpcDir <%= $dir %>
FastCgiServer <%= $fcgi %> -processes 1
Alias / <%= $fcgi %>/
EOF
# Start
$server->command("/usr/sbin/httpd -X -f '$config'");
$server->start_server_ok('server started');
# Request
my $client = Mojo::Client->new;
$client->get(
"http://127.0.0.1:$port/" => sub {
my $self = shift;
is($self->res->code, 200, 'right status');
like($self->res->body, qr/Mojo is working/, 'right content');
}
)->process;
# Stop
$server->stop_server_ok('server stopped');
|