HealthCheck-Diagnostic-FilePermissions

 view release on metacpan or  search on metacpan

t/HealthCheck-Diagnostic-FilePermissions.t  view on Meta::CPAN

use strict;
use warnings;

use File::Temp qw( tempdir tempfile );
use Test::More;
use Test::Differences;
use HealthCheck::Diagnostic::FilePermissions;

# Add a few fake files that will be used during the tests.
my $filename  = File::Temp->new( CLEANUP => 1 );
my $filename2 = File::Temp->new( CLEANUP => 1 );

# Check that we can use HealthCheck as a class.
my $result = HealthCheck::Diagnostic::FilePermissions->check(
    files  => [ $filename ],
    access => 'x',
);
is $result->{status}, 'CRITICAL',
    'Can use HealthCheck as a class.';
is $result->{info}, qq{Must have permission to execute '$filename'},
    'Info message is correct.';

# Check that we can use HealthCheck with initialized values too.
my $diagnostic = HealthCheck::Diagnostic::FilePermissions->new(
    files  => [ $filename ],
    access => 'rwx',
);
$result = $diagnostic->check;
is $result->{status}, 'CRITICAL',
    'Can use HealthCheck with instance values too.';
is $result->{info}, qq{Must have permission to execute '$filename'},
    'Info message is correct.';

# Check that `check` parameters override the initialized parameters.
$diagnostic = HealthCheck::Diagnostic::FilePermissions->new(
    id                     => 'custom_id',
    label                  => 'Custom Label',
    collapse_single_result => 0,
    files                  => [$filename],
    access                 => '!rwx',
);
$result = $diagnostic->check;
is $result->{status}, 'CRITICAL',
    'Test that the original instance check is invalid.';
eq_or_diff $result, {
    id      => 'custom_id',
    label   => 'Custom Label',
    status  => 'CRITICAL',
    info    => qq{Must not have permission to read and write '$filename'},
    results => [ {
        status => 'CRITICAL',
        info =>
            qq{Must not have permission to read and write '$filename'},
    } ],
}, 'Result is as expected.';
$result = $diagnostic->check(
    id     => 'overridden_id',     # TODO?
    label  => 'Overridden Label',  # TODO?
    files  => [$filename2],
    access => 'rw',
);
eq_or_diff $result, {
    id      => 'custom_id',
    label   => 'Custom Label',
    status  => 'OK',
    info    => qq{Permissions are correct for '$filename2'},



( run in 0.653 second using v1.01-cache-2.11-cpan-6aa56a78535 )