File: apache1.t

package info (click to toggle)
libplack-perl 0.9989-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,556 kB
  • sloc: perl: 6,890; python: 6; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download
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
use strict;
use warnings;
use Test::More;
use Plack;
use Test::TCP;
use LWP::UserAgent;
use FindBin;
use File::Path;

use Plack::Test::Suite;

plan skip_all => "TEST_APACHE1 is not set"
    unless $ENV{TEST_APACHE1};

Plack::Test::Suite->run_server_tests(\&run_httpd);
done_testing();

my $log_filename;

sub run_httpd {
    my $port = shift;

    my $tmpdir = $ENV{APACHE1_TMP_DIR} || File::Temp::tempdir( CLEANUP => 1 );

    my $httpd = $ENV{APACHE_BIN} || 'httpd';

    write_file("$tmpdir/app.psgi", _render_psgi());
    write_file("$tmpdir/httpd.conf", _render_conf($tmpdir, $port, "$tmpdir/app.psgi"));
    mkpath( "$tmpdir/conf" );
    write_file("$tmpdir/conf/mime.types", _render_mimetypes());


    $log_filename = "$tmpdir/error_log";
    system ("touch $log_filename");
    link($log_filename, 'err');

    exec "$httpd -X -F -f $tmpdir/httpd.conf" or die "couldn't start httpd : $!\n";
}


sub write_file {
    my($path, $content) = @_;

    open my $out, ">", $path or die "$path: $!";
    print $out $content;
}

sub _render_mimetypes {
    return 'text/html                                       html htm';
}


sub _render_psgi {
    return <<'EOF';
use lib "lib";
use Plack::Test::Suite;

Plack::Test::Suite->test_app_handler;
EOF
}

sub _render_conf {
    my ($tmpdir, $port, $psgi_path) = @_;
    my $load_module = ( -f "$tmpdir/libexec/mod_perl.so" ) ? 'LoadModule perl_module libexec/mod_perl.so' : '' ;
    my $conf = <<"END";
$load_module
ServerRoot $tmpdir
ServerName 127.0.0.1
PidFile $tmpdir/httpd.pid
LockFile $tmpdir/httpd.lock
ErrorLog $tmpdir/error_log
Listen $port

<Location />
SetHandler perl-script
PerlHandler Plack::Handler::Apache1
PerlSetVar psgi_app $tmpdir/app.psgi
</Location>
END
    return $conf;
}