/[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 713 by dpavlin, Tue Sep 26 12:42:49 2006 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 => 37;  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 25  diag "NULL Store"; Line 25  diag "NULL Store";
25    
26  throws_ok { new WebPAC::Store() } qr/path/, 'new without path';  throws_ok { new WebPAC::Store() } qr/path/, 'new without path';
27    
28  throws_ok { new WebPAC::Store( path => '/tmp' ) } qr/database/, 'new without database';  ok(new WebPAC::Store( path => '/tmp' ), 'new without database');
29    
30  ok($db = new WebPAC::Store( path => '/tmp', database => 'foobar', debug => $debug ), "new");  ok($db = new WebPAC::Store( path => '/tmp', database => 'foobar', debug => $debug ), "new");
31    
# Line 39  throws_ok { $db->save_ds( id => 000 ) } Line 39  throws_ok { $db->save_ds( id => 000 ) }
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    
# Line 56  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    #
60    # test *_ds
61    #
62    
63  throws_ok { $db->load_ds() } qr/without id/, 'load_ds without arguments';  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    
# Line 99  ok(! $db->load_ds( id => 1, database => Line 103  ok(! $db->load_ds( id => 1, database =>
103    
104  ok($ds2 = $db->load_ds( id => 1, database => 'webpac-test' ), "load_ds");  ok($ds2 = $db->load_ds( id => 1, database => 'webpac-test' ), "load_ds");
105    
106    #
107    # test *_lookup
108    #
109    
110  my $l = {  my $l = {
111          foo => { 42 => 1 },          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");  ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup");
117    
118  ok(-e $db->path . '/lookup/webpac-test/foo/bar', "exists");  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");  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");  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.713  
changed lines
  Added in v.735

  ViewVC Help
Powered by ViewVC 1.1.26