2014-09-11 01:53:28 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Data::Dumper;
|
|
|
|
use Test::More;
|
|
|
|
use Test::Output;
|
|
|
|
|
|
|
|
use lib 't';
|
|
|
|
use lib 'lib'; # test lib/Qpsmtpd/SMTP (vs site_perl)
|
|
|
|
|
|
|
|
use_ok('Test::Qpsmtpd');
|
|
|
|
use_ok('Qpsmtpd::SMTP');
|
|
|
|
|
|
|
|
ok(my $smtp = Qpsmtpd::SMTP->new(), "new smtp");
|
|
|
|
ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection");
|
|
|
|
|
|
|
|
__new();
|
|
|
|
__fault();
|
|
|
|
|
|
|
|
done_testing();
|
|
|
|
|
|
|
|
sub __new {
|
|
|
|
isa_ok( $smtp, 'Qpsmtpd::SMTP' );
|
|
|
|
|
|
|
|
ok( $smtp->{_commands}, "valid commands populated");
|
|
|
|
$smtp = Qpsmtpd::SMTP->new( key => 'val' );
|
|
|
|
cmp_ok( $smtp->{args}{key}, 'eq', 'val', "new with args");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub __fault {
|
|
|
|
|
|
|
|
my $fault;
|
|
|
|
stderr_like { $fault = $smtpd->fault }
|
2014-09-11 19:53:09 +02:00
|
|
|
qr/program fault - command not performed.*Last system error:/ms,
|
2014-09-11 01:53:28 +02:00
|
|
|
'fault outputs proper warning to STDOUT';
|
|
|
|
is($fault->[0], 451, 'fault returns 451');
|
|
|
|
|
|
|
|
stderr_like { $fault = $smtpd->fault('test message') }
|
2014-09-11 19:53:09 +02:00
|
|
|
qr/test message.*Last system error/ms,
|
2014-09-11 01:53:28 +02:00
|
|
|
'fault outputs proper custom warning to STDOUT';
|
|
|
|
is($fault->[1], 'Internal error - try again later - test message',
|
|
|
|
'returns the input message');
|
|
|
|
}
|