our
@EXPORT
=
qw(test_redis)
;
sub
test_redis(&) {
my
$cb
=
shift
;
chomp
(
my
$redis_server
= `which redis-server`);
unless
(
$redis_server
&& -e
$redis_server
&& -x _) {
plan
skip_all
=>
'redis-server not found in your PATH'
;
}
test_tcp
server
=>
sub
{
my
$port
=
shift
;
rewrite_redis_conf(
$port
);
exec
"redis-server"
,
"t/redis.conf"
;
},
client
=>
sub
{
my
$port
=
shift
;
my
$r
= AnyEvent::Redis->new(
host
=>
"127.0.0.1"
,
port
=>
$port
);
$cb
->(
$r
,
$port
);
};
}
sub
rewrite_redis_conf {
my
$port
=
shift
;
my
$dir
=
$FindBin::Bin
;
open
my
$in
,
"<"
,
"t/redis.conf.base"
or
die
$!;
open
my
$out
,
">"
,
"t/redis.conf"
or
die
$!;
while
(<
$in
>) {
s/__PORT__/
$port
/;
s/__DIR__/
$dir
/;
print
$out
$_
;
}
}
END {
unlink
"t/redis.conf"
}
1;