1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use Test::More tests => 47; |
use Test::More tests => 37; |
4 |
use Test::Exception; |
use Test::Exception; |
|
use Cwd qw/abs_path/; |
|
5 |
use blib; |
use blib; |
6 |
use File::Temp qw/tempdir/; |
use File::Temp qw/tempdir/; |
7 |
use strict; |
use strict; |
8 |
use Data::Dumper; |
use Data::Dump; |
9 |
|
|
10 |
BEGIN { |
BEGIN { |
11 |
use_ok( 'WebPAC::Store' ); |
use_ok( 'WebPAC::Store' ); |
12 |
} |
} |
13 |
|
|
|
ok(my $abs_path = abs_path($0), "abs_path"); |
|
|
$abs_path =~ s#/[^/]*$#/#; |
|
|
diag "abs_path: $abs_path"; |
|
|
|
|
14 |
my $db; |
my $db; |
15 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
16 |
my $no_log = 1; # force no log output |
my $no_log = 1; # force no log output |
18 |
|
|
19 |
diag "NULL Store"; |
diag "NULL Store"; |
20 |
|
|
21 |
throws_ok { new WebPAC::Store() } qr/path/, 'new without path'; |
ok(new WebPAC::Store(), 'new without database'); |
|
|
|
|
ok(new WebPAC::Store( path => '/tmp' ), 'new without database'); |
|
|
|
|
|
ok($db = new WebPAC::Store( path => '/tmp', database => 'foobar', debug => $debug ), "new"); |
|
22 |
|
|
23 |
cmp_ok($db->path, 'eq', '/tmp', "path"); |
ok($db = new WebPAC::Store({ database => 'foobar', debug => $debug }), "new"); |
24 |
|
|
25 |
throws_ok { $db->load_ds() } qr/id/, 'load_ds without id'; |
throws_ok { $db->load_ds() } qr/id/, 'load_ds without id'; |
26 |
ok(! $db->load_ds( id => 000 ), 'load_ds'); |
ok(! $db->load_ds( id => 000 ), 'load_ds'); |
30 |
|
|
31 |
undef $db; |
undef $db; |
32 |
|
|
33 |
ok(my $path = tempdir( CLEANUP => $debug ? 0 : 1 ), "path"); |
ok($db = new WebPAC::Store({ database => 'webpac-test', debug => $debug, no_log => $no_log }), "new"); |
|
|
|
|
diag "Store path: $path"; |
|
|
|
|
|
ok($db = new WebPAC::Store( path => $path, database => 'webpac-test', debug => $debug, no_log => $no_log ), "new"); |
|
|
|
|
|
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
|
|
cmp_ok($db->path, 'eq', $path, "path"); |
|
|
|
|
|
ok(! $db->path(''), "path - disable caching"); |
|
|
|
|
|
ok(! defined($db->{'path'}), "no path"); |
|
|
|
|
|
ok($db->path( $path ), "path($path)"); |
|
|
|
|
|
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
|
34 |
|
|
35 |
# |
# |
36 |
# test *_ds |
# test *_ds |
71 |
|
|
72 |
ok(! $db->load_ds( id => 42 ), "load_ds non-existing"); |
ok(! $db->load_ds( id => 42 ), "load_ds non-existing"); |
73 |
|
|
74 |
ok($db = new WebPAC::Store( path => $path, database => 'webpac-test', debug => $debug, no_log => $no_log ), "new"); |
ok($db = new WebPAC::Store({ database => 'webpac-test', debug => $debug, no_log => $no_log }), "new"); |
75 |
|
|
76 |
ok(! $db->load_ds( id => 1, input => 'foobar' ), "load_ds with invalid input"); |
ok(! $db->load_ds( id => 1, input => 'foobar' ), "load_ds with invalid input"); |
77 |
|
|
91 |
|
|
92 |
ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup"); |
ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup"); |
93 |
|
|
94 |
ok(-e $db->path . '/lookup/webpac-test/foo/bar', "exists"); |
ok(-e $db->var_path( 'lookup', 'webpac-test', 'foo', 'bar'), "exists"); |
95 |
|
|
96 |
is_deeply($db->load_lookup( input => 'foo', key => 'bar' ), $l, 'load_lookup'); |
is_deeply($db->load_lookup( input => 'foo', key => 'bar' ), $l, 'load_lookup'); |
97 |
|
|
98 |
ok($db->save_lookup( database => 'baz', input => 'foo', key => 'bar', data => $l ), "save_lookup with database"); |
ok($db->save_lookup( database => 'baz', input => 'foo', key => 'bar', data => $l ), "save_lookup with database"); |
99 |
|
|
100 |
ok(-e $db->path . '/lookup/baz/foo/bar', "exists"); |
ok(-e $db->var_path( '/lookup','baz','foo','bar'), "exists"); |
101 |
|
|
102 |
is_deeply($db->load_lookup( database => 'baz', input => 'foo', key => 'bar' ), $l, 'load_lookup'); |
is_deeply($db->load_lookup( database => 'baz', input => 'foo', key => 'bar' ), $l, 'load_lookup'); |
103 |
|
|
114 |
|
|
115 |
ok($db->save_row( input => 'foo', id => 1234, row => $row ), "save_row"); |
ok($db->save_row( input => 'foo', id => 1234, row => $row ), "save_row"); |
116 |
|
|
117 |
ok(-e $db->path . '/row/webpac-test/foo/1234', "exists"); |
ok(-e $db->var_path( 'row','webpac-test','foo',1234), "exists"); |
118 |
|
|
119 |
is_deeply($db->load_row( input => 'foo', id => 1234 ), $row, 'load_row'); |
is_deeply($db->load_row( input => 'foo', id => 1234 ), $row, 'load_row'); |
120 |
|
|
121 |
ok($db->save_row( database => 'baz', input => 'foo', id => 1234, row => $row ), "save_row with database"); |
ok($db->save_row( database => 'baz', input => 'foo', id => 1234, row => $row ), "save_row with database"); |
122 |
|
|
123 |
ok(-e $db->path . '/row/baz/foo/1234', "exists"); |
ok(-e $db->var_path( 'row','baz','foo',1234), "exists"); |
124 |
|
|
125 |
is_deeply($db->load_row( database => 'baz', input => 'foo', id => 1234 ), $row, 'load_row'); |
is_deeply($db->load_row( database => 'baz', input => 'foo', id => 1234 ), $row, 'load_row'); |
126 |
|
|