File: perm.t

package info (click to toggle)
liblog-agent-rotate-perl 0.104-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 112 kB
  • ctags: 43
  • sloc: perl: 790; makefile: 2; ansic: 1
file content (102 lines) | stat: -rw-r--r-- 2,165 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
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
100
101
102
#!perl
###########################################################################
# $Id: perm.t,v 1.1 2002/05/14 04:46:34 wendigo Exp $
###########################################################################
#
# perm.t
#
# RCS Revision: $Revision: 1.1 $
# Date: $Date: 2002/05/14 04:46:34 $
#
# Copyright (c) 2002 Mark Rogaski, mrogaski@cpan.org; all rights reserved.
#
# See the README file included with the
# distribution for license information.
#
# $Log: perm.t,v $
# Revision 1.1  2002/05/14 04:46:34  wendigo
# Initial revision
#
#
###########################################################################
use Test;

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;
}


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;