1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use Test::More tests => 31; |
use Test::More tests => 37; |
4 |
use Test::Exception; |
use Test::Exception; |
5 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
6 |
use blib; |
use blib; |
17 |
diag "abs_path: $abs_path"; |
diag "abs_path: $abs_path"; |
18 |
|
|
19 |
my $db; |
my $db; |
20 |
my $debug = 1; |
my $debug = shift @ARGV; |
21 |
my $no_log = 1; # force no log output |
my $no_log = 1; # force no log output |
22 |
|
$no_log = 0 if ($debug); |
23 |
|
|
24 |
diag "NULL Store"; |
diag "NULL Store"; |
25 |
|
|
27 |
|
|
28 |
throws_ok { new WebPAC::Store( path => '/tmp' ) } qr/database/, 'new without database'; |
throws_ok { new WebPAC::Store( path => '/tmp' ) } qr/database/, 'new without database'; |
29 |
|
|
30 |
ok($db = new WebPAC::Store( path => '/tmp', database => '.', debug => $debug ), "new"); |
ok($db = new WebPAC::Store( path => '/tmp', database => 'foobar', debug => $debug ), "new"); |
31 |
|
|
32 |
ok(! $db->path, "path"); |
cmp_ok($db->path, 'eq', '/tmp', "path"); |
33 |
|
|
34 |
ok(! $db->load_ds(), 'load_ds'); |
throws_ok { $db->load_ds() } qr/id/, 'load_ds without id'; |
35 |
ok(! $db->load_ds( id => 000 ), 'load_ds'); |
ok(! $db->load_ds( id => 000 ), 'load_ds'); |
36 |
|
|
37 |
ok(! $db->save_ds(), "save_ds"); |
throws_ok { $db->save_ds() } qr/id/, "save_ds without id"; |
38 |
ok(! $db->save_ds( id => 000 ), 'save_ds'); |
throws_ok { $db->save_ds( id => 000 ) } qr/ds/, 'save_ds without ds'; |
39 |
|
|
40 |
undef $db; |
undef $db; |
41 |
|
|
43 |
|
|
44 |
diag "Store path: $path"; |
diag "Store path: $path"; |
45 |
|
|
46 |
ok($db = new WebPAC::Store( path => $path, database => '.', debug => $debug, no_log => $no_log ), "new"); |
ok($db = new WebPAC::Store( path => $path, database => 'webpac-test', debug => $debug, no_log => $no_log ), "new"); |
47 |
|
|
48 |
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
49 |
|
cmp_ok($db->path, 'eq', $path, "path"); |
50 |
|
|
51 |
ok(! $db->path(''), "path - disable caching"); |
ok(! $db->path(''), "path - disable caching"); |
52 |
|
|
91 |
|
|
92 |
ok(! $db->load_ds( id => 42 ), "load_ds non-existing"); |
ok(! $db->load_ds( id => 42 ), "load_ds non-existing"); |
93 |
|
|
94 |
ok($db = new WebPAC::Store( path => $path, database => '.', debug => $debug, no_log => $no_log ), "new"); |
ok($db = new WebPAC::Store( path => $path, database => 'webpac-test', debug => $debug, no_log => $no_log ), "new"); |
95 |
|
|
96 |
ok(! $db->load_ds( id => 1, prefix => 'foobar' ), "load_ds with invalid prefix"); |
ok(! $db->load_ds( id => 1, input => 'foobar' ), "load_ds with invalid input"); |
97 |
|
|
98 |
ok($ds2 = $db->load_ds( id => 1, database => '.' ), "load_ds"); |
ok(! $db->load_ds( id => 1, database => 'non-existant', ), "load_ds with unknown database"); |
99 |
|
|
100 |
|
ok($ds2 = $db->load_ds( id => 1, database => 'webpac-test' ), "load_ds"); |
101 |
|
|
102 |
|
my $l = { |
103 |
|
foo => { 42 => 1 }, |
104 |
|
}; |
105 |
|
|
106 |
|
ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup"); |
107 |
|
|
108 |
|
ok(-e $db->path . '/lookup/webpac-test/foo/bar', "exists"); |
109 |
|
|
110 |
|
ok($db->save_lookup( database => 'baz', input => 'foo', key => 'bar', data => $l ), "save_lookup with database"); |
111 |
|
|
112 |
|
ok(-e $db->path . '/lookup/baz/foo/bar', "exists"); |
113 |
|
|
114 |
undef $db; |
undef $db; |
115 |
|
|