add more tests
This commit is contained in:
parent
e64265a39a
commit
84f5d8b83b
|
@ -1,6 +1,7 @@
|
|||
use strict;
|
||||
|
||||
use Test::More;
|
||||
use Data::Dumper;
|
||||
|
||||
BEGIN {
|
||||
use_ok('Parse::Netstat::Search');
|
||||
|
@ -56,7 +57,7 @@ my $res=[ '0', '1',
|
|||
'local_host' => '127.0.0.1',
|
||||
'foreign_port' => '*',
|
||||
'state' => 'LISTEN',
|
||||
'proto' => 'tcp4',
|
||||
'proto' => 'udp4',
|
||||
'sendq' => '0'
|
||||
},
|
||||
{
|
||||
|
@ -103,8 +104,35 @@ ok( $#found eq '5', 'search, state reset') or diag('"'.$#found.'" number of retu
|
|||
$search->set_cidrs( ['10.0.0.0/24'] );
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '3', 'search, CIDR 1') or diag('"'.$#found.'" number of returned connections for CIDR 10.0.0.0/24 search instead of "3"');
|
||||
$search->set_cidrs( ['127.0.0.0/24'] );
|
||||
$search->set_cidrs( ['127.0.0.1/32'] );
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '0', 'search, CIDR 2') or diag('"'.$#found.'" number of returned connections for CIDR 127.0.0.1/32 search instead of "0"');
|
||||
$search->set_cidrs( ['10.0.0.0/24','127.0.0.1/32'] );
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '4', 'search, CIDR 3') or diag('"'.$#found.'" number of returned connections for CIDR 127.0.0.1/32 10.0.0.0/24 search instead of "4"');
|
||||
$search->set_cidrs;
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '5', 'search, CIDR reset') or diag('"'.$#found.'" number of returned connections for a empty search instead of "5"... failed to reset the CIDRs');
|
||||
|
||||
done_testing(7);
|
||||
#make sure we can match multiple items
|
||||
$search->set_cidrs( ['127.0.0.0/24'] );
|
||||
$search->set_states( ['LISTEN'] );
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '0', 'search, CIDR+state') or diag('"'.$#found.'" number of returned connections for CIDR 127.0.0.0/24 + LISTEN state search instead of "0"');
|
||||
$search->set_cidrs;
|
||||
$search->set_states;
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '5', 'search, CIDR+state reset') or diag('"'.$#found.'" number of returned connections for a empty search instead of "5"... failed to reset the CIDRs and states');
|
||||
|
||||
#make sure we cans search based on protocols
|
||||
$search->set_protocols(['udp4']);
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '0', 'search, Protocol 1') or diag('"'.$#found.'" number of returned connections for udp4 protocol instead of "0"');
|
||||
$search->set_protocols(['tcp4']);
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '4', 'search, Protocol 2') or diag('"'.$#found.'" number of returned connections for tcp4 protocol instead of "4"');
|
||||
$search->set_states( ['LISTEN'] );
|
||||
@found=$search->search($res);
|
||||
ok( $#found eq '0', 'search, Protocol+Listen') or diag('"'.$#found.'" number of returned connections for tcp4 protocol + LISTEN state instead of "0"');
|
||||
|
||||
done_testing(14);
|
||||
|
|
Loading…
Reference in New Issue