File: syslog.t

package info (click to toggle)
liblog-dispatch-perl 2.71-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: perl: 1,457; sh: 24; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 1,784 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
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
92
93
use strict;
use warnings;

use Test::More 0.88;

use Test::Needs {
    'Sys::Syslog' => '0.28',
};

use Log::Dispatch;
use Log::Dispatch::Syslog;
use Try::Tiny;

## no critic (TestingAndDebugging::ProhibitNoWarnings)
no warnings 'redefine', 'once';

my @sock;
local *Sys::Syslog::setlogsock = sub { @sock = @_ };

local *Sys::Syslog::openlog  = sub { return 1 };
local *Sys::Syslog::closelog = sub { return 1 };

my @log;
local *Sys::Syslog::syslog = sub { push @log, [@_] };

{
    @log = ();

    my $dispatch = Log::Dispatch->new;
    $dispatch->add(
        Log::Dispatch::Syslog->new(
            name      => 'syslog',
            min_level => 'debug',
        )
    );

    $dispatch->info('Foo');

    ok(
        !@sock,
        'no call to setlogsock unless socket is set explicitly'
    );

    is_deeply(
        \@log,
        [ [ 'INFO', 'Foo' ] ],
        'passed message to syslog'
    );
}

{
    @log = ();

    my $dispatch = Log::Dispatch->new;
    $dispatch->add(
        Log::Dispatch::Syslog->new(
            name      => 'syslog',
            min_level => 'debug',
            socket    => { type => 'foo' },
        )
    );

    $dispatch->info('Foo');

    is_deeply(
        \@sock,
        [ { type => 'foo' } ],
        'call to setlogsock is made when logging a message if socket was passed to LD::Syslog constructor'
    );
}

{
    @log = ();
    my $dispatch = Log::Dispatch->new;
    $dispatch->add(
        Log::Dispatch::Syslog->new(
            name      => 'syslog',
            min_level => 'debug',
            socket    => { type => 'foo' },
        )
    );

    local $@ = 'foo!';

    $dispatch->debug('Foo');

    like(
        $@, qr/^foo!/,
        '$@ is not changed when Log::Dispatch::Syslog does logging'
    );
}

done_testing();