File: 03_extra.t

package info (click to toggle)
libapache-logformat-compiler-perl 0.30-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 144 kB
  • sloc: perl: 247; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use HTTP::Request::Common;
use t::Req2PSGI;
use Test::More;
use Apache::LogFormat::Compiler;

{
    my $log_handler = Apache::LogFormat::Compiler->new(
        q!%z %{HTTP_X_FORWARDED_FOR|REMOTE_ADDR}Z!,
        char_handlers => +{
            'z' => sub {
                my ($env,$req) = @_;
                ok($env);
                ok($req);
                return $env->{HTTP_X_REQ_TEST};
            },
        },
        block_handlers => +{
            'Z' => sub {
                my ($block,$env,$req) = @_;
                is($block, 'HTTP_X_FORWARDED_FOR|REMOTE_ADDR');
                ok($env);
                ok($req);
                return $block;
            },
        },
    );
    ok($log_handler);
    my $log = $log_handler->log_line(
        t::Req2PSGI::req_to_psgi(GET "/", 'X-Req-Test'=>'foo'),
        [200,['X-Res-Test'=>'bar'],[q!OK!]],
        2,
        1_000_000
    );
    is $log, q!foo HTTP_X_FORWARDED_FOR|REMOTE_ADDR!."\n";
}

done_testing();