8 |
|
|
9 |
=cut |
=cut |
10 |
|
|
11 |
use Jifty::Test tests => 11; |
use Jifty::Test tests => 14; |
12 |
|
|
13 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
14 |
|
|
19 |
|
|
20 |
my $instance = 'cache'; |
my $instance = 'cache'; |
21 |
|
|
22 |
ok( my $strix = A3C::Cache->new({ instance => $instance }), 'new' ); |
ok( my $strix = A3C::Cache->new({ instance => $instance, dir => 't' }), 'new' ); |
23 |
isa_ok( $strix, 'A3C::Cache' ); |
isa_ok( $strix, 'A3C::Cache' ); |
24 |
|
|
25 |
# cache |
# cache |
26 |
ok( my $path = $strix->cache_path( 'test', 42, 'bar' ), 'cache_path' ); |
ok( my $path = $strix->cache_path( 'test', 42, 'bar' ), 'cache_path' ); |
27 |
like( $path, qr/test-42-bar/, 'correct' ); |
like( $path, qr'var/t/.*test-42-bar', 'correct' ); |
28 |
|
diag "path: $path"; |
29 |
|
|
30 |
my $data = 'scalar'; |
my $data = 'scalar'; |
31 |
SKIP: { |
SKIP: { |
33 |
ok( $strix->write_cache( $data, 'test-scalar' ), 'write_cache scalar' ); |
ok( $strix->write_cache( $data, 'test-scalar' ), 'write_cache scalar' ); |
34 |
is_deeply( $strix->read_cache( 'test-scalar' ), $data, 'read_cache scalar' ); |
is_deeply( $strix->read_cache( 'test-scalar' ), $data, 'read_cache scalar' ); |
35 |
} |
} |
36 |
|
|
37 |
$data = { foo => 42, bar => 'baz' }; |
$data = { foo => 42, bar => 'baz' }; |
38 |
ok( $strix->write_cache( $data, 'test-hash' ), 'write_cache hash' ); |
ok( $strix->write_cache( $data, 'test-hash' ), 'write_cache hash' ); |
39 |
is_deeply( $strix->read_cache( 'test-hash' ), $data, 'read_cache hash' ); |
is_deeply( $strix->read_cache( 'test-hash' ), $data, 'read_cache hash' ); |
40 |
|
|
41 |
|
bless $data, 'foo'; |
42 |
|
like( ref($data), qr/foo/, 'data blessed' ); |
43 |
|
diag "blessed = ",dump( $data ) if $debug; |
44 |
|
ok( $strix->write_cache( $data, 'test-blessed' ), 'write_cache blessed' ); |
45 |
|
is_deeply( $strix->read_cache( 'test-blessed' ), $data, 'read_cache blessed' ); |
46 |
|
|
47 |
$data = [ 1, 2, 42 ]; |
$data = [ 1, 2, 42 ]; |
48 |
ok( $strix->write_cache( $data, 'test-array' ), 'write_cache array' ); |
ok( $strix->write_cache( $data, 'test-array' ), 'write_cache array' ); |
49 |
is_deeply( $strix->read_cache( 'test-array' ), $data, 'read_cache array' ); |
is_deeply( $strix->read_cache( 'test-array' ), $data, 'read_cache array' ); |