2 |
use strict; |
use strict; |
3 |
use warnings; |
use warnings; |
4 |
|
|
5 |
use Test::More tests => 13; |
use Test::More tests => 21; |
6 |
use lib 'lib'; |
use lib 'lib'; |
7 |
|
|
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
|
10 |
my $debug = 1 if @ARGV; |
my $debug = @ARGV ? 1 : 0; |
11 |
|
|
12 |
BEGIN { |
BEGIN { |
13 |
use_ok('Frey::Storage'); |
use_ok('Frey::Storage'); |
27 |
ok( my $o = Mock->new( debug => $debug ), 'new' ); |
ok( my $o = Mock->new( debug => $debug ), 'new' ); |
28 |
diag $o->dump(2) if $debug; |
diag $o->dump(2) if $debug; |
29 |
|
|
30 |
|
foreach my $path ( map { "var/t/Frey.Storage.$_" } ( 'yaml', 'storable' ) ) { |
31 |
|
|
32 |
|
diag $path; |
33 |
|
|
34 |
my $data = { foo => 'bar' }; |
my $data = { foo => 'bar' }; |
|
my $path = 'var/test.Frey.Storeage'; |
|
35 |
|
|
36 |
ok( $o->store( $path, $data ), 'store' ); |
ok( $o->store( $path, $data ), 'store' ); |
37 |
|
|
47 |
$data->{baz} = 42; |
$data->{baz} = 42; |
48 |
ok( $o->store( $path, $data ), 'store again' ); |
ok( $o->store( $path, $data ), 'store again' ); |
49 |
|
|
50 |
my $new; |
ok( my $new = $o->reload( $path ), 'reload' ); |
|
ok( $o->reload( $path, \$new ), 'reload' ); |
|
51 |
|
|
52 |
diag dump( $data, $new ) if $debug; |
diag dump( $data, $new ) if $debug; |
53 |
is_deeply( $data, $new, 'same' ); |
is_deeply( $data, $new, 'same' ); |
54 |
|
|
55 |
my $keep = { 'test' => 'data' }; |
ok( ! $o->reload( $path ), 'no reload' ); |
56 |
my $new2 = $keep; |
|
57 |
ok( ! $o->reload( $path, \$new2 ), 'reload' ); |
} # foreach |
58 |
is_deeply( $keep, $new2, 'same' ); |
|
59 |
|
ok( ! $o->load( 'var/something.which.doesnt.exist' ), 'load without file' ); |