mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 13:40:07 +00:00
Fix and test resource_diff().
This commit is contained in:
@@ -1466,6 +1466,7 @@ no Lmo;
|
||||
{
|
||||
package Percona::WebAPI::Util;
|
||||
|
||||
use JSON;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
use Percona::WebAPI::Representation;
|
||||
@@ -1478,8 +1479,12 @@ sub resource_diff {
|
||||
my ($x, $y) = @_;
|
||||
return 0 if !$x && !$y;
|
||||
return 1 if ($x && !$y) || (!$x && $y);
|
||||
return md5_hex(Percona::WebAPI::Representation::as_json($x))
|
||||
ne md5_hex(Percona::WebAPI::Representation::as_json($y));
|
||||
my $json = JSON->new->canonical([1]); # avoid hash key sort diffs
|
||||
my $x_hex = md5_hex(
|
||||
Percona::WebAPI::Representation::as_json($x, json => $json));
|
||||
my $y_hex = md5_hex(
|
||||
Percona::WebAPI::Representation::as_json($y, json => $json));
|
||||
return $x_hex eq $y_hex ? 0 : 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@@ -20,6 +20,7 @@
|
||||
{
|
||||
package Percona::WebAPI::Util;
|
||||
|
||||
use JSON;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
use Percona::WebAPI::Representation;
|
||||
@@ -32,8 +33,12 @@ sub resource_diff {
|
||||
my ($x, $y) = @_;
|
||||
return 0 if !$x && !$y;
|
||||
return 1 if ($x && !$y) || (!$x && $y);
|
||||
return md5_hex(Percona::WebAPI::Representation::as_json($x))
|
||||
ne md5_hex(Percona::WebAPI::Representation::as_json($y));
|
||||
my $json = JSON->new->canonical([1]); # avoid hash key sort diffs
|
||||
my $x_hex = md5_hex(
|
||||
Percona::WebAPI::Representation::as_json($x, json => $json));
|
||||
my $y_hex = md5_hex(
|
||||
Percona::WebAPI::Representation::as_json($y, json => $json));
|
||||
return $x_hex eq $y_hex ? 0 : 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@@ -45,7 +45,18 @@ $y->options->{spool} = '/var/lib/spool';
|
||||
is(
|
||||
resource_diff($x, $y),
|
||||
1,
|
||||
"Diff"
|
||||
"Big diff in 1 attrib"
|
||||
);
|
||||
|
||||
# Restore this...
|
||||
$y->options->{spool} = '/var/spool';
|
||||
# Change this...
|
||||
$y->options->{ts} = '101';
|
||||
|
||||
is(
|
||||
resource_diff($x, $y),
|
||||
1,
|
||||
"Small diff in 1 attrib"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
|
Reference in New Issue
Block a user