Merged fix-1022622-ptcd-case-sensitivity

This commit is contained in:
Brian Fraser
2012-12-11 11:45:29 -03:00
4 changed files with 92 additions and 6 deletions

View File

@@ -2470,6 +2470,9 @@ sub new {
value_is_optional => \%value_is_optional, value_is_optional => \%value_is_optional,
any_value_is_true => \%any_value_is_true, any_value_is_true => \%any_value_is_true,
base_path => \%base_path, base_path => \%base_path,
ignore_case => exists $args{ignore_case}
? $args{ignore_case}
: 1,
}; };
return bless $self, $class; return bless $self, $class;
@@ -2496,6 +2499,7 @@ sub diff {
my $config0 = $configs->[0]; my $config0 = $configs->[0];
my $last_config = @$configs - 1; my $last_config = @$configs - 1;
my $vars = $self->_get_shared_vars(%args); my $vars = $self->_get_shared_vars(%args);
my $ignore_case = $self->{ignore_case};
my $diffs; my $diffs;
VARIABLE: VARIABLE:
@@ -2520,7 +2524,9 @@ sub diff {
next CONFIG if $val0 == $valN; next CONFIG if $val0 == $valN;
} }
else { else {
next CONFIG if $val0 eq $valN; next CONFIG if $ignore_case
? lc($val0) eq lc($valN)
: $val0 eq $valN;
if ( $config0->format() ne $configN->format() ) { if ( $config0->format() ne $configN->format() ) {
if ( $any_value_is_true->{$var} ) { if ( $any_value_is_true->{$var} ) {
@@ -4332,6 +4338,7 @@ sub main {
my $trp = new TextResultSetParser(); my $trp = new TextResultSetParser();
my $config_cmp = new MySQLConfigComparer( my $config_cmp = new MySQLConfigComparer(
ignore_variables => $o->get('ignore-variables'), ignore_variables => $o->get('ignore-variables'),
ignore_case => $o->get('ignore-case'),
); );
my %common_modules = ( my %common_modules = (
DSNParser => $dp, DSNParser => $dp,
@@ -4574,6 +4581,12 @@ L<"SYNOPSIS"> and usage information for details.
Prompt for a password when connecting to MySQL. Prompt for a password when connecting to MySQL.
=item --[no]ignore-case
default: yes
Compare the variables case-insensitively.
=item --charset =item --charset
short form: -A; type: string short form: -A; type: string

View File

@@ -126,6 +126,9 @@ sub new {
value_is_optional => \%value_is_optional, value_is_optional => \%value_is_optional,
any_value_is_true => \%any_value_is_true, any_value_is_true => \%any_value_is_true,
base_path => \%base_path, base_path => \%base_path,
ignore_case => exists $args{ignore_case}
? $args{ignore_case}
: 1,
}; };
return bless $self, $class; return bless $self, $class;
@@ -172,6 +175,7 @@ sub diff {
my $config0 = $configs->[0]; my $config0 = $configs->[0];
my $last_config = @$configs - 1; my $last_config = @$configs - 1;
my $vars = $self->_get_shared_vars(%args); my $vars = $self->_get_shared_vars(%args);
my $ignore_case = $self->{ignore_case};
# Compare variables from first config (config0) to other configs (configN). # Compare variables from first config (config0) to other configs (configN).
my $diffs; my $diffs;
@@ -197,7 +201,9 @@ sub diff {
next CONFIG if $val0 == $valN; next CONFIG if $val0 == $valN;
} }
else { else {
next CONFIG if $val0 eq $valN; next CONFIG if $ignore_case
? lc($val0) eq lc($valN)
: $val0 eq $valN;
# Special rules apply when comparing different inputs/formats, # Special rules apply when comparing different inputs/formats,
# e.g. when comparing an option file to SHOW VARIABLES. This # e.g. when comparing an option file to SHOW VARIABLES. This

View File

@@ -392,6 +392,39 @@ $c2 = new MySQLConfig(
"Values are the same regardless of quoting" "Values are the same regardless of quoting"
) or diag(Dumper($diff)); ) or diag(Dumper($diff));
} }
# #############################################################################
# Case insensitivity
# #############################################################################
$c1 = new MySQLConfig(
result_set => [['binlog_format', 'MIXED']],
format => 'option_file',
);
$c2 = new MySQLConfig(
result_set => [['binlog_format', 'mixed']],
format => 'option_file',
);
is_deeply(
diff($c1, $c2),
undef,
"Case insensitivity is on by default"
);
my $case_cc = MySQLConfigComparer->new( ignore_case => undef, );
is_deeply(
$case_cc->diff(configs => [$c1, $c2]),
{
binlog_format => [
'MIXED',
'mixed'
]
},
"..but can be turned off"
);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################

View File

@@ -26,11 +26,9 @@ if ( !$master_dbh ) {
elsif ( !$slave_dbh ) { elsif ( !$slave_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave'; plan skip_all => 'Cannot connect to sandbox slave';
} }
else {
plan tests => 13;
}
my $cnf = '/tmp/12345/my.sandbox.cnf'; my $cnf = '/tmp/12345/my.sandbox.cnf';
my $samples = "$trunk/t/pt-config-diff/samples/";
my $output; my $output;
my $retval; my $retval;
@@ -162,8 +160,44 @@ like(
"Config diff output" "Config diff output"
); );
# #############################################################################
# Case insensitivity
# #############################################################################
use File::Spec;
$output = output(
sub { $retval = pt_config_diff::main(
File::Spec->catfile($samples, "case1.cnf"),
File::Spec->catfile($samples, "case2.cnf"),
) },
stderr => 1,
);
is(
$output,
"",
"Case-insensitive by default, finds no diffs"
);
$output = output(
sub { $retval = pt_config_diff::main(
File::Spec->catfile($samples, "case1.cnf"),
File::Spec->catfile($samples, "case2.cnf"),
'--no-ignore-case',
) },
stderr => 1,
);
like(
$output,
qr/binlog_format\s+genlog\s+GENLOG/,
"With case-insensitivity turned off, finds one diff"
);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;
done_testing;