1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
use 5.008000;
use strict;
use warnings;
use Test::More;
use AnyEvent::RipeRedis qw( :err_codes );
require 't/test_helper.pl';
my $server_info = run_redis_instance(
requirepass => 'testpass',
);
if ( !defined $server_info ) {
plan skip_all => 'redis-server is required for this test';
}
plan tests => 8;
t_successful_auth($server_info);
t_invalid_password($server_info);
sub t_successful_auth {
my $server_info = shift;
my $redis = AnyEvent::RipeRedis->new(
host => $server_info->{host},
port => $server_info->{port},
password => $server_info->{password},
);
can_ok( $redis, 'disconnect' );
my $t_reply;
ev_loop(
sub {
my $cv = shift;
$redis->ping(
sub {
$t_reply = shift;
my $err = shift;
if ( defined $err ) {
diag( $err->message );
}
$cv->send;
}
);
}
);
$redis->disconnect;
is( $t_reply, 'PONG', 'successful AUTH' );
}
sub t_invalid_password {
my $server_info = shift;
my $redis;
my $t_cli_err;
my $t_cmd_err;
ev_loop(
sub {
my $cv = shift;
$redis = AnyEvent::RipeRedis->new(
host => $server_info->{host},
port => $server_info->{port},
password => 'invalid',
on_error => sub {
$t_cli_err = shift;
$cv->send;
},
);
$redis->ping(
sub {
my $reply = shift;
$t_cmd_err = shift;
}
);
}
);
$redis->disconnect;
my $t_name_prefix = 'invalid password';
isa_ok( $t_cmd_err, 'AnyEvent::RipeRedis::Error' );
like( $t_cmd_err->message, qr/^Operation "ping" aborted:/,
"$t_name_prefix; command error message" );
is( $t_cmd_err->code, E_OPRN_ERROR, "$t_name_prefix; command error code" );
isa_ok( $t_cli_err, 'AnyEvent::RipeRedis::Error' );
like( $t_cli_err->message, qr/^(?:ERR invalid password|WRONGPASS )/,
"$t_name_prefix; client error message" );
is( $t_cli_err->code, E_OPRN_ERROR, "$t_name_prefix; client error code" );
return;
}
|