BGPmon-core-2

 view release on metacpan or  search on metacpan

t/00-bgpmon-log.t  view on Meta::CPAN

# try a failure opening a file - directory doesn't exit
$init_params{"log_file"} = "/this/directory/cannot/exist/foo.txt";
test_init_failure("Testing unable to open log file ",
                  BGPmon::Log::LOG_INIT_FILE_OPEN_CODE, 
                  BGPmon::Log::LOG_INIT_FILE_OPEN_MSG );

# try a failure opening a file - bad permissions
my $retu = unlink ($log_file);
my $reto = open($log_fh, "> $log_file");
close($log_fh);
chmod(0000, $log_file);
ok($reto != 0, "Making unreadable log file : $log_file");
$init_params{"log_file"} = $log_file;
test_init_failure("Testing bad log file permissions",
                  BGPmon::Log::LOG_INIT_FILE_OPEN_CODE, 
                  BGPmon::Log::LOG_INIT_FILE_OPEN_MSG );
$retu = unlink ($log_file);

# test no init function
$ret = BGPmon::Log::log_close();
$ret = BGPmon::Log::log_notice($log_msg);

t/00-bgpmon-log.t  view on Meta::CPAN

ok(($ret == 1) && 
   ($ret_code eq BGPmon::Log::LOG_MSG_PRINTABLE_CODE ) && 
   ($ret_msg eq BGPmon::Log::LOG_MSG_PRINTABLE_MSG), 
   "Testing a non-printable log message, result is $ret_code: $ret_msg");

# test write fails for log_file
# tried removing and unlinking the file,  but 
# both yield no errors
# remove the file we are logging to
#$ret = unlink($log_file);
#chmod(0000, $log_file);
#ok($ret == 1, "Removing test log_file $log_file");
#$ret = BGPmon::Log::log_notice("help");
#$ret_code = BGPmon::Log::get_error_code("log_notice");
#$ret_msg = BGPmon::Log::get_error_msg("log_notice");
#ok(($ret == 1) && 
#   ($ret_code eq BGPmon::Log::LOG_WRITE_FAILED_CODE ) && 
#   ($ret_msg eq BGPmon::Log::LOG_WRITE_FAILED_MSG), 
#   "Testing log message to deleted file");
#

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

#Try actually connecting to the file this time
$ret = connect_file($location."compress_test.gz");
is($ret,1,"connect_file - connect to binary file");
ok(!is_connected(),"connect_file - not connected to binary file");

#Connect to a file, read a message, change the permissions, try to read again
#This should work because permissions only get checked once, not per-read
$ret = connect_file($location."bgpmon-fetch-file-valid.xml.gz");
ok( is_connected(),"confirm file connection");
$msg = read_xml_message();
`chmod a-r "/tmp/BGP.File.$$/extract_bgp.$$"`;
$msg = read_xml_message();
ok(defined($msg),"read_xml_message - chmod mid-read");
close_connection();

#Connect to a file, read a message, move the file, try to read again
$ret = connect_file($location."bgpmon-fetch-file-valid.xml.gz");
ok( is_connected(),"confirm file connection");
$msg = read_xml_message();
ok(defined($msg),"read_xml_message - read before move");
`mv "/tmp/BGP.File.$$/extract_bgp.$$" "/tmp/BGP.File.$$/extract_bgp.$$.bak"`;
#Now that we've moved the file that we were reading, the next read will fail
$msg = read_xml_message();



( run in 0.265 second using v1.01-cache-2.11-cpan-496ff517765 )