Further work on config module

This commit is contained in:
Duncan Ferguson 2011-07-11 21:00:43 +01:00
parent 3fedc40eaf
commit 5fb98fc796
4 changed files with 47 additions and 5 deletions

View file

@ -141,13 +141,13 @@ sub parse_config_file {
my ( $key, $value ) = ( $1, $2 ); my ( $key, $value ) = ( $1, $2 );
if ( defined $key && defined $value ) { if ( defined $key && defined $value ) {
$read_config{$key} = $value; $read_config{$key} = $value;
logmsg( 3, "$key=$value" ); $self->debug( 3, "$key=$value" );
} }
} }
close(CFG); close(CFG);
# tidy up entries, just in case # tidy up entries, just in case
$read_config{terminal_font} =~ s/['"]//g; $read_config{terminal_font} =~ s/['"]//g if($read_config{terminal_font});
$self->validate_args(%read_config); $self->validate_args(%read_config);
} }

View file

@ -81,6 +81,7 @@ Readonly::Hash my %default_config => {
my %expected = %default_config; my %expected = %default_config;
is_deeply( $config, \%expected, 'default config is correct' ); is_deeply( $config, \%expected, 'default config is correct' );
$config = App::ClusterSSH::Config->new();
trap { trap {
$config = $config->validate_args( $config = $config->validate_args(
whoops => 'not there', whoops => 'not there',
@ -97,6 +98,7 @@ is_deeply(
[ 'doesnt_exist', 'whoops' ], [ 'doesnt_exist', 'whoops' ],
'Picked up unknown config array' 'Picked up unknown config array'
); );
isa_ok( $config, "App::ClusterSSH::Config" );
$expected{extra_cluster_file} = '/etc/filename'; $expected{extra_cluster_file} = '/etc/filename';
$expected{rsh_args} = 'some args'; $expected{rsh_args} = 'some args';
@ -109,8 +111,10 @@ trap {
); );
}; };
is( $trap->die, undef, 'validated ok' ); is( $trap->die, undef, 'validated ok' );
isa_ok( $config, "App::ClusterSSH::Config" );
is_deeply( $config, \%expected, 'default config is correct' ); is_deeply( $config, \%expected, 'default config is correct' );
$config = App::ClusterSSH::Config->new();
%expected = %default_config; %expected = %default_config;
my $file = "$Bin/$Script.doesntexist"; my $file = "$Bin/$Script.doesntexist";
@ -123,4 +127,36 @@ is( $trap->die,
'got correct error message' 'got correct error message'
); );
$file = "$Bin/$Script.file1";
note("using $file");
$config = App::ClusterSSH::Config->new();
%expected = %default_config;
$expected{screen_reserve_left}=100;
$expected{screen_reserve_right}=100;
$expected{screen_reserve_top}=100;
$expected{screen_reserve_bottom}=160;
trap {
$config = $config->parse_config_file( $file, );
};
is( $trap->leaveby, 'return', 'returned ok' );
is( $trap->die, undef, 'returned ok' );
isa_ok( $config, "App::ClusterSSH::Config" );
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
is( $trap->stderr, q{}, 'Expecting no STDERR' );
is_deeply( $config, \%expected, 'amended config is correct' );
$file = "$Bin/$Script.file2";
note("using $file");
$config = App::ClusterSSH::Config->new();
%expected = %default_config;
trap {
$config = $config->parse_config_file( $file, );
};
is( $trap->leaveby, 'die', 'died ok' );
isa_ok( $trap->die, 'App::ClusterSSH::Exception::Config' );
isa_ok( $config, "App::ClusterSSH::Config" );
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
is( $trap->stderr, q{}, 'Expecting no STDERR' );
is_deeply( $config, \%expected, 'amended config is correct' );
done_testing(); done_testing();

View file

@ -1,3 +1,7 @@
comms=telnet screen_reserve_top = 100
method=telnet screen_reserve_bottom = 160
telnet=/usr/bin/telnet
screen_reserve_left = 100
screen_reserve_right = 100

2
t/15config.t.file2 Normal file
View file

@ -0,0 +1,2 @@
missing=what
rubbish=here