File: 040-output-email.t

package info (click to toggle)
liblog-handler-perl 0.45-1%2Blenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 392 kB
  • ctags: 145
  • sloc: perl: 2,017; makefile: 39
file content (51 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use strict;
use warnings;
use Test::More;

BEGIN {
    eval "use Net::SMTP;";
    if ($@) {
        plan skip_all => "No Net::SMTP installed";
        exit(0);
    } 
};

plan tests => 3;

use Log::Handler::Output::Email;
$Log::Handler::Output::Email::TEST = 1;

my $log = Log::Handler::Output::Email->new(
    host     => [ 'bloonix.de' ],
    hello    => 'EHLO bloonix.de',
    timeout  => 60,
    debug    => 1,
    from     => 'jschulz.cpan@bloonix.de',
    to       => 'jschulz.cpan@bloonix.de',
    subject  => 'Log::Handler::Output::Email test',
    buffer   => 20,
);

ok(1, 'new');

# checking all log levels for would()
foreach my $i (1..10) {
    $log->log(message => "test $i\n") or die $!;
}
ok(1, "checking log()");

# checking all lines
my $match_lines = 0;
my $all_lines   = 0;

foreach my $line ( @{$log->{MESSAGE_BUFFER}} ) {
    ++$all_lines;
    next unless $line =~ /^test \d+$/;
    ++$match_lines;
}

if ($match_lines == 10) {
   ok(1, "checking buffer ($all_lines:$match_lines)");
} else {
   ok(0, "checking buffer ($all_lines:$match_lines)");
}