--- trunk/t/4-store.t 2005/12/05 17:47:51 217 +++ trunk/t/4-store.t 2006/09/26 14:03:12 715 @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More tests => 29; +use Test::More tests => 40; use Test::Exception; use Cwd qw/abs_path/; use blib; @@ -17,20 +17,25 @@ diag "abs_path: $abs_path"; my $db; -my $debug = 1; +my $debug = shift @ARGV; my $no_log = 1; # force no log output +$no_log = 0 if ($debug); diag "NULL Store"; -ok($db = new WebPAC::Store( debug => $debug ), "new"); +throws_ok { new WebPAC::Store() } qr/path/, 'new without path'; -ok(! $db->path, "path"); +ok(new WebPAC::Store( path => '/tmp' ), 'new without database'); -ok(! $db->load_ds(), 'load_ds'); +ok($db = new WebPAC::Store( path => '/tmp', database => 'foobar', debug => $debug ), "new"); + +cmp_ok($db->path, 'eq', '/tmp', "path"); + +throws_ok { $db->load_ds() } qr/id/, 'load_ds without id'; ok(! $db->load_ds( id => 000 ), 'load_ds'); -ok(! $db->save_ds(), "save_ds"); -ok(! $db->save_ds( id => 000 ), 'save_ds'); +throws_ok { $db->save_ds() } qr/id/, "save_ds without id"; +throws_ok { $db->save_ds( id => 000 ) } qr/ds/, 'save_ds without ds'; undef $db; @@ -38,9 +43,10 @@ diag "Store path: $path"; -ok($db = new WebPAC::Store( path => $path, database => '.', debug => $debug, no_log => $no_log ), "new"); +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"); @@ -85,11 +91,31 @@ ok(! $db->load_ds( id => 42 ), "load_ds non-existing"); -ok($db = new WebPAC::Store( path => $path, debug => $debug, no_log => $no_log ), "new without database"); +ok($db = new WebPAC::Store( path => $path, database => 'webpac-test', debug => $debug, no_log => $no_log ), "new"); + +ok(! $db->load_ds( id => 1, input => 'foobar' ), "load_ds with invalid input"); + +ok(! $db->load_ds( id => 1, database => 'non-existant', ), "load_ds with unknown database"); + +ok($ds2 = $db->load_ds( id => 1, database => 'webpac-test' ), "load_ds"); + +my $l = { + foo => { 42 => 1 }, +}; + +ok(! $db->load_lookup( input => 'non-existant', key => 'foo' ), 'invalid load_lookup'); + +ok($db->save_lookup( input => 'foo', key => 'bar', data => $l ), "save_lookup"); + +ok(-e $db->path . '/lookup/webpac-test/foo/bar', "exists"); + +is_deeply($db->load_lookup( input => 'foo', key => 'bar' ), $l, 'load_lookup'); + +ok($db->save_lookup( database => 'baz', input => 'foo', key => 'bar', data => $l ), "save_lookup with database"); -throws_ok { $ds2 = $db->load_ds( id => 1 ) } qr/database/, "load_ds without database"; +ok(-e $db->path . '/lookup/baz/foo/bar', "exists"); -ok($ds2 = $db->load_ds( id => 1, database => '.' ), "load_ds"); +is_deeply($db->load_lookup( database => 'baz', input => 'foo', key => 'bar' ), $l, 'load_lookup'); undef $db;