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
|
#!/usr/bin/env perl
use warnings;
use strict;
use lib 't/tlib';
use Test::More;
use Test::Mock::Redis ();
ok(my $r = Test::Mock::Redis->new, 'pretended to connect to our test redis-server');
my @redi = ($r);
my ( $guard, $srv );
if( $ENV{RELEASE_TESTING} ){
use_ok("Redis");
use_ok("Test::SpawnRedisServer");
($guard, $srv) = redis();
ok(my $r = Redis->new(server => $srv), 'connected to our test redis-server');
$r->flushall;
unshift @redi, $r
}
foreach my $o (@redi){
diag("testing $o") if $ENV{RELEASE_TESTING};
my @lists = ( qw/ forward backward all / );
for my $lname ( @lists ) {
$o->rpush($lname, 'hello');
$o->rpush($lname, 'hello');
$o->rpush($lname, 'foo');
$o->rpush($lname, 'hello');
is_deeply(
[ $o->lrange($lname, 0, -1) ],
[ qw/
hello
hello
foo
hello
/ ],
"list $lname as expected"
);
}
is( $o->lrem('forward', 2, 'hello'), 2, 'two removed from forward list' );
is_deeply(
[ $o->lrange('forward', 0, -1) ],
[ qw/
foo
hello
/ ],
'forward list as expected'
);
is( $o->lrem('backward', -2, 'hello'), 2, 'two removed from backward list' );
is_deeply(
[ $o->lrange('backward', 0, -1) ],
[ qw/
hello
foo
/ ],
'backward list as expected'
);
is( $o->lrem('all', 0, 'hello'), 3, '3 removed from all list' );
is_deeply(
[ $o->lrange('all', 0, -1) ],
[ qw/
foo
/ ],
'all list as expected'
);
}
done_testing;
|