2011-08-31 21:01:12 +01:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2015-11-28 12:38:39 +00:00
|
|
|
# Force use of English in tests for the moment, for those users that
|
|
|
|
# have a different locale set, since errors are hardcoded below
|
|
|
|
use POSIX qw(setlocale locale_h);
|
|
|
|
setlocale( LC_ALL, "C" );
|
|
|
|
|
2011-08-31 21:01:12 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
use Readonly;
|
|
|
|
|
2014-07-04 21:41:52 +01:00
|
|
|
package App::ClusterSSH::Config;
|
|
|
|
|
|
|
|
sub new {
|
2014-09-19 23:33:08 +01:00
|
|
|
my ( $class, %args ) = @_;
|
2014-07-04 21:41:52 +01:00
|
|
|
my $self = {%args};
|
|
|
|
return bless $self, $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
package main;
|
|
|
|
|
2013-04-15 21:56:19 +01:00
|
|
|
BEGIN {
|
|
|
|
use_ok("App::ClusterSSH::Helper") || BAIL_OUT('failed to use module');
|
|
|
|
}
|
2011-08-31 21:01:12 +01:00
|
|
|
|
|
|
|
my $helper;
|
|
|
|
|
|
|
|
$helper = App::ClusterSSH::Helper->new();
|
|
|
|
isa_ok( $helper, 'App::ClusterSSH::Helper' );
|
|
|
|
|
2014-07-02 22:39:36 +01:00
|
|
|
my $script;
|
|
|
|
|
|
|
|
trap {
|
|
|
|
$script = $helper->script;
|
|
|
|
};
|
|
|
|
is( $trap->leaveby, 'die', 'returned ok' );
|
|
|
|
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
|
|
|
is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
|
|
|
is( $trap->die, 'No configuration provided or in wrong format', 'no config' );
|
|
|
|
|
|
|
|
trap {
|
|
|
|
$script = $helper->script( something => 'nothing' );
|
|
|
|
};
|
|
|
|
is( $trap->leaveby, 'die', 'returned ok' );
|
|
|
|
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
|
|
|
is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
|
|
|
is( $trap->die, 'No configuration provided or in wrong format',
|
|
|
|
'bad format' );
|
|
|
|
|
2014-07-04 21:41:52 +01:00
|
|
|
my $mock_config = App::ClusterSSH::Config->new();
|
2014-07-02 22:39:36 +01:00
|
|
|
trap {
|
2014-09-19 23:33:08 +01:00
|
|
|
$script = $helper->script($mock_config);
|
2014-07-02 22:39:36 +01:00
|
|
|
};
|
|
|
|
is( $trap->leaveby, 'die', 'returned ok' );
|
|
|
|
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
|
|
|
|
|
|
|
# ignore stderr here as it will complain about missing xxx_arg var
|
|
|
|
#is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
|
|
|
is( $trap->die, q{Config 'comms' not provided}, 'missing arg' );
|
|
|
|
|
2014-07-04 21:41:52 +01:00
|
|
|
$mock_config->{comms} = 'method';
|
2014-07-02 22:39:36 +01:00
|
|
|
trap {
|
2014-09-19 23:33:08 +01:00
|
|
|
$script = $helper->script($mock_config);
|
2014-07-02 22:39:36 +01:00
|
|
|
};
|
2014-09-19 23:33:08 +01:00
|
|
|
is( $trap->leaveby, 'die', 'returned ok' );
|
|
|
|
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
|
|
|
is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
|
|
|
is( $trap->die, q{Config 'method' not provided}, 'missing arg' );
|
2014-07-02 22:39:36 +01:00
|
|
|
|
2014-07-04 21:41:52 +01:00
|
|
|
$mock_config->{method} = 'binary';
|
2014-07-02 22:39:36 +01:00
|
|
|
trap {
|
2014-09-19 23:33:08 +01:00
|
|
|
$script = $helper->script($mock_config);
|
2014-07-02 22:39:36 +01:00
|
|
|
};
|
|
|
|
is( $trap->leaveby, 'die', 'returned ok' );
|
|
|
|
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
|
|
|
is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
|
|
|
is( $trap->die, q{Config 'method_args' not provided}, 'missing arg' );
|
|
|
|
|
2014-07-04 21:41:52 +01:00
|
|
|
$mock_config->{method_args} = 'rubbish';
|
2014-09-19 23:33:08 +01:00
|
|
|
$mock_config->{command} = 'echo';
|
|
|
|
$mock_config->{auto_close} = 5;
|
2014-07-02 22:39:36 +01:00
|
|
|
trap {
|
2014-09-19 23:33:08 +01:00
|
|
|
$script = $helper->script($mock_config);
|
2014-07-02 22:39:36 +01:00
|
|
|
};
|
|
|
|
is( $trap->leaveby, 'return', 'returned ok' );
|
2014-09-19 23:33:08 +01:00
|
|
|
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
|
|
|
is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
|
|
|
is( $trap->die, undef, 'not died' );
|
2014-07-02 22:39:36 +01:00
|
|
|
|
|
|
|
trap {
|
2014-09-19 23:33:08 +01:00
|
|
|
eval {$script};
|
2014-07-02 22:39:36 +01:00
|
|
|
};
|
|
|
|
is( $trap->leaveby, 'return', 'returned ok' );
|
2014-09-19 23:33:08 +01:00
|
|
|
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
|
|
|
|
is( $trap->stderr, q{}, 'Expecting no STDERR' );
|
|
|
|
is( $trap->die, undef, 'not died' );
|
2011-08-31 21:01:12 +01:00
|
|
|
|
|
|
|
done_testing();
|