Take advantage of fake_hook() in existing tests
This commit is contained in:
parent
0204fb0f18
commit
a5f786c986
@ -152,13 +152,13 @@ sub __config {
|
||||
my @test_data = (
|
||||
{
|
||||
pref => 'size_threshold',
|
||||
result => [],
|
||||
result => undef,
|
||||
expected => 10000,
|
||||
descr => 'fall back to global config when user_config is absent',
|
||||
},
|
||||
{
|
||||
pref => 'test_config',
|
||||
result => [],
|
||||
result => undef,
|
||||
expected => undef,
|
||||
descr => 'return nothing when no user_config plugins exist',
|
||||
},
|
||||
@ -176,16 +176,11 @@ sub __config {
|
||||
},
|
||||
);
|
||||
for (@test_data) {
|
||||
$qp->hooks->{user_config} = @{$_->{result}}
|
||||
? [
|
||||
{
|
||||
name => 'test hook',
|
||||
code => sub { return @{$_->{result}} }
|
||||
}
|
||||
]
|
||||
: undef;
|
||||
$qp->fake_hook( 'user_config', sub { return @{$_->{result}} } )
|
||||
if $_->{result};
|
||||
is($sender->config($_->{pref}), $_->{expected}, $_->{descr});
|
||||
}
|
||||
$qp->unfake_hook('user_config');
|
||||
}
|
||||
|
||||
sub __canonify {
|
||||
|
20
t/qpsmtpd.t
20
t/qpsmtpd.t
@ -258,8 +258,8 @@ sub __config {
|
||||
{
|
||||
pref => 'size_threshold',
|
||||
hooks => {
|
||||
user_config => [],
|
||||
config => [],
|
||||
user_config => undef,
|
||||
config => undef,
|
||||
},
|
||||
expected => {
|
||||
user => 10000,
|
||||
@ -270,8 +270,8 @@ sub __config {
|
||||
{
|
||||
pref => 'timeout',
|
||||
hooks => {
|
||||
user_config => [],
|
||||
config => [],
|
||||
user_config => undef,
|
||||
config => undef,
|
||||
},
|
||||
expected => {
|
||||
user => 1200,
|
||||
@ -329,15 +329,8 @@ sub __config {
|
||||
},
|
||||
);
|
||||
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;
|
||||
for my $hook ( grep { $t->{hooks}{$_} } qw( config user_config ) ) {
|
||||
$qp->fake_hook( $hook, sub { return @{ $t->{hooks}{$hook} } } );
|
||||
}
|
||||
is(
|
||||
$qp->config($t->{pref}, $a),
|
||||
@ -348,6 +341,7 @@ sub __config {
|
||||
$t->{expected}{global},
|
||||
"Global config: $t->{descr}");
|
||||
}
|
||||
$qp->unfake_hook($_) for qw( config user_config );
|
||||
}
|
||||
|
||||
sub __warn_level {
|
||||
|
Loading…
Reference in New Issue
Block a user