/[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 735 by dpavlin, Mon Oct 2 09:31:25 2006 UTC revision 949 by dpavlin, Thu Nov 1 00:16:48 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use Test::More tests => 47;  use strict;
 use Test::Exception;  
 use Cwd qw/abs_path/;  
4  use blib;  use blib;
5    
6    use Test::More tests => 38;
7    
8  use File::Temp qw/tempdir/;  use File::Temp qw/tempdir/;
 use strict;  
 use Data::Dumper;  
9    
10  BEGIN {  BEGIN {
11    use_ok( 'WebPAC::Test' );
12  use_ok( 'WebPAC::Store' );  use_ok( 'WebPAC::Store' );
13  }  }
14    
 ok(my $abs_path = abs_path($0), "abs_path");  
 $abs_path =~ s#/[^/]*$#/#;  
 diag "abs_path: $abs_path";  
   
15  my $db;  my $db;
 my $debug = shift @ARGV;  
 my $no_log = 1; # force no log output  
 $no_log = 0 if ($debug);  
16    
17  diag "NULL Store";  diag "NULL Store";
18    
19  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");  
20    
21  cmp_ok($db->path, 'eq', '/tmp', "path");  ok($db = new WebPAC::Store({ database => 'foobar', %LOG }), "new");
22    
23  throws_ok { $db->load_ds() } qr/id/, 'load_ds without id';  throws_ok { $db->load_ds() } qr/id/, 'load_ds without id';
24  ok(! $db->load_ds( id => 000 ), 'load_ds');  ok(! $db->load_ds( id => 000 ), 'load_ds');
# Line 39  throws_ok { $db->save_ds( id => 000 ) } Line 28  throws_ok { $db->save_ds( id => 000 ) }
28    
29  undef $db;  undef $db;
30    
31  ok(my $path = tempdir( CLEANUP => $debug ? 0 : 1 ), "path");  ok($db = new WebPAC::Store({ database => 'webpac-test', %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");  
32    
33  #  #
34  # test *_ds  # test *_ds
# Line 95  is_deeply($ds, $ds2, "loaded data"); Line 69  is_deeply($ds, $ds2, "loaded data");
69    
70  ok(! $db->load_ds( id => 42 ), "load_ds non-existing");  ok(! $db->load_ds( id => 42 ), "load_ds non-existing");
71    
72  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', %LOG }), "new");
73    
74  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");
75    
# Line 115  ok(! $db->load_lookup( input => 'non-exi Line 89  ok(! $db->load_lookup( input => 'non-exi
89    
90  ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup");  ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup");
91    
92  ok(-e $db->path . '/lookup/webpac-test/foo/bar', "exists");  ok(-e $db->var_path( 'lookup', 'webpac-test', 'foo', 'bar'), "exists");
93    
94  is_deeply($db->load_lookup( input => 'foo', key => 'bar' ), $l, 'load_lookup');  is_deeply($db->load_lookup( input => 'foo', key => 'bar' ), $l, 'load_lookup');
95    
96  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");
97    
98  ok(-e $db->path . '/lookup/baz/foo/bar', "exists");  ok(-e $db->var_path( '/lookup','baz','foo','bar'), "exists");
99    
100  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');
101    
# Line 138  ok(! $db->load_row( input => 'non-exista Line 112  ok(! $db->load_row( input => 'non-exista
112    
113  ok($db->save_row( input => 'foo', id => 1234, row => $row ), "save_row");  ok($db->save_row( input => 'foo', id => 1234, row => $row ), "save_row");
114    
115  ok(-e $db->path . '/row/webpac-test/foo/1234', "exists");  ok(-e $db->var_path( 'row','webpac-test','foo',1234), "exists");
116    
117  is_deeply($db->load_row( input => 'foo', id => 1234 ), $row, 'load_row');  is_deeply($db->load_row( input => 'foo', id => 1234 ), $row, 'load_row');
118    
119  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");
120    
121  ok(-e $db->path . '/row/baz/foo/1234', "exists");  ok(-e $db->var_path( 'row','baz','foo',1234), "exists");
122    
123  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');
124    

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

  ViewVC Help
Powered by ViewVC 1.1.26