1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use Test::More tests => 25; |
use Test::More tests => 40; |
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 |
|
|
26 |
ok($db = new WebPAC::Store( debug => $debug, ), "new"); |
throws_ok { new WebPAC::Store() } qr/path/, 'new without path'; |
27 |
|
|
28 |
ok(! $db->path, "path"); |
ok(new WebPAC::Store( path => '/tmp' ), 'new without database'); |
29 |
|
|
30 |
ok(! $db->load_ds(), 'load_ds'); |
ok($db = new WebPAC::Store( path => '/tmp', database => 'foobar', debug => $debug ), "new"); |
31 |
|
|
32 |
|
cmp_ok($db->path, 'eq', '/tmp', "path"); |
33 |
|
|
34 |
|
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, 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 |
|
|
56 |
|
|
57 |
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
58 |
|
|
59 |
ok(! $db->load_ds(), 'load_ds'); |
throws_ok { $db->load_ds() } qr/without id/, 'load_ds without arguments'; |
60 |
ok(! $db->load_ds( id => 000 ), 'load_ds'); |
ok(! $db->load_ds( id => 000 ), 'load_ds'); |
61 |
|
|
62 |
throws_ok { $db->save_ds() } qr/id/, "save_ds - need id"; |
throws_ok { $db->save_ds() } qr/id/, "save_ds - need id"; |
83 |
|
|
84 |
is_deeply($ds, $ds2, "loaded data"); |
is_deeply($ds, $ds2, "loaded data"); |
85 |
|
|
86 |
ok($ds2 = $db->load_ds( 1 ), "load_ds without id"); |
throws_ok { $ds2 = $db->load_ds( 1 ) } qr/HASH/, "load_ds without hash"; |
87 |
|
|
88 |
|
ok($ds2 = $db->load_ds( id => 1 ), "load_ds"); |
89 |
|
|
90 |
is_deeply($ds, $ds2, "loaded data"); |
is_deeply($ds, $ds2, "loaded data"); |
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 => 'webpac-test', debug => $debug, no_log => $no_log ), "new"); |
95 |
|
|
96 |
|
ok(! $db->load_ds( id => 1, input => 'foobar' ), "load_ds with invalid input"); |
97 |
|
|
98 |
|
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->load_lookup( input => 'non-existant', key => 'foo' ), 'invalid load_lookup'); |
107 |
|
|
108 |
|
ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup"); |
109 |
|
|
110 |
|
ok(-e $db->path . '/lookup/webpac-test/foo/bar', "exists"); |
111 |
|
|
112 |
|
is_deeply($db->load_lookup( input => 'foo', key => 'bar' ), $l, 'load_lookup'); |
113 |
|
|
114 |
|
ok($db->save_lookup( database => 'baz', input => 'foo', key => 'bar', data => $l ), "save_lookup with database"); |
115 |
|
|
116 |
|
ok(-e $db->path . '/lookup/baz/foo/bar', "exists"); |
117 |
|
|
118 |
|
is_deeply($db->load_lookup( database => 'baz', input => 'foo', key => 'bar' ), $l, 'load_lookup'); |
119 |
|
|
120 |
undef $db; |
undef $db; |
121 |
|
|