/[webpac2]/trunk/t/4-store.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/4-store.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 209 by dpavlin, Mon Dec 5 17:46:57 2005 UTC revision 735 by dpavlin, Mon Oct 2 09:31:25 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use Test::More tests => 25;  use Test::More tests => 47;
4  use Test::Exception;  use Test::Exception;
5  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
6  use blib;  use blib;
# Line 17  $abs_path =~ s#/[^/]*$#/#; Line 17  $abs_path =~ s#/[^/]*$#/#;
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    
42  ok(my $path = tempdir( CLEANUP => 1 ), "path");  ok(my $path = tempdir( CLEANUP => $debug ? 0 : 1 ), "path");
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    
# Line 50  ok($db->path( $path ), "path($path)"); Line 56  ok($db->path( $path ), "path($path)");
56    
57  cmp_ok($db->{'path'}, 'eq', $path, "path");  cmp_ok($db->{'path'}, 'eq', $path, "path");
58    
59  ok(! $db->load_ds(), 'load_ds');  #
60    # test *_ds
61    #
62    
63    throws_ok { $db->load_ds() } qr/without id/, 'load_ds without arguments';
64  ok(! $db->load_ds( id => 000 ), 'load_ds');  ok(! $db->load_ds( id => 000 ), 'load_ds');
65    
66  throws_ok { $db->save_ds() } qr/id/, "save_ds - need id";  throws_ok { $db->save_ds() } qr/id/, "save_ds - need id";
# Line 77  ok(my $ds2 = $db->load_ds( id => 1 ), "l Line 87  ok(my $ds2 = $db->load_ds( id => 1 ), "l
87    
88  is_deeply($ds, $ds2, "loaded data");  is_deeply($ds, $ds2, "loaded data");
89    
90  ok($ds2 = $db->load_ds( 1 ), "load_ds without id");  throws_ok { $ds2 = $db->load_ds( 1 ) } qr/HASH/, "load_ds without hash";
91    
92    ok($ds2 = $db->load_ds( id => 1 ), "load_ds");
93    
94  is_deeply($ds, $ds2, "loaded data");  is_deeply($ds, $ds2, "loaded data");
95    
96  ok(! $db->load_ds( id => 42 ), "load_ds non-existing");  ok(! $db->load_ds( id => 42 ), "load_ds non-existing");
97    
98    ok($db = new WebPAC::Store( path => $path, database => 'webpac-test', debug => $debug, no_log => $no_log ), "new");
99    
100    ok(! $db->load_ds( id => 1, input => 'foobar' ), "load_ds with invalid input");
101    
102    ok(! $db->load_ds( id => 1, database => 'non-existant', ), "load_ds with unknown database");
103    
104    ok($ds2 = $db->load_ds( id => 1, database => 'webpac-test' ), "load_ds");
105    
106    #
107    # test *_lookup
108    #
109    
110    my $l = {
111            foo => { 42 => 1 },
112    };
113    
114    ok(! $db->load_lookup( input => 'non-existant', key => 'foo' ), 'invalid load_lookup');
115    
116    ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup");
117    
118    ok(-e $db->path . '/lookup/webpac-test/foo/bar', "exists");
119    
120    is_deeply($db->load_lookup( input => 'foo', key => 'bar' ), $l, 'load_lookup');
121    
122    ok($db->save_lookup( database => 'baz', input => 'foo', key => 'bar', data => $l ), "save_lookup with database");
123    
124    ok(-e $db->path . '/lookup/baz/foo/bar', "exists");
125    
126    is_deeply($db->load_lookup( database => 'baz', input => 'foo', key => 'bar' ), $l, 'load_lookup');
127    
128    #
129    # test *_row
130    #
131    
132    my $row = {
133            '000' => [ 42 ],
134            '900' => [ qw/a foo b bar c baz/ ],
135    };
136    
137    ok(! $db->load_row( input => 'non-existant', id => 1234 ), 'invalid load_row');
138    
139    ok($db->save_row( input => 'foo', id => 1234, row => $row ), "save_row");
140    
141    ok(-e $db->path . '/row/webpac-test/foo/1234', "exists");
142    
143    is_deeply($db->load_row( input => 'foo', id => 1234 ), $row, 'load_row');
144    
145    ok($db->save_row( database => 'baz', input => 'foo', id => 1234, row => $row ), "save_row with database");
146    
147    ok(-e $db->path . '/row/baz/foo/1234', "exists");
148    
149    is_deeply($db->load_row( database => 'baz', input => 'foo', id => 1234 ), $row, 'load_row');
150    
151  undef $db;  undef $db;
152    

Legend:
Removed from v.209  
changed lines
  Added in v.735

  ViewVC Help
Powered by ViewVC 1.1.26