MT#18089 replace is_deeply by Data::Compare in controller

Change-Id: I873e1351694f6e9f2783bde2ad8ada71ae04276a
changes/88/4788/3
Gerhard Jungwirth 10 years ago
parent 45b0f85705
commit a221ae2aa0

1
debian/control vendored

@ -24,6 +24,7 @@ Depends: gettext,
libconvert-ascii85-perl,
libcrypt-rc4-perl,
libcrypt-rijndael-perl,
libdata-compare-perl,
libdata-hal-perl,
libdata-printer-perl,
libdata-record-perl,

@ -5,7 +5,6 @@ BEGIN { use base 'Catalyst::Controller'; }
use HTML::Entities;
use JSON qw(decode_json encode_json);
use URI::Escape qw(uri_unescape);
use Test::More;
use Data::Dumper;
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Utils::Contract;
@ -869,7 +868,7 @@ sub preferences_edit :Chained('preferences_base') :PathPart('edit') :Args(0) {
my $new_auth_prefs = {};
NGCP::Panel::Utils::Preferences::get_peer_auth_params(
$c, $prov_subscriber, $new_auth_prefs);
unless(is_deeply($old_auth_prefs, $new_auth_prefs)) {
unless(compare($old_auth_prefs, $new_auth_prefs)) {
try {
if(!NGCP::Panel::Utils::Preferences::is_peer_auth_active($c, $old_auth_prefs) &&
@ -2532,7 +2531,7 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
sn => $subscriber->primary_number->sn,
};
if($subscriber->provisioning_voip_subscriber->admin &&
!is_deeply($old_number, $new_number)) {
!compare($old_number, $new_number)) {
foreach my $sub($c->stash->{subscribers}->all, ( $c->stash->{pbx_groups} ? $c->stash->{pbx_groups}->all : () )) {
my $base_pref = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'cloud_pbx_base_cli',

@ -1,16 +1,18 @@
package NGCP::Panel::Utils::Generic;
use strict;
use warnings;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = ();
@EXPORT_OK = qw(is_int is_integer is_decimal merge);
%EXPORT_TAGS = ( DEFAULT => [qw(&is_int &is_integer &is_decimal &merge)],
all => [qw(&is_int &is_integer &is_decimal &merge)]);
@EXPORT_OK = qw(is_int is_integer is_decimal merge compare);
%EXPORT_TAGS = ( DEFAULT => [qw(&is_int &is_integer &is_decimal &merge &compare)],
all => [qw(&is_int &is_integer &is_decimal &merge &compare)]);
use Hash::Merge;
use Data::Compare qw//;
sub is_int {
my $val = shift;
@ -38,4 +40,9 @@ sub merge {
return Hash::Merge::merge($a, $b);
}
# 0 if different, 1 if equal
sub compare {
return Data::Compare::Compare(@_);
}
1;

@ -0,0 +1,84 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Data::Compare;
use JSON;
my $origin = {
num => 123,
string => "foobar",
true_val => !!1,
false_val => !1,
json_true => JSON::true,
json_false => JSON::false,
};
my $same = {
num => 123,
string => "foobar",
true_val => !!1,
false_val => !1,
json_true => JSON::true,
json_false => JSON::false,
};
my $diff_num = {
num => 999,
string => "foobar",
true_val => !!1,
false_val => !1,
json_true => JSON::true,
json_false => JSON::false,
};
my $diff_string = {
num => 123,
string => "aaaa",
true_val => !!1,
false_val => !1,
json_true => JSON::true,
json_false => JSON::false,
};
my $diff_bool = {
num => 123,
string => "foobar",
true_val => !1,
false_val => !!1,
json_true => JSON::true,
json_false => JSON::false,
};
my $diff_json = {
num => 123,
string => "foobar",
true_val => !1,
false_val => !!1,
json_true => JSON::false,
json_false => JSON::true,
};
diag("Test::More only checks using is_deeply");
is_deeply($same, $origin);
TODO: {
local $TODO = "The following tests must fail";
is_deeply($diff_num, $origin);
is_deeply($diff_string, $origin);
is_deeply($diff_bool, $origin);
is_deeply($diff_json, $origin);
}
diag("The same checks, this time using Data::Compare");
ok(Data::Compare::Compare($same, $origin));
ok(!Data::Compare::Compare($diff_num, $origin));
ok(!Data::Compare::Compare($diff_string, $origin));
ok(!Data::Compare::Compare($diff_bool, $origin));
# note: this fails with Data::Compare@1.23 due to a bug, which has been fixed in 1.25
ok(!Data::Compare::Compare($diff_json, $origin));
done_testing();
Loading…
Cancel
Save