Improve MasterSlave::check_recursion_method() tests.

This commit is contained in:
Daniel Nichter
2013-10-02 11:15:58 -07:00
parent 2411cf6880
commit b0cacd15f4
2 changed files with 42 additions and 16 deletions

View File

@@ -32,8 +32,18 @@ use constant PTDEBUG => $ENV{PTDEBUG} || 0;
sub check_recursion_method { sub check_recursion_method {
my ($methods) = @_; my ($methods) = @_;
if ( @$methods != 1 ) { # Check that each method is valid.
if ( grep({ !m/processlist|hosts/i } @$methods) foreach my $method ( @$methods ) {
die "Invalid recursion method: " . ($method || 'undef') . "\n"
unless $method && $method =~ m/^(?:processlist$|hosts$|none$|cluster|dsn=)/i;
}
# Check for invalid combination of methods.
if ( @$methods > 1 ) {
if ( grep( { m/none/ } @$methods) && grep( {! m/none/ } @$methods) ) {
die "--recursion-method=none cannot be combined with other methods\n";
}
elsif ( grep({ !m/processlist|hosts/i } @$methods)
&& $methods->[0] !~ /^dsn=/i ) && $methods->[0] !~ /^dsn=/i )
{ {
die "Invalid combination of recursion methods: " die "Invalid combination of recursion methods: "
@@ -41,11 +51,8 @@ sub check_recursion_method {
. "Only hosts and processlist may be combined.\n" . "Only hosts and processlist may be combined.\n"
} }
} }
else {
my ($method) = @$methods; return;
die "Invalid recursion method: " . ( $method || 'undef' )
unless $method && $method =~ m/^(?:processlist$|hosts$|none$|dsn=)/i;
}
} }
sub new { sub new {

View File

@@ -11,10 +11,6 @@ use warnings FATAL => 'all';
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Test::More; use Test::More;
if ( !$ENV{SLOW_TESTS} ) {
plan skip_all => "lib/MasterSlave.t is a top 5 slowest file; set SLOW_TESTS=1 to enable it.";
}
use MasterSlave; use MasterSlave;
use DSNParser; use DSNParser;
use VersionParser; use VersionParser;
@@ -709,28 +705,51 @@ is(
# ############################################################################ # ############################################################################
# Invalid recursion methods are caught # Invalid recursion methods are caught
# ############################################################################ # ############################################################################
local $EVAL_ERROR;
eval { eval {
MasterSlave::check_recursion_method([qw(stuff)]) MasterSlave::check_recursion_method([qw(stuff)])
}; };
like( like(
$EVAL_ERROR, $EVAL_ERROR,
qr/Invalid recursion method: stuff/, qr/Invalid recursion method: stuff/,
"--recursion-method stuff causes error" "--recursion-method stuff causes error"
); );
local $EVAL_ERROR;
eval { eval {
MasterSlave::check_recursion_method([qw(processlist stuff)]) MasterSlave::check_recursion_method([qw(processlist stuff)])
}; };
like( like(
$EVAL_ERROR, $EVAL_ERROR,
qr/Invalid combination of recursion methods: processlist, stuff/, qr/Invalid recursion method: stuff/,
"--recursion-method processlist,stuff causes error", "--recursion-method processlist,stuff causes error",
); );
eval {
MasterSlave::check_recursion_method([qw(none hosts)])
};
like(
$EVAL_ERROR,
qr/none cannot be combined with other methods/,
"--recursion-method none,hosts"
);
eval {
MasterSlave::check_recursion_method([qw(cluster none)])
};
like(
$EVAL_ERROR,
qr/none cannot be combined with other methods/,
"--recursion-method cluster,none"
);
eval {
MasterSlave::check_recursion_method([qw(none none)])
};
like(
$EVAL_ERROR,
qr/Invalid combination of recursion methods: none, none/,
"--recursion-method none,none"
);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################