2011-11-18 22:44:08 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use FindBin qw($Bin $Script);
|
|
|
|
use lib "$Bin/../lib";
|
|
|
|
|
|
|
|
use Test::More;
|
|
|
|
use Test::Trap;
|
|
|
|
use File::Which qw(which);
|
|
|
|
use File::Temp qw(tempdir);
|
2013-02-14 23:34:06 +00:00
|
|
|
use English '-no_match_vars';
|
2011-11-18 22:44:08 +00:00
|
|
|
|
|
|
|
use Readonly;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use_ok("App::ClusterSSH::Cluster") || BAIL_OUT('failed to use module');
|
|
|
|
}
|
|
|
|
|
|
|
|
my $cluster1 = App::ClusterSSH::Cluster->new();
|
|
|
|
isa_ok( $cluster1, 'App::ClusterSSH::Cluster' );
|
|
|
|
|
|
|
|
my $cluster2 = App::ClusterSSH::Cluster->new();
|
|
|
|
isa_ok( $cluster2, 'App::ClusterSSH::Cluster' );
|
|
|
|
|
2011-11-21 18:02:26 +00:00
|
|
|
my @expected = ( 'pete', 'jo', 'fred' );
|
2011-11-18 22:44:08 +00:00
|
|
|
|
2011-11-21 18:02:26 +00:00
|
|
|
$cluster1->register_tag( 'people', @expected );
|
|
|
|
|
2011-11-24 21:47:37 +00:00
|
|
|
my @got = $cluster2->get_tag('people');
|
|
|
|
|
2013-02-14 23:34:06 +00:00
|
|
|
is_deeply( \@got, \@expected, 'Shared cluster object' );
|
2011-11-21 18:02:26 +00:00
|
|
|
|
|
|
|
# should pass without issue
|
|
|
|
trap {
|
|
|
|
$cluster1->read_cluster_file( $Bin . '/30cluster.doesnt exist' );
|
|
|
|
};
|
2013-02-14 23:34:06 +00:00
|
|
|
is( !$trap, '', 'coped with missing file ok' );
|
2011-11-21 18:02:26 +00:00
|
|
|
isa_ok( $cluster1, 'App::ClusterSSH::Cluster' );
|
|
|
|
|
2013-02-14 23:34:06 +00:00
|
|
|
# no point running this test as root since root cannot be blocked
|
|
|
|
# from accessing the file
|
|
|
|
if ( $EUID != 0 ) {
|
|
|
|
my $no_read = $Bin . '/30cluster.cannot_read';
|
|
|
|
chmod 0000, $no_read;
|
|
|
|
trap {
|
|
|
|
$cluster1->read_cluster_file($no_read);
|
|
|
|
};
|
|
|
|
chmod 0644, $no_read;
|
|
|
|
isa_ok( $trap->die, 'App::ClusterSSH::Exception::Cluster' );
|
|
|
|
is( $trap->die,
|
|
|
|
"Unable to read file $no_read: Permission denied",
|
|
|
|
'Error on reading an existing file ok'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pass('Cannot test for lack of read access when run as root');
|
|
|
|
}
|
2011-11-21 18:02:26 +00:00
|
|
|
|
|
|
|
@expected = ('host1');
|
|
|
|
$cluster1->read_cluster_file( $Bin . '/30cluster.file1' );
|
2011-11-24 21:47:37 +00:00
|
|
|
@got = $cluster1->get_tag('tag1');
|
|
|
|
is_deeply( \@got, \@expected, 'read simple file OK' );
|
2011-11-21 18:02:26 +00:00
|
|
|
|
|
|
|
@expected = ('host1');
|
|
|
|
$cluster1->read_cluster_file( $Bin . '/30cluster.file2' );
|
2013-02-14 23:34:06 +00:00
|
|
|
@got = $cluster1->get_tag('tag1');
|
|
|
|
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
2011-11-21 18:02:26 +00:00
|
|
|
|
|
|
|
@expected = ('host2');
|
2013-02-14 23:34:06 +00:00
|
|
|
@got = $cluster1->get_tag('tag2');
|
|
|
|
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
2011-11-21 18:02:26 +00:00
|
|
|
|
|
|
|
@expected = ( 'host3', 'host4' );
|
2013-02-14 23:34:06 +00:00
|
|
|
@got = $cluster1->get_tag('tag3');
|
|
|
|
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
2011-11-18 22:44:08 +00:00
|
|
|
|
|
|
|
done_testing();
|