Use a loop to make test data clearer
This commit is contained in:
parent
41a71f5d79
commit
fb8f582055
@ -127,11 +127,42 @@ sub __config {
|
|||||||
ok( $qp->command('HELO test') );
|
ok( $qp->command('HELO test') );
|
||||||
ok( $qp->command('MAIL FROM:<test@example.com>') );
|
ok( $qp->command('MAIL FROM:<test@example.com>') );
|
||||||
my $sender = $qp->transaction->sender;
|
my $sender = $qp->transaction->sender;
|
||||||
$qp->hooks->{user_config} = undef;
|
my @test_data = (
|
||||||
is( $qp->config('size_threshold'), 10000, 'use global config when user_config is absent' );
|
{
|
||||||
is( $sender->config('test config'), undef, 'no user_config plugins exist' );
|
pref => 'size_threshold',
|
||||||
$qp->hooks->{user_config} = [{ name => 'test hook', code => sub { return DECLINED } }];
|
result => [],
|
||||||
is( $sender->config('test config'), undef, 'no user_config plugins return OK' );
|
expected => 10000,
|
||||||
$qp->hooks->{user_config} = [{ name => 'test hook', code => sub { return OK, 'test data' } }];
|
descr => 'fall back to global config when user_config is absent',
|
||||||
is( $sender->config('test config'), 'test data', 'user_config plugins return a value' );
|
},
|
||||||
|
{
|
||||||
|
pref => 'test_config',
|
||||||
|
result => [],
|
||||||
|
expected => undef,
|
||||||
|
descr => 'return nothing when no user_config plugins exist',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pref => 'test_config',
|
||||||
|
result => [DECLINED],
|
||||||
|
expected => undef,
|
||||||
|
descr => 'return nothing when user_config plugins return DECLINED',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pref => 'test_config',
|
||||||
|
result => [OK,'test value'],
|
||||||
|
expected => 'test value',
|
||||||
|
descr => 'return results when user_config plugin returns a value',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
for (@test_data) {
|
||||||
|
$qp->hooks->{user_config}
|
||||||
|
= @{ $_->{result} }
|
||||||
|
? [{ name => 'test hook', code => sub { return @{ $_->{result} }} }]
|
||||||
|
: undef;
|
||||||
|
is( $sender->config($_->{pref}), $_->{expected}, $_->{descr} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub fake_hook {
|
||||||
|
my ( $r ) = @_;
|
||||||
|
return @$r ? [{ name => 'test hook', code => sub { return @{ $_->{result} }} }] : undef;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user