File: 01_basic.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 (70 lines) | stat: -rw-r--r-- 1,695 bytes parent folder | download | duplicates (2)
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
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();
    ok($log_handler);
    my $log = $log_handler->log_line(
        t::Req2PSGI::req_to_psgi(GET "/"),
        [200,[],[q!OK!]],
        2,
    );
    like $log, 
        qr!^[a-z0-9\.]+ - - \[\d{2}/\w{3}/\d{4}:\d{2}:\d{2}:\d{2} [+\-]\d{4}\] "GET / HTTP/1\.1" 200 2 "-" "-"$!;
};

{
    my $log_handler = Apache::LogFormat::Compiler->new(
        '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i" %D'
    );
    ok($log_handler);
    my $log = $log_handler->log_line(
        t::Req2PSGI::req_to_psgi(GET "/"),
        [200,[],[q!OK!]],
        2,
    );
    like $log, 
        qr!^[a-z0-9\.]+ - - \[\d{2}/\w{3}/\d{4}:\d{2}:\d{2}:\d{2} [+\-]\d{4}\] "GET / HTTP/1\.1" 200 2 "-" "-" -$!;
};


{
    my $log_handler = Apache::LogFormat::Compiler->new(
        '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i" %D'
    );
    ok($log_handler);
    my $log = $log_handler->log_line(
        t::Req2PSGI::req_to_psgi(GET "/"),
        [200,[],[q!OK!]],
        2,
        1_000_000,
        time()
    );
    like $log, 
        qr!^[a-z0-9\.]+ - - \[\d{2}/\w{3}/\d{4}:\d{2}:\d{2}:\d{2} [+\-]\d{4}\] "GET / HTTP/1\.1" 200 2 "-" "-" 1000000$!;
};


{
    my $log_handler = Apache::LogFormat::Compiler->new(
        '%m %U %q %H'
    );
    ok($log_handler);
    my $log = $log_handler->log_line(
        t::Req2PSGI::req_to_psgi(GET "/foo?bar=baz"),
        [200,[],[q!OK!]],
        2,
        1_000_000,
        time()
    );
    like $log, 
        qr!^GET /foo \?bar=baz HTTP/1\.1$!
};


done_testing();