Move hook testing stuff to Test::Qpsmtpd

This makes it more available to plugins outside of t/plugin_tests/
This commit is contained in:
Jared Johnson 2014-12-17 21:25:12 -06:00
parent 46d26848a9
commit 7f357af1c2
2 changed files with 37 additions and 32 deletions

View File

@ -118,4 +118,37 @@ sub run_plugin_tests {
$Test->done_testing();
}
sub fake_hook {
my ( $self, $hook, $sub ) = @_;
unshift @{ $self->hooks->{$hook} ||= [] },
{
name => '___FakeHook___',
code => $sub,
};
}
sub unfake_hook {
my ( $self, $hook ) = @_;
$self->hooks->{$hook} = [
grep { $_->{name} ne '___FakeHook___' }
@{ $self->hooks->{$hook} || [] }
];
}
sub fake_config {
my $self = shift;
my $fake_config = {@_};
$self->fake_hook( 'config',
sub {
my ( $self, $txn, $conf ) = @_;
return DECLINED if ! exists $fake_config->{$conf};
return OK, $fake_config->{$conf};
} );
}
sub unfake_config {
my ( $self ) = @_;
$self->unfake_hook('config');
}
1;

View File

@ -84,37 +84,9 @@ sub validate_password {
return $deny, "$file - wrong password";
}
sub fake_hook {
my ( $self, $hook, $sub ) = @_;
unshift @{ $self->qp->hooks->{$hook} ||= [] },
{
name => '___FakeHook___',
code => $sub,
};
}
sub unfake_hook {
my ( $self, $hook ) = @_;
$self->qp->hooks->{$hook} = [
grep { $_->{name} ne '___FakeHook___' }
@{ $self->qp->hooks->{$hook} || [] }
];
}
sub fake_config {
my $self = shift;
my $fake_config = {@_};
$self->fake_hook( 'config',
sub {
my ( $self, $txn, $conf ) = @_;
return DECLINED if ! exists $fake_config->{$conf};
return OK, $fake_config->{$conf};
} );
}
sub unfake_config {
my ( $self ) = @_;
$self->unfake_hook('config');
}
sub fake_hook { shift->qp->fake_hook(@_) }
sub unfake_hook { shift->qp->unfake_hook(@_) }
sub fake_config { shift->qp->fake_config(@_) }
sub unfake_config { shift->qp->unfake_config(@_) }
1;