mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-31 01:24:35 +02:00
60 lines
1.7 KiB
Perl
60 lines
1.7 KiB
Perl
use strict;
|
|
use warnings;
|
|
|
|
package MockOptions;
|
|
sub new { bless { extra_arguments => [ ], option_results => {}, default => {}, custom => {} }, shift }
|
|
sub add_options { }
|
|
sub add_help { }
|
|
|
|
package MockOutput;
|
|
sub new { bless {}, shift }
|
|
sub add_option_msg { }
|
|
sub output_add { }
|
|
sub option_exit { }
|
|
|
|
package main;
|
|
|
|
# Unit tests to check that the plugin constructs a valid redis-cli command with the corresponding parameters
|
|
|
|
use Test2::V0;
|
|
use FindBin;
|
|
use lib "$FindBin::RealBin/../../../src";
|
|
use apps::redis::sentinel::mode::listclusters;
|
|
use apps::redis::sentinel::custom::cli;
|
|
|
|
my $capture;
|
|
my $options = MockOptions->new();
|
|
my $output = MockOutput->new();
|
|
|
|
my $plugin_misc = mock 'centreon::plugins::misc';
|
|
|
|
$plugin_misc->override('execute' => sub {
|
|
my (%options) = @_;
|
|
$capture = "$options{command} $options{command_options}";
|
|
});
|
|
|
|
my $plugin = apps::redis::sentinel::mode::listclusters->new(
|
|
options => $options,
|
|
output => $output,
|
|
);
|
|
$plugin->init(%$options);
|
|
|
|
my $cust = apps::redis::sentinel::custom::cli->new(
|
|
options => $options,
|
|
output => $output,
|
|
);
|
|
$options->{custom} = $cust;
|
|
|
|
foreach my $test ({ title => 'Test --key parameter', param => { key => 'private.key'}, expect => q(--key 'private.key') },
|
|
{ title => 'Test --cert parameter', param => { cert => 'dummy.crt'}, expect => q(--cert 'dummy.crt') },
|
|
{ title => 'Test --cacert parameter', param => { cacert => 'ca.crt'}, expect => q(--cacert 'ca.crt') },) {
|
|
$cust->set_options(option_results => $test->{param} );
|
|
$cust->check_options();
|
|
|
|
$plugin->manage_selection(%$options);
|
|
|
|
ok($capture =~ /$test->{expect}/, "$test->{title}");
|
|
}
|
|
|
|
done_testing;
|