BGPmon-core-1

 view release on metacpan or  search on metacpan

t/08-bgpmon-fetchdata-file.t  view on Meta::CPAN

#Test suite for BGPmon::Fetch::File

use warnings;
use strict;
use Test::More;

use BGPmon::Fetch::File qw/init_bgpdata connect_file read_xml_message
 get_error_code get_error_message close_connection messages_read is_connected/;
use BGPmon::Log;

my $first_msg = "<ARCHIVER><TIME timestamp=\"1340136304\" datetime=\"2012-06-19T20:05:04Z\"/><EVENT cause=\"CREATE_NEW_FILE\">OPENED</EVENT></ARCHIVER>";

my $second_msg = "<BGP_MESSAGE xmlns=\"urn:ietf:params:xml:ns:xfb-0.4\" length=\"00001735\" version=\"0.4\" type_value=\"2\" type=\"UPDATE\"><BGPMON_SEQ id=\"2128112124\" seq_num=\"-1913318876\"/><TIME timestamp=\"1340136301\" datetime=\"2012-06-19T2...

#set the data directory
#my $data_dir = `echo -n \`pwd\``."/t/data";
#my $data_dir = 't';

my $resp = `pwd`;
my $location = 't/';
if($resp =~ m/bgpmon-tools\/BGPmon-core\/t/){
        $location = '';
}



my $ret = undef;    #Return value of calls
my $err = undef;    #Log message


##################### connect_file ###########################################
##################### Validation conditions ##################################
#Connect with no argument (done)
#Connect with 2 arguments (done)
#Connect with nonexistant file (done)
#Connect with file w/ invalid permissions (done)
#Connect with valid bz2 file (done)
#Connect with valid gz file (done)
#Connect to uncompressed file (done)
#Connect while already connected (done)
#No <xml> tag (wrong format) (done)


#Read XML while not connected (done)
#Connect, read, delete file, continue reading (done)
#Connect, delete file, read (done)
#Connect, read, move file, read (done)
#Connect, change permissions, read (done)

init_bgpdata();

#Connect w/ no argument
$ret = connect_file();
is($ret,1,"connect_file - no argument");
is(get_error_code("connect_file"),301, "connect_file - check error code");

#Connect w/ 2 arguments
#Test should work because connect_file only SHIFTs out the first argument
$ret = connect_file($location."bgpmon-fetch-file-valid.xml.gz", "Makefile");
is($ret,0,"connect_file - too many arguments");
close_connection();

#Connect to a valid, gzipped file
$ret = connect_file($location."bgpmon-fetch-file-valid.xml.gz");
is($ret,0,"connect_file - valid gzip archive");
close_connection();

#Connect to a compressed archive file that is missing ARCHIVER tags
$ret = connect_file($location."bgpmon-fetch-file-no-archiver.xml.bz2");
ok( is_connected() ,"connect_file - valid XML archive (compressed)");

#Try to read the first message out of the file
#This test will fail because of the missing ARCHIVER messages



( run in 2.123 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )