Qpsmtpd::config() tests

This commit is contained in:
Jared Johnson 2014-09-15 09:24:13 -05:00
parent cda40f970b
commit 23ce6002cf

View File

@ -6,8 +6,13 @@ use Data::Dumper;
use Test::More;
use lib 'lib'; # test lib/Qpsmtpd (vs site_perl)
BEGIN { use_ok('Qpsmtpd'); }
BEGIN { use_ok('Qpsmtpd::Constants'); }
BEGIN {
use_ok('Qpsmtpd');
use_ok('Qpsmtpd::Constants');
}
use lib 't';
use_ok('Test::Qpsmtpd');
my $qp = bless {}, 'Qpsmtpd';
@ -23,11 +28,6 @@ __load_logging();
done_testing();
sub __config {
my @r = $qp->config('badhelo');
ok( $r[0], "config, badhelo, @r");
};
sub __get_qmail_config {
ok( !$qp->get_qmail_config('me'), "get_qmail_config, me");
@ -83,3 +83,103 @@ sub __authenticated {
$qp->{_auth} = 0;
ok( !$qp->authenticated(), "authenticated, false");
};
sub __config {
my @r = $qp->config('badhelo');
ok( $r[0], "config, badhelo, @r");
my $a = FakeAddress->new( test => 'test value' );
ok( my ($qp,$cxn) = Test::Qpsmtpd->new_conn(), "get new connection" );
my @test_data = (
{
pref => 'size_threshold',
hooks => {
user_config => [],
config => [],
},
expected => {
user => 10000,
global => 10000,
},
descr => 'no user or global config hooks, fall back to config file',
},
{
pref => 'timeout',
hooks => {
user_config => [],
config => [],
},
expected => {
user => 1200,
global => 1200,
},
descr => 'no user or global config hooks, fall back to defaults',
},
{
pref => 'timeout',
hooks => {
user_config => [DECLINED],
config => [DECLINED],
},
expected => {
user => 1200,
global => 1200,
},
descr => 'user and global config hooks decline, fall back to defaults',
},
{
pref => 'timeout',
hooks => {
user_config => [DECLINED],
config => [OK,1000],
},
expected => {
user => 1000,
global => 1000,
},
descr => 'user hook declines, global hook returns',
},
{
pref => 'timeout',
hooks => {
user_config => [OK,500],
config => [OK,undef],
},
expected => {
user => 500,
global => undef,
},
descr => 'user hook returns int, global hook returns undef',
},
{
pref => 'timeout',
hooks => {
user_config => [OK,undef],
config => [OK,1000],
},
expected => {
user => undef,
global => 1000,
},
descr => 'user hook returns undef, global hook returns int',
},
);
for my $t (@test_data) {
for my $hook (qw( config user_config )) {
$qp->hooks->{$hook}
= @{ $t->{hooks}{$hook} }
? [{ name => 'test hook', code => sub { return @{ $t->{hooks}{$hook} }} }]
: undef;
}
is( $qp->config($t->{pref},$a), $t->{expected}{user}, "User config: $t->{descr}");
is( $qp->config($t->{pref}), $t->{expected}{global}, "Global config: $t->{descr}");
}
}
package FakeAddress;
sub new {
shift;
return bless {@_};
}
sub address { } # pass the can('address') conditional