Parse-Netstat-Search/Parse-Netstat-Search/t/search.t

94 lines
2.2 KiB
Perl

use strict;
use Test::More;
BEGIN {
use_ok('Parse::Netstat::Search');
}
my $res=[ '0', '1',
{
'active_conns'=>[
{
'foriegn_host'=>'10.0.0.1',
'local_host'=>'10.0.0.2',
'foriegn_port'=>'22222',
'local_port'=>'22',
'sendq'=>'0',
'recvq'=>'0',
'state' => 'ESTABLISHED',
'proto' => 'tcp4',
},
{
'foriegn_host'=>'10.0.0.1',
'local_host'=>'10.0.0.2',
'foriegn_port'=>'22',
'local_port'=>'2222',
'sendq'=>'0',
'recvq'=>'0',
'state' => 'TIME_WAIT',
'proto' => 'tcp4',
},
{
'foriegn_host'=>'10.0.0.1',
'local_host'=>'192.168.0.1',
'foriegn_port'=>'22',
'local_port'=>'2222',
'sendq'=>'0',
'recvq'=>'0',
'state' => 'ESTABLISHED',
'proto' => 'tcp4',
},
{
'foriegn_host'=>'10.0.0.1',
'local_host'=>'10.0.0.2',
'foriegn_port'=>'22',
'local_port'=>'2222',
'sendq'=>'0',
'recvq'=>'0',
'state' => 'ESTABLISHED',
'proto' => 'tcp4',
},
{
'foreign_host' => '*',
'recvq' => '0',
'local_port' => '389',
'local_host' => '127.0.0.1',
'foreign_port' => '*',
'state' => 'LISTEN',
'proto' => 'tcp4',
'sendq' => '0'
},
{
'foreign_host' => '*',
'recvq' => '0',
'local_port' => '22',
'local_host' => '*',
'foreign_port' => '*',
'state' => 'LISTEN',
'proto' => 'tcp4',
'sendq' => '0'
},
],
}
];
# does a quick test to make sure we have the basics required for the following tests to work
my $res_good=1;
if (
( ref( $res ) ne 'ARRAY' ) ||
( ! defined( $res->[2] ) ) ||
( ! defined( $res->[2]->{active_conns} ) )
){
$res_good=0;
}
ok( $res_good eq '1', 'res test') or diag("Test data is bad");
my $search=Parse::Netstat::Search->new;
#return all non-unix connections
my @found=$search->search($res);
ok( $#found eq '5', 'search, all') or diag('"'.$#found.'" number of returned connections for a empty search instead of "5"');
done_testing(3);