Mail-Log-Parse
view release on metacpan or search on metacpan
t/002_basic.t view on Meta::CPAN
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests=> 268;
use Test::Exception;
use Time::Local;
use Mail::Log::Parse;
use Mail::Log::Parse::Postfix;
use Mail::Log::Exceptions;
#use Test::Differences;
# A quick test of Mail::Log::Parse.
{
my $object;
lives_ok { $object = Mail::Log::Parse->new() } 'Create Mai::Log::Parse object.';
throws_ok { $object->next() } 'Mail::Log::Exceptions::Unimplemented';
}
# We'll need this value over and over.
( undef, undef, undef, undef, undef, my $year) = localtime;
# The keys list.
my @keys = sort qw(to from relay pid msgid program host status id timestamp text size delay_before_queue
delay_in_queue delay_connect_setup delay_message_transmission delay connect
disconnect previous_host previous_host_name previous_host_ip);
### Test the non-working. ###
{
my $object;
throws_ok {$object = Mail::Log::Parse::Postfix->new({'log_file' => 't/log'})} 'Mail::Log::Exceptions::LogFile';
$object = Mail::Log::Parse::Postfix->new({'logfile' => 't/data'});
# Boolean coercion: False condition.
ok(!($object), 'False boolean coercion.');
throws_ok {my $line = $object->next()} 'Mail::Log::Exceptions::LogFile';
# The next test doesn't work for root. Try to skip if we need to.
SKIP: {
skip 'This test cannot be run as root.', 1 if ( $> == 0 );
# This is going to test
# a file that exists, but we can't read...
chmod (0000, 't/data/log');
throws_ok {$object = Mail::Log::Parse::Postfix->new({'log_file' => 't/data/log'})} 'Mail::Log::Exceptions::LogFile';
chmod (0644, 't/data/log'); # Make sure we set it back at the end.
}
}
my $object = Mail::Log::Parse::Postfix->new();
$object->set_logfile('t/data/log');
is($object->get_line_number(), 0, 'Starting line number.');
# A quick test of the coercions.
is("$object", 'Mail::Log::Parse::Postfix File: t/data/log Line: 0', 'String coercion.');
ok($object, 'True boolean coercion.');
throws_ok { 1 + $object } 'Mail::Log::Exceptions';
# Back from the beginning.
{
my $result = $object->previous();
is($result, undef, 'Previous from start.');
ok(!$object->go_backward(3), 'Backward from start.');
}
# A quick test of the first line.
{
my $result = $object->next();
( run in 0.540 second using v1.01-cache-2.11-cpan-39bf76dae61 )