App-ClusterSSH

 view release on metacpan or  search on metacpan

t/15config.t  view on Meta::CPAN

trap {
    $config->write_user_config_file();
};
is( $trap->leaveby, 'die', 'died ok' );
isa_ok( $trap->die, 'App::ClusterSSH::Exception::Config' );
isa_ok( $config,    "App::ClusterSSH::Config" );
is( $trap->die,
    'Unable to create directory $HOME/.clusterssh: File exists' . $/,
    'die message correct'
);
isa_ok( $config, "App::ClusterSSH::Config" );
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
is( $trap->stderr, q{}, 'Expecting no STDERR' );

note('check failure to write default config is caught');
$ENV{HOME} = tempdir( CLEANUP => 1 );
mkdir( $ENV{HOME} . '/.clusterssh' );
mkdir( $ENV{HOME} . '/.clusterssh/config' );
$config = App::ClusterSSH::Config->new();
trap {
    $config->write_user_config_file();
};
is( $trap->leaveby, 'die', 'died ok' );
isa_ok( $trap->die, 'App::ClusterSSH::Exception::Config' );
isa_ok( $config,    "App::ClusterSSH::Config" );
is( $trap->die,
    'Unable to write default $HOME/.clusterssh/config: Is a directory' . $/,
    'die message correct'
);
isa_ok( $config, "App::ClusterSSH::Config" );
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
is( $trap->stderr, q{}, 'Expecting no STDERR' );

note('check .clusterssh errors via load_configs are not fatal');
$ENV{HOME} = tempdir( CLEANUP => 1 );
open( $csshrc, '>', $ENV{HOME} . '/.clusterssh' );
print $csshrc 'should_be_dir_not_file = PROBLEM', $/;
close($csshrc);
$config = App::ClusterSSH::Config->new();
trap {
    $config->load_configs();
};
is( $trap->leaveby, 'return', 'died ok' );
isa_ok( $config, "App::ClusterSSH::Config" );
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
is( $trap->stderr,
    q{Unable to create directory $HOME/.clusterssh: File exists} . $/ . $/,
    'Expecting no STDERR'
);

SKIP: {
    skip "Test inappropriate when running as root", 5 if $< == 0;
    note('move of .csshrc failure');
    $ENV{HOME} = tempdir( CLEANUP => 1 );
    open( $csshrc, '>', $ENV{HOME} . '/.csshrc' );
    print $csshrc "Something", $/;
    close($csshrc);
    open( $csshrc, '>', $ENV{HOME} . '/.csshrc.DISABLED' );
    print $csshrc "Something else", $/;
    close($csshrc);
    chmod( 0666, $ENV{HOME} . '/.csshrc.DISABLED', $ENV{HOME} );
    $config = App::ClusterSSH::Config->new();
    trap {
        $config->write_user_config_file();
    };
    is( $trap->leaveby, 'die', 'died ok' );
    isa_ok( $config, "App::ClusterSSH::Config" );
    is( $trap->stdout, q{}, 'Expecting no STDOUT' );
    is( $trap->stderr, q{}, 'Expecting no STDERR' );
    is( $trap->die,
        q{Unable to create directory $HOME/.clusterssh: Permission denied}
            . $/,
        'Expected die msg ' . $trap->stderr
    );
    chmod( 0755, $ENV{HOME} . '/.csshrc.DISABLED', $ENV{HOME} );
}

note('check failure to write default config is caught');
$ENV{HOME} = tempdir( CLEANUP => 1 );
mkdir( $ENV{HOME} . '/.clusterssh' );
mkdir( $ENV{HOME} . '/.clusterssh/config' );
$config = App::ClusterSSH::Config->new();
trap {
    $config->load_configs();
};
is( $trap->leaveby, 'return', 'returned ok' );
isa_ok( $config, "App::ClusterSSH::Config" );
isa_ok( $config, "App::ClusterSSH::Config" );
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
is( $trap->stderr,
    q{Unable to write default $HOME/.clusterssh/config: Is a directory}
        . $/
        . $/,
    'Expecting no STDERR'
);

note('Checking dump');
$config = App::ClusterSSH::Config->new(
    send_menu_xml_file => $ENV{HOME} . '/.clusterssh/send_menu', );

trap {
    $config->dump();
};
my $expected = qq{# Configuration dump produced by "cssh -d"
auto_close=5
auto_quit=yes
auto_wm_decoration_offsets=no
cols=-1
console=console
console_args=
console_position=
external_cluster_command=
external_command_mode=0600
external_command_pipe=
extra_cluster_file=
extra_tag_file=
fillscreen=no
hide_menu=0
history_height=10
history_width=40
key_addhost=Control-Shift-plus
key_clientname=Alt-n
key_history=Alt-h
key_localname=Alt-l
key_macros_enable=Alt-p
key_paste=Control-v
key_quit=Alt-q
key_retilehosts=Alt-r
key_username=Alt-u
lang=en
macro_hostname=%h
macro_newline=%n
macro_servername=%s
macro_username=%u
macro_version=%v



( run in 1.376 second using v1.01-cache-2.11-cpan-39bf76dae61 )