qpsmtpd.t: added tests for hook_responder
This commit is contained in:
parent
820af9a26c
commit
9cd8b165a0
@ -369,11 +369,9 @@ sub run_continuation {
|
|||||||
|
|
||||||
sub hook_responder {
|
sub hook_responder {
|
||||||
my ($self, $hook, $msg, $args) = @_;
|
my ($self, $hook, $msg, $args) = @_;
|
||||||
|
|
||||||
my $code = shift @$msg;
|
my $code = shift @$msg;
|
||||||
|
|
||||||
my $responder = $hook . '_respond';
|
if (my $meth = $self->can($hook . '_respond')) {
|
||||||
if (my $meth = $self->can($responder)) {
|
|
||||||
return $meth->($self, $code, $msg, $args);
|
return $meth->($self, $code, $msg, $args);
|
||||||
}
|
}
|
||||||
return $code, @$msg;
|
return $code, @$msg;
|
||||||
|
32
t/qpsmtpd.t
32
t/qpsmtpd.t
@ -24,6 +24,9 @@ __hooks_none();
|
|||||||
ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection");
|
ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection");
|
||||||
__hooks();
|
__hooks();
|
||||||
|
|
||||||
|
__register_hook();
|
||||||
|
__hook_responder();
|
||||||
|
|
||||||
__temp_file();
|
__temp_file();
|
||||||
__temp_dir();
|
__temp_dir();
|
||||||
__size_threshold();
|
__size_threshold();
|
||||||
@ -61,6 +64,35 @@ sub __hooks_none {
|
|||||||
is_deeply($r, [], 'hooks, empty, specified');
|
is_deeply($r, [], 'hooks, empty, specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub __hook_responder {
|
||||||
|
# my ($self, $hook, $msg, $args) = @_;
|
||||||
|
my ($code, $msg) = $qp->hook_responder('test-hook', ['test code','test mesg'], ['test-arg']);
|
||||||
|
is($code, 'test code', "hook_responder, code");
|
||||||
|
is($msg, 'test mesg', "hook_responder, test msg");
|
||||||
|
|
||||||
|
($code, $msg) = $smtpd->hook_responder('connect', ['test code','test mesg'], ['test-arg']);
|
||||||
|
is($code->[0], 220, "hook_responder, code");
|
||||||
|
ok($code->[1] =~ /ESMTP qpsmtpd/, "hook_responder, message: ". $code->[1]);
|
||||||
|
|
||||||
|
my $rej_msg = 'Your father smells of elderberries';
|
||||||
|
#($smtpd, $conn) = Test::Qpsmtpd->new_conn();
|
||||||
|
($code, $msg) = $smtpd->hook_responder('connect', [DENY, $rej_msg]);
|
||||||
|
# warn Data::Dumper::Dumper($code);
|
||||||
|
# warn Data::Dumper::Dumper($msg);
|
||||||
|
# is($code, undef, "hook_responder, disconnected yields undef code");
|
||||||
|
is($msg, undef, "hook_responder, disconnected yields undef msg");
|
||||||
|
|
||||||
|
#warn Data::Dumper::Dumper($msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub __register_hook {
|
||||||
|
my $hook = 'test';
|
||||||
|
is( $Qpsmtpd::hooks->{'test'}, undef, "_register_hook, test hook is undefined");
|
||||||
|
|
||||||
|
$smtpd->_register_hook('test', 'fake-code-ref');
|
||||||
|
is_deeply( $Qpsmtpd::hooks->{'test'}, ['fake-code-ref'], "test hook is registered");
|
||||||
|
}
|
||||||
|
|
||||||
sub __log {
|
sub __log {
|
||||||
my $warned = '';
|
my $warned = '';
|
||||||
local $SIG{__WARN__} = sub {
|
local $SIG{__WARN__} = sub {
|
||||||
|
Loading…
Reference in New Issue
Block a user