mirror of
https://github.com/duncs/clusterssh.git
synced 2025-07-03 01:43:25 +00:00
Start of tags file handling
Refactor file loading code into one place since it should all work in a similar way. Added in tag functionality. - Cluster files are: tag host host host host - Tag files are: host tag tag tag Yes to add in remainder of code to load in the files automatically
This commit is contained in:
parent
2ab7527633
commit
b2ba4daa46
8 changed files with 255 additions and 92 deletions
|
@ -139,9 +139,9 @@ my $file = "$Bin/$Script.doesntexist";
|
|||
trap {
|
||||
$config = $config->parse_config_file( $file, );
|
||||
};
|
||||
isa_ok( $trap->die, 'App::ClusterSSH::Exception::Config' );
|
||||
isa_ok( $trap->die, 'App::ClusterSSH::Exception::LoadFile' );
|
||||
is( $trap->die,
|
||||
"File $file does not exist or cannot be read" . $/,
|
||||
"Unable to read file $file: No such file or directory" . $/,
|
||||
'got correct error message'
|
||||
);
|
||||
|
||||
|
|
|
@ -22,13 +22,16 @@ isa_ok( $cluster1, 'App::ClusterSSH::Cluster' );
|
|||
my $cluster2 = App::ClusterSSH::Cluster->new();
|
||||
isa_ok( $cluster2, 'App::ClusterSSH::Cluster' );
|
||||
|
||||
my @expected = ( 'pete', 'jo', 'fred' );
|
||||
my %expected = ( people => [ 'fred', 'jo', 'pete', ] );
|
||||
|
||||
$cluster1->register_tag( 'people', @expected );
|
||||
$cluster1->register_tag( 'people', @{ $expected{people} } );
|
||||
|
||||
my @got = $cluster2->get_tag('people');
|
||||
is_deeply( \@got, \@{ $expected{people} }, 'Shared cluster object' )
|
||||
or diag explain @got;
|
||||
my %got = $cluster2->dump_tags;
|
||||
|
||||
is_deeply( \@got, \@expected, 'Shared cluster object' );
|
||||
is_deeply( \%got, \%expected, 'Shared cluster object' ) or diag explain %got;
|
||||
|
||||
# should pass without issue
|
||||
trap {
|
||||
|
@ -46,7 +49,7 @@ if ( $EUID != 0 ) {
|
|||
$cluster1->read_cluster_file($no_read);
|
||||
};
|
||||
chmod 0644, $no_read;
|
||||
isa_ok( $trap->die, 'App::ClusterSSH::Exception::Cluster' );
|
||||
isa_ok( $trap->die, 'App::ClusterSSH::Exception::LoadFile' );
|
||||
is( $trap->die,
|
||||
"Unable to read file $no_read: Permission denied",
|
||||
'Error on reading an existing file ok'
|
||||
|
@ -56,22 +59,38 @@ else {
|
|||
pass('Cannot test for lack of read access when run as root');
|
||||
}
|
||||
|
||||
@expected = ('host1');
|
||||
$expected{tag1} = ['host1'];
|
||||
$cluster1->read_cluster_file( $Bin . '/30cluster.file1' );
|
||||
@got = $cluster1->get_tag('tag1');
|
||||
is_deeply( \@got, \@expected, 'read simple file OK' );
|
||||
test_expected( 'file 1', %expected );
|
||||
|
||||
@expected = ('host1');
|
||||
$expected{tag2} = [ 'host2', ];
|
||||
$expected{tag3} = [ 'host3', 'host4' ];
|
||||
$cluster1->read_cluster_file( $Bin . '/30cluster.file2' );
|
||||
@got = $cluster1->get_tag('tag1');
|
||||
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
||||
test_expected( 'file 2', %expected );
|
||||
|
||||
@expected = ('host2');
|
||||
@got = $cluster1->get_tag('tag2');
|
||||
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
||||
|
||||
@expected = ( 'host3', 'host4' );
|
||||
@got = $cluster1->get_tag('tag3');
|
||||
is_deeply( \@got, \@expected, 'read more complex file OK' );
|
||||
$expected{tag10} = [ 'host10', 'host20', 'host30' ];
|
||||
$expected{tag20} = [ 'host10', ];
|
||||
$expected{tag30} = [ 'host10', ];
|
||||
$expected{tag40} = [ 'host20', 'host30', ];
|
||||
$expected{tag50} = [ 'host30', ];
|
||||
$cluster1->read_tag_file( $Bin . '/30cluster.tag1' );
|
||||
test_expected( 'tag 1', %expected );
|
||||
|
||||
done_testing();
|
||||
|
||||
sub test_expected {
|
||||
my ( $test, %expected ) = @_;
|
||||
|
||||
foreach my $key ( keys %expected ) {
|
||||
my @got = $cluster2->get_tag($key);
|
||||
is_deeply(
|
||||
\@got,
|
||||
\@{ $expected{$key} },
|
||||
'file ' . $test . ' get_tag on: '. $key
|
||||
) or diag explain @got;
|
||||
}
|
||||
|
||||
my %got = $cluster1->dump_tags;
|
||||
is_deeply( \%got, \%expected, 'file ' . $test . ' dump_tags' )
|
||||
or diag explain %got;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue