Generalized method for test hooks
This commit is contained in:
parent
7d33c42d35
commit
46d26848a9
@ -84,26 +84,37 @@ sub validate_password {
|
|||||||
return $deny, "$file - wrong 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 {
|
sub fake_config {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $fake_config = {@_};
|
my $fake_config = {@_};
|
||||||
unshift @{ $self->qp->hooks->{config} ||= [] },
|
$self->fake_hook( 'config',
|
||||||
{
|
sub {
|
||||||
name => '___FakeHook___',
|
|
||||||
code => sub {
|
|
||||||
my ( $self, $txn, $conf ) = @_;
|
my ( $self, $txn, $conf ) = @_;
|
||||||
return DECLINED if ! exists $fake_config->{$conf};
|
return DECLINED if ! exists $fake_config->{$conf};
|
||||||
return OK, $fake_config->{$conf};
|
return OK, $fake_config->{$conf};
|
||||||
},
|
} );
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub unfake_config {
|
sub unfake_config {
|
||||||
my ( $self ) = @_;
|
my ( $self ) = @_;
|
||||||
$self->qp->hooks->{config} = [
|
$self->unfake_hook('config');
|
||||||
grep { $_->{name} ne '___FakeHook___' }
|
|
||||||
@{ $self->qp->hooks->{config} || [] }
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user