/[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 887 by dpavlin, Mon Sep 3 15:26:46 2007 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 => 37;
4  use Test::Exception;  use Test::Exception;
 use Cwd qw/abs_path/;  
5  use blib;  use blib;
6  use File::Temp qw/tempdir/;  use File::Temp qw/tempdir/;
7  use strict;  use strict;
8  use Data::Dumper;  use Data::Dump;
9    
10  BEGIN {  BEGIN {
11  use_ok( 'WebPAC::Store' );  use_ok( 'WebPAC::Store' );
12  }  }
13    
 ok(my $abs_path = abs_path($0), "abs_path");  
 $abs_path =~ s#/[^/]*$#/#;  
 diag "abs_path: $abs_path";  
   
14  my $db;  my $db;
15  my $debug = 1;  my $debug = shift @ARGV;
16  my $no_log = 1; # force no log output  my $no_log = 1; # force no log output
17    $no_log = 0 if ($debug);
18    
19  diag "NULL Store";  diag "NULL Store";
20    
21  ok($db = new WebPAC::Store( debug => $debug, ), "new");  ok(new WebPAC::Store(), 'new without database');
22    
23  ok(! $db->path, "path");  ok($db = new WebPAC::Store({ database => 'foobar', debug => $debug }), "new");
24    
25  ok(! $db->load_ds(), 'load_ds');  throws_ok { $db->load_ds() } qr/id/, 'load_ds without id';
26  ok(! $db->load_ds( id => 000 ), 'load_ds');  ok(! $db->load_ds( id => 000 ), 'load_ds');
27    
28  ok(! $db->save_ds(), "save_ds");  throws_ok { $db->save_ds() } qr/id/, "save_ds without id";
29  ok(! $db->save_ds( id => 000 ), 'save_ds');  throws_ok { $db->save_ds( id => 000 ) } qr/ds/, 'save_ds without ds';
30    
31  undef $db;  undef $db;
32    
33  ok(my $path = tempdir( CLEANUP => 1 ), "path");  ok($db = new WebPAC::Store({ database => 'webpac-test', debug => $debug, no_log => $no_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");  
34    
35  ok(! $db->path(''), "path - disable caching");  #
36    # test *_ds
37    #
38    
39  ok(! defined($db->{'path'}), "no path");  throws_ok { $db->load_ds() } qr/without id/, 'load_ds without arguments';
   
 ok($db->path( $path ), "path($path)");  
   
 cmp_ok($db->{'path'}, 'eq', $path, "path");  
   
 ok(! $db->load_ds(), 'load_ds');  
40  ok(! $db->load_ds( id => 000 ), 'load_ds');  ok(! $db->load_ds( id => 000 ), 'load_ds');
41    
42  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 63  ok(my $ds2 = $db->load_ds( id => 1 ), "l
63    
64  is_deeply($ds, $ds2, "loaded data");  is_deeply($ds, $ds2, "loaded data");
65    
66  ok($ds2 = $db->load_ds( 1 ), "load_ds without id");  throws_ok { $ds2 = $db->load_ds( 1 ) } qr/HASH/, "load_ds without hash";
67    
68    ok($ds2 = $db->load_ds( id => 1 ), "load_ds");
69    
70  is_deeply($ds, $ds2, "loaded data");  is_deeply($ds, $ds2, "loaded data");
71    
72  ok(! $db->load_ds( id => 42 ), "load_ds non-existing");  ok(! $db->load_ds( id => 42 ), "load_ds non-existing");
73    
74    ok($db = new WebPAC::Store({ database => 'webpac-test', debug => $debug, no_log => $no_log }), "new");
75    
76    ok(! $db->load_ds( id => 1, input => 'foobar' ), "load_ds with invalid input");
77    
78    ok(! $db->load_ds( id => 1, database => 'non-existant', ), "load_ds with unknown database");
79    
80    ok($ds2 = $db->load_ds( id => 1, database => 'webpac-test' ), "load_ds");
81    
82    #
83    # test *_lookup
84    #
85    
86    my $l = {
87            foo => { 42 => 1 },
88    };
89    
90    ok(! $db->load_lookup( input => 'non-existant', key => 'foo' ), 'invalid load_lookup');
91    
92    ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup");
93    
94    ok(-e $db->var_path( 'lookup', 'webpac-test', 'foo', 'bar'), "exists");
95    
96    is_deeply($db->load_lookup( input => 'foo', key => 'bar' ), $l, 'load_lookup');
97    
98    ok($db->save_lookup( database => 'baz', input => 'foo', key => 'bar', data => $l ), "save_lookup with database");
99    
100    ok(-e $db->var_path( '/lookup','baz','foo','bar'), "exists");
101    
102    is_deeply($db->load_lookup( database => 'baz', input => 'foo', key => 'bar' ), $l, 'load_lookup');
103    
104    #
105    # test *_row
106    #
107    
108    my $row = {
109            '000' => [ 42 ],
110            '900' => [ qw/a foo b bar c baz/ ],
111    };
112    
113    ok(! $db->load_row( input => 'non-existant', id => 1234 ), 'invalid load_row');
114    
115    ok($db->save_row( input => 'foo', id => 1234, row => $row ), "save_row");
116    
117    ok(-e $db->var_path( 'row','webpac-test','foo',1234), "exists");
118    
119    is_deeply($db->load_row( input => 'foo', id => 1234 ), $row, 'load_row');
120    
121    ok($db->save_row( database => 'baz', input => 'foo', id => 1234, row => $row ), "save_row with database");
122    
123    ok(-e $db->var_path( 'row','baz','foo',1234), "exists");
124    
125    is_deeply($db->load_row( database => 'baz', input => 'foo', id => 1234 ), $row, 'load_row');
126    
127  undef $db;  undef $db;
128    

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

  ViewVC Help
Powered by ViewVC 1.1.26