From: Jason Mills <jmmi...@cpan.org>
Signed-off-by: Jason Mills <jmmi...@cpan.org> --- config.sample/plugins | 3 +++ plugins/reverse_config_cachekey | 10 ++++++++++ t/plugin_tests/reverse_config_cachekey | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 0 deletions(-) create mode 100644 plugins/reverse_config_cachekey create mode 100644 t/plugin_tests/reverse_config_cachekey diff --git a/config.sample/plugins b/config.sample/plugins index 0b51124..8efc133 100644 --- a/config.sample/plugins +++ b/config.sample/plugins @@ -73,3 +73,6 @@ spamassassin # check_relay # check_relay:0 somearg # check_relay:1 someotherarg + +# load reverse_config_cachekey for testing +reverse_config_cachekey diff --git a/plugins/reverse_config_cachekey b/plugins/reverse_config_cachekey new file mode 100644 index 0000000..94ea07e --- /dev/null +++ b/plugins/reverse_config_cachekey @@ -0,0 +1,10 @@ +# This is a dummy plugin to demonstrate and test the config-get-cachekey hook +# You probably don't want to use this in a production environment + +use Qpsmtpd::Constants; + +sub hook_config_get_cachekey { + my ($self, $transaction, $key, @rest) = @_; + return DECLINED if $key =~ /^(?:me|timeout)$/; + return ( OK, $key = reverse(split('', $key)) ); +} diff --git a/t/plugin_tests/reverse_config_cachekey b/t/plugin_tests/reverse_config_cachekey new file mode 100644 index 0000000..65bb1a3 --- /dev/null +++ b/t/plugin_tests/reverse_config_cachekey @@ -0,0 +1,18 @@ +sub register_tests { + my $self = shift; + $self->register_test("foo", 1); + $self->register_test("test_return_value", 1); +} + +sub foo { + ok(1); +} + +sub test_return_value { + my $self = shift; + my $t = "foobar"; + my $e = reverse(split('', $t)); + my $r; + is( $r = $self->hook_config_get_cachekey($self->transaction, $t), $e) or + diag("Expected '$e' got '$r'"); +} \ No newline at end of file -- 1.6.0.4