#321 clean interface descriptions of null and trailing space

This commit is contained in:
Oliver Gorwits
2019-04-20 09:28:06 +01:00
parent ea9ad92cc4
commit 75785f70c7
4 changed files with 31 additions and 7 deletions

View File

@@ -150,6 +150,10 @@ sub interfaces {
my $port = $i_descr->{$iid};
next unless defined $port;
my $port = SNMP::Info::munge_null($port);
$port =~ s/^\s+//; $port =~ s/\s+$//;
next unless length $port;
if ( $seen{$port}++ ) {
# (#320) also fixup the port this is a duplicate of
$interfaces->{ $first_seen_as{$port} }

View File

@@ -335,6 +335,10 @@ sub interfaces {
my $port = $i_descr->{$iid};
next unless defined $port;
my $port = SNMP::Info::munge_null($port);
$port =~ s/^\s+//; $port =~ s/\s+$//;
next unless length $port;
if ( $seen{$port}++ ) {
# (#320) also fixup the port this is a duplicate of
$interfaces->{ $first_seen_as{$port} }

View File

@@ -50,18 +50,22 @@ sub setup : Tests(setup) {
'_i_index' => 1,
'_i_description' => 1,
'store' => {
'i_index' => {1 => 1, 2 => 2, 3 => 3, 4 => 4},
'i_index' => { map {($_ => $_)} (1 .. 8) },
'i_description' => {
1 => 'Unique Interface Name',
2 => 'Duplicate Interface Name',
3 => 'Duplicate Interface Name'
3 => 'Duplicate Interface Name',
4 => "\0",
5 => "\0",
6 => " \0",
7 => "\0 ",
},
},
};
$test->{info}->cache($cache_data);
}
sub duplicates : Tests(2) {
sub interfaces : Tests(2) {
my $test = shift;
my $expected_data = {
@@ -69,11 +73,15 @@ sub duplicates : Tests(2) {
2 => 'Duplicate Interface Name (2)',
3 => 'Duplicate Interface Name (3)',
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
};
can_ok($test->{info}, 'interfaces');
cmp_deeply($test->{info}->interfaces(),
$expected_data, 'Call to interfaces() removes duplicates');
$expected_data, 'Call to interfaces() removes duplicates and cleans up');
}
1;

View File

@@ -50,11 +50,15 @@ sub setup : Tests(setup) {
'_i_index' => 1,
'_i_description' => 1,
'store' => {
'i_index' => {1 => 1, 2 => 2, 3 => 3, 4 => 4},
'i_index' => { map {($_ => $_)} (1 .. 8) },
'i_description' => {
1 => 'Unique Interface Name',
2 => 'Duplicate Interface Name',
3 => 'Duplicate Interface Name'
3 => 'Duplicate Interface Name',
4 => "\0",
5 => "\0",
6 => " \0",
7 => "\0 ",
},
},
};
@@ -69,11 +73,15 @@ sub duplicates : Tests(2) {
2 => 'Duplicate Interface Name (2)',
3 => 'Duplicate Interface Name (3)',
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
};
can_ok($test->{info}, 'interfaces');
cmp_deeply($test->{info}->interfaces(),
$expected_data, 'Call to interfaces() removes duplicates');
$expected_data, 'Call to interfaces() removes duplicates and cleans up');
}
1;