File: 11log.t

package info (click to toggle)
libhttp-proxy-perl 0.301-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 636 kB
  • ctags: 164
  • sloc: perl: 2,403; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (9)
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
use Test::More;
use HTTP::Proxy qw(:log);
use strict;

my %mask = (
    CONNECT => CONNECT,
    DATA    => DATA,
    ENGINE  => ENGINE,
    ERROR   => ERROR,
    FILTERS => FILTERS,
    HEADERS => HEADERS,
    PROCESS => PROCESS,
    PROXY   => PROXY,
    SOCKET  => SOCKET,
    STATUS  => STATUS,
);

# try all combinations

my @tests = (
    [ NONE,                   qw( ERROR ) ],
    [ PROXY,                  qw( ERROR PROXY ) ],
    [ STATUS | SOCKET,        qw( ERROR SOCKET STATUS ) ],
    [ DATA | STATUS | SOCKET, qw( DATA ERROR SOCKET STATUS ) ],
    [   ALL, qw( CONNECT DATA ENGINE ERROR FILTERS
            HEADERS PROCESS PROXY SOCKET STATUS )
    ],
);

my $t;
$t += @$_ - 1 for @tests;
plan tests => $t;

# communicate with a pipe
pipe my ( $rh, $wh );
select( ( select($wh), $| = 1 )[0] );

# the proxy logs error to the pipe
my $proxy = HTTP::Proxy->new( logfh => $wh );

for (@tests) {
    my ( $mask, @msgs ) = @$_;
    $proxy->logmask($mask);
    $proxy->log( $mask{$_}, 'TEST', $_ ) for sort keys %mask;
    like( <$rh>, qr/TEST: $_$/, "mask $mask: $_ message" ) for @msgs;
}
close $wh;
print for <$rh>;