more tests for Qpsmtpd::Config
* fix for cache clearing that didn't work * imported a sample .cdb file for testing
This commit is contained in:
parent
75cb416b62
commit
b153c0ab99
21
Makefile.PL
21
Makefile.PL
@ -7,18 +7,19 @@ WriteMakefile(
|
||||
NAME => 'qpsmtpd',
|
||||
VERSION_FROM => 'lib/Qpsmtpd.pm',
|
||||
PREREQ_PM => {
|
||||
'Data::Dumper' => 0,
|
||||
'Date::Parse' => 0,
|
||||
'File::Temp' => 0,
|
||||
'Mail::Header' => 0,
|
||||
'MIME::Base64' => 0,
|
||||
'Net::DNS' => 0.39,
|
||||
'Net::IP' => 0,
|
||||
'Time::HiRes' => 0,
|
||||
'CDB_File' => 0,
|
||||
'Data::Dumper' => 0,
|
||||
'Date::Parse' => 0,
|
||||
'File::Temp' => 0,
|
||||
'Mail::Header' => 0,
|
||||
'MIME::Base64' => 0,
|
||||
'Net::DNS' => 0.39,
|
||||
'Net::IP' => 0,
|
||||
'Time::HiRes' => 0,
|
||||
'IO::Socket::SSL' => 0,
|
||||
# Dev/Test modules
|
||||
'Test::More' => 0,
|
||||
'Test::Output' => 0,
|
||||
'Test::More' => 0,
|
||||
'Test::Output' => 0,
|
||||
# modules for specific features
|
||||
'Mail::DKIM' => 0,
|
||||
'File::Tail' => 0, # log/summarize, log/watch
|
||||
|
@ -8,7 +8,7 @@ use lib 'lib';
|
||||
use parent 'Qpsmtpd::Base';
|
||||
use Qpsmtpd::Constants;
|
||||
|
||||
our $_config_cache = {};
|
||||
our %config_cache = ();
|
||||
our %dir_memo;
|
||||
our %defaults = (
|
||||
me => hostname,
|
||||
@ -43,7 +43,7 @@ sub config_dir {
|
||||
}
|
||||
|
||||
sub clear_cache {
|
||||
$_config_cache = {};
|
||||
%config_cache = ();
|
||||
%dir_memo = ();
|
||||
}
|
||||
|
||||
@ -72,7 +72,8 @@ sub get_qmail_map {
|
||||
my ($self, $config, $configfile) = @_;
|
||||
|
||||
if (!-e $configfile . ".cdb") {
|
||||
$_config_cache->{$config} ||= [];
|
||||
$self->log(LOGERROR, "File $configfile.cdb does not exist");
|
||||
$config_cache{$config} ||= [];
|
||||
return +{};
|
||||
}
|
||||
eval { require CDB_File };
|
||||
@ -99,7 +100,7 @@ sub get_qmail_map {
|
||||
sub from_file {
|
||||
my ($self, $configfile, $config, $visited) = @_;
|
||||
if (!-e $configfile) {
|
||||
$_config_cache->{$config} ||= [];
|
||||
$config_cache{$config} ||= [];
|
||||
return;
|
||||
}
|
||||
|
||||
@ -145,7 +146,7 @@ sub from_file {
|
||||
}
|
||||
push @{$visited}, $inclusion;
|
||||
|
||||
for my $inc ($self->expand_inclusion_($inclusion, $configfile)) {
|
||||
for my $inc ($self->expand_inclusion($inclusion, $configfile)) {
|
||||
my @insertion = $self->from_file($inc, $config, $visited);
|
||||
splice @config, $pos, 0, @insertion; # insert the inclusion
|
||||
$pos += @insertion;
|
||||
@ -156,12 +157,12 @@ sub from_file {
|
||||
}
|
||||
}
|
||||
|
||||
$_config_cache->{$config} = \@config;
|
||||
$config_cache{$config} = \@config;
|
||||
|
||||
return wantarray ? @config : $config[0];
|
||||
}
|
||||
|
||||
sub expand_inclusion_ {
|
||||
sub expand_inclusion {
|
||||
my $self = shift;
|
||||
my $inclusion = shift;
|
||||
my $context = shift;
|
||||
|
BIN
t/config/users.cdb
Normal file
BIN
t/config/users.cdb
Normal file
Binary file not shown.
@ -4,6 +4,7 @@ use warnings;
|
||||
use Data::Dumper;
|
||||
use File::Path;
|
||||
use Test::More;
|
||||
use Sys::Hostname;
|
||||
|
||||
use lib 'lib'; # test lib/Qpsmtpd (vs site_perl)
|
||||
use lib 't';
|
||||
@ -30,8 +31,12 @@ isa_ok($config, 'Qpsmtpd::Config');
|
||||
|
||||
__log();
|
||||
__config_dir();
|
||||
__clear_cache();
|
||||
__default();
|
||||
__from_file();
|
||||
__get_qmail();
|
||||
__get_qmail_map();
|
||||
__expand_inclusion();
|
||||
__config_via_smtpd();
|
||||
|
||||
foreach my $f (@mes) { unlink $f; }
|
||||
@ -52,26 +57,55 @@ sub __log {
|
||||
is($warned, "$$ test log message\n", 'LOGWARN emitted correct warning');
|
||||
}
|
||||
|
||||
sub __config_dir {
|
||||
my $dir = $config->config_dir('logging');
|
||||
ok($dir, "config_dir, $dir");
|
||||
|
||||
#warn Data::Dumper::Dumper($Qpsmtpd::config_dir_memo{logging});
|
||||
$dir = $Qpsmtpd::Config::dir_memo{logging};
|
||||
ok($dir, "config_dir, $dir (memo)");
|
||||
}
|
||||
|
||||
sub __clear_cache {
|
||||
$Qpsmtpd::Config::config_cache{foo} = 2;
|
||||
$Qpsmtpd::Config::dir_memo{dir1} = 'some/path';
|
||||
|
||||
$config->clear_cache();
|
||||
ok(! $Qpsmtpd::Config::config_cache{foo}, "clear_cache, config_cache")
|
||||
or diag Data::Dumper::Dumper($Qpsmtpd::Config::config_cache{foo});
|
||||
ok(! $Qpsmtpd::Config::dir_memo{dir1}, "clear_cache, dir_memo")
|
||||
};
|
||||
|
||||
sub __default {
|
||||
is($config->default('me'), hostname, "default, my hostname");
|
||||
is($config->default('timeout'), 1200, "default timeout is 1200");
|
||||
ok(!$config->default('undefined-test'), "default, undefined");
|
||||
}
|
||||
|
||||
sub __get_qmail {
|
||||
is($config->get_qmail('me'), 'host.example.org', 'get_qmail("me")');
|
||||
ok(!$config->get_qmail('not-me'), 'get_qmail("not-me")');
|
||||
}
|
||||
|
||||
sub __get_qmail_map {
|
||||
eval "require CDB_File"; ## no critic (StringyEval)
|
||||
if (!$@) {
|
||||
my $r = $config->get_qmail_map('users', 't/config/users');
|
||||
ok(keys %$r, 'get_qmail_map("users.cdb")');
|
||||
ok($r->{'!example.com-'}, "get_qmail_map, known entry");
|
||||
};
|
||||
}
|
||||
|
||||
sub __from_file {
|
||||
my $test_file = 't/config/test_config_file';
|
||||
my @r = $config->from_file($test_file, 'test_config_file');
|
||||
ok( @r, "from_file, $test_file");
|
||||
cmp_ok('1st line with content', 'eq', $r[0], "from_file string compare");
|
||||
ok( !$r[1], "from_file");
|
||||
};
|
||||
}
|
||||
|
||||
sub __config_dir {
|
||||
my $dir = $config->config_dir('logging');
|
||||
ok($dir, "config_dir, $dir");
|
||||
|
||||
#warn Data::Dumper::Dumper($Qpsmtpd::config_dir_memo{logging});
|
||||
$dir = $Qpsmtpd::Config::dir_memo{logging};
|
||||
ok($dir, "config_dir, $dir (memo)");
|
||||
sub __expand_inclusion {
|
||||
# TODO
|
||||
}
|
||||
|
||||
sub __config_via_smtpd {
|
||||
|
Loading…
Reference in New Issue
Block a user