| 1 | use warnings; |
|---|
| 2 | use strict; |
|---|
| 3 | |
|---|
| 4 | use Test::More; |
|---|
| 5 | |
|---|
| 6 | use FindBin; |
|---|
| 7 | |
|---|
| 8 | use lib "$FindBin::Bin"; |
|---|
| 9 | use Memd; |
|---|
| 10 | |
|---|
| 11 | if ($Memd::memd) { |
|---|
| 12 | plan tests => 12; |
|---|
| 13 | } else { |
|---|
| 14 | plan skip_all => 'Not connected'; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | my %hash = ( a => 'a', b => 2, c => [ 'a', 1 ], d => { a => 1, b => [] } ); |
|---|
| 19 | |
|---|
| 20 | is_deeply(\%hash, \%hash, 'Check that is_deeply works'); |
|---|
| 21 | |
|---|
| 22 | my $key = 'serialize'; |
|---|
| 23 | |
|---|
| 24 | ok($Memd::memd->set($key, \%hash), 'Serialize and store'); |
|---|
| 25 | |
|---|
| 26 | my $res = $Memd::memd->get($key); |
|---|
| 27 | ok($res, 'Fetch'); |
|---|
| 28 | is_deeply($res, \%hash, 'De-serialization'); |
|---|
| 29 | |
|---|
| 30 | $res = $Memd::memd->get_multi($key); |
|---|
| 31 | isa_ok($res, 'HASH'); |
|---|
| 32 | ok(exists $res->{$key}, 'Fetch'); |
|---|
| 33 | is_deeply($res->{$key}, \%hash, 'De-serialization'); |
|---|
| 34 | |
|---|
| 35 | SKIP: { |
|---|
| 36 | skip "memcached 1.2.4 is required for prepend command", 4 |
|---|
| 37 | if $Memd::version_num < 10204; |
|---|
| 38 | |
|---|
| 39 | ok($Memd::memd->prepend($key, 'garbage'), 'Prepend garbage'); |
|---|
| 40 | $res = $Memd::memd->get($key); |
|---|
| 41 | ok(! $res, 'Check that fetch fails'); |
|---|
| 42 | |
|---|
| 43 | $res = $Memd::memd->get_multi($key); |
|---|
| 44 | isa_ok($res, 'HASH'); |
|---|
| 45 | ok(! exists $res->{$key}, 'Check that fetch fails'); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | ok($Memd::memd->delete($key), 'Delete'); |
|---|