clusterssh/t/20helper.t

106 lines
2.9 KiB
Perl
Raw Permalink Normal View History

use strict;
use warnings;
# 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" );
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 {
my ( $class, %args ) = @_;
2014-07-04 21:41:52 +01:00
my $self = {%args};
return bless $self, $class;
}
package main;
BEGIN {
use_ok("App::ClusterSSH::Helper") || BAIL_OUT('failed to use module');
}
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 {
$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 {
$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' 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 {
$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';
$mock_config->{command} = 'echo';
$mock_config->{auto_close} = 5;
2014-07-02 22:39:36 +01:00
trap {
$script = $helper->script($mock_config);
2014-07-02 22:39:36 +01:00
};
is( $trap->leaveby, 'return', 'returned ok' );
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 {
eval {$script};
2014-07-02 22:39:36 +01:00
};
is( $trap->leaveby, 'return', 'returned ok' );
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
is( $trap->stderr, q{}, 'Expecting no STDERR' );
is( $trap->die, undef, 'not died' );
done_testing();