/[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 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 => 25;  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 = 1;  
 my $no_log = 1; # force no log output  
16    
17  diag "NULL Store";  diag "NULL Store";
18    
19  ok($db = new WebPAC::Store( debug => $debug, ), "new");  ok(new WebPAC::Store(), 'new without database');
20    
21  ok(! $db->path, "path");  ok($db = new WebPAC::Store({ database => 'foobar', %LOG }), "new");
22    
23  ok(! $db->load_ds(), 'load_ds');  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');
25    
26  ok(! $db->save_ds(), "save_ds");  throws_ok { $db->save_ds() } qr/id/, "save_ds without id";
27  ok(! $db->save_ds( id => 000 ), 'save_ds');  throws_ok { $db->save_ds( id => 000 ) } qr/ds/, 'save_ds without ds';
28    
29  undef $db;  undef $db;
30    
31  ok(my $path = tempdir( CLEANUP => 1 ), "path");  ok($db = new WebPAC::Store({ database => 'webpac-test', %LOG }), "new");
   
 diag "Store path: $path";  
   
 ok($db = new WebPAC::Store( path => $path, debug => $debug, no_log => $no_log ), "new");  
   
 cmp_ok($db->{'path'}, 'eq', $path, "path");  
   
 ok(! $db->path(''), "path - disable caching");  
32    
33  ok(! defined($db->{'path'}), "no path");  #
34    # test *_ds
35    #
36    
37  ok($db->path( $path ), "path($path)");  throws_ok { $db->load_ds() } qr/without id/, 'load_ds without arguments';
   
 cmp_ok($db->{'path'}, 'eq', $path, "path");  
   
 ok(! $db->load_ds(), 'load_ds');  
38  ok(! $db->load_ds( id => 000 ), 'load_ds');  ok(! $db->load_ds( id => 000 ), 'load_ds');
39    
40  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 61  ok(my $ds2 = $db->load_ds( id => 1 ), "l
61    
62  is_deeply($ds, $ds2, "loaded data");  is_deeply($ds, $ds2, "loaded data");
63    
64  ok($ds2 = $db->load_ds( 1 ), "load_ds without id");  throws_ok { $ds2 = $db->load_ds( 1 ) } qr/HASH/, "load_ds without hash";
65    
66    ok($ds2 = $db->load_ds( id => 1 ), "load_ds");
67    
68  is_deeply($ds, $ds2, "loaded data");  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({ database => 'webpac-test', %LOG }), "new");
73    
74    ok(! $db->load_ds( id => 1, input => 'foobar' ), "load_ds with invalid input");
75    
76    ok(! $db->load_ds( id => 1, database => 'non-existant', ), "load_ds with unknown database");
77    
78    ok($ds2 = $db->load_ds( id => 1, database => 'webpac-test' ), "load_ds");
79    
80    #
81    # test *_lookup
82    #
83    
84    my $l = {
85            foo => { 42 => 1 },
86    };
87    
88    ok(! $db->load_lookup( input => 'non-existant', key => 'foo' ), 'invalid load_lookup');
89    
90    ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup");
91    
92    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');
95    
96    ok($db->save_lookup( database => 'baz', input => 'foo', key => 'bar', data => $l ), "save_lookup with database");
97    
98    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');
101    
102    #
103    # test *_row
104    #
105    
106    my $row = {
107            '000' => [ 42 ],
108            '900' => [ qw/a foo b bar c baz/ ],
109    };
110    
111    ok(! $db->load_row( input => 'non-existant', id => 1234 ), 'invalid load_row');
112    
113    ok($db->save_row( input => 'foo', id => 1234, row => $row ), "save_row");
114    
115    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');
118    
119    ok($db->save_row( database => 'baz', input => 'foo', id => 1234, row => $row ), "save_row with database");
120    
121    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');
124    
125  undef $db;  undef $db;
126    

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

  ViewVC Help
Powered by ViewVC 1.1.26