File: perm.t

package info (click to toggle)
liblog-agent-rotate-perl 1.201-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 140 kB
  • sloc: perl: 825; makefile: 2
file content (99 lines) | stat: -rw-r--r-- 2,186 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!perl
###########################################################################
#
# t/perm.t
#
# Copyright (c) 2000 Raphael Manfredi.
# Copyright (c) 2002-2015 Mark Rogaski, mrogaski@cpan.org;
# all rights reserved.
#
# See the README file included with the
# distribution for license information.
#
###########################################################################

use Test::More;

BEGIN { plan tests => 4 }

use Log::Agent;
require Log::Agent::Driver::File;
require Log::Agent::Rotate;

sub clear_log () {
    unlink <t/logfile*>;
}

sub perm_ok ($$) {
    #
    # Given a fileame and target permissions, checks if the file
    # was created with the correct permissions.
    #
    my($file, $target) = @_;

    $target &= ~ umask;         # account for user mask
    my $mode = (stat $file)[2]; # find the current mode
    $mode &= 0777;              # we only care about UGO

    return $mode == $target;
}

SKIP: {

    skip "file mode not supported on Win32.", 4 if $^O eq 'MSWin32';

    my $rotate = Log::Agent::Rotate->make(
        -backlog     => 2,
        -unzipped    => 2,
        -is_alone    => 1,
        -single_host => 1,
        -max_size    => 100,
        -file_perm   => 0600
    );

    my $driver = Log::Agent::Driver::File->make(
        -rotate   => $rotate,
        -channels => {
            'error'  => 't/logfile',
            'output' => 't/logfile',
        },
    );

    my $msg = '!' x 55;

    logconfig(-driver => $driver);
    clear_log;

    logsay $msg;
    ok(perm_ok("t/logfile", 0600));
    logsay $msg;
    ok(perm_ok("t/logfile.0", 0600));

    $rotate = Log::Agent::Rotate->make(
        -backlog     => 2,
        -unzipped    => 2,
        -is_alone    => 1,
        -single_host => 1,
        -max_size    => 100,
        -file_perm   => 0644
    );

    $driver = Log::Agent::Driver::File->make(
        -rotate   => $rotate,
        -channels => {
            'error'  => 't/logfile',
            'output' => 't/logfile',
        },
    );

    logconfig(-driver => $driver);
    clear_log;

    logsay $msg;
    ok(perm_ok("t/logfile", 0644));
    logsay $msg;
    ok(perm_ok("t/logfile.0", 0644));

    clear_log;

}