#!/usr/bin/perl -w
-use Test::More tests => 40;
+use Test::More tests => 47;
use Test::Exception;
use Cwd qw/abs_path/;
use blib;
undef $db;
-ok(my $path = tempdir( CLEANUP => 1 ), "path");
+ok(my $path = tempdir( CLEANUP => $debug ? 0 : 1 ), "path");
diag "Store path: $path";
cmp_ok($db->{'path'}, 'eq', $path, "path");
+#
+# test *_ds
+#
+
throws_ok { $db->load_ds() } qr/without id/, 'load_ds without arguments';
ok(! $db->load_ds( id => 000 ), 'load_ds');
ok($ds2 = $db->load_ds( id => 1, database => 'webpac-test' ), "load_ds");
+#
+# test *_lookup
+#
+
my $l = {
foo => { 42 => 1 },
};
is_deeply($db->load_lookup( database => 'baz', input => 'foo', key => 'bar' ), $l, 'load_lookup');
+#
+# test *_row
+#
+
+my $row = {
+ '000' => [ 42 ],
+ '900' => [ qw/a foo b bar c baz/ ],
+};
+
+ok(! $db->load_row( input => 'non-existant', id => 1234 ), 'invalid load_row');
+
+ok($db->save_row( input => 'foo', id => 1234, row => $row ), "save_row");
+
+ok(-e $db->path . '/row/webpac-test/foo/1234', "exists");
+
+is_deeply($db->load_row( input => 'foo', id => 1234 ), $row, 'load_row');
+
+ok($db->save_row( database => 'baz', input => 'foo', id => 1234, row => $row ), "save_row with database");
+
+ok(-e $db->path . '/row/baz/foo/1234', "exists");
+
+is_deeply($db->load_row( database => 'baz', input => 'foo', id => 1234 ), $row, 'load_row');
+
undef $db;