11 plan skip_all => "DBD::Pg required for testing" if $@;
18 my $dsn = "DBI:Pg:dbname=$test_db";
19 my $mount = '/tmp/fuse_dbi_mnt';
21 ok((! -e $mount || rmdir $mount), "mount point $mount");
23 mkdir $mount || die "mkdir $mount: $!";
24 ok(-d $mount, "mkdir $mount");
26 ok(my $dbh = DBI->connect($dsn, , '', '', { RaiseError => 1 }),
27 "connect fusedbi test database");
29 my $drop = eval { $dbh->do(qq{ drop table files }) };
30 diag "drop table files" if ($drop);
34 name text primary key,
37 }), "create table files");
39 ok(my $sth_insert = $dbh->prepare(qq{
40 insert into files (name,data) values (?,?)
41 }), "prepare insert");
43 ok(my $sth_select = $dbh->prepare(qq{
44 select data from files where name = ?
45 }), "prepare select");
47 my @files = qw(file dir/file dir/subdir/file);
50 foreach my $file (@files) {
51 $file_data{$file} = ("this is test data on ".localtime()."\n") x length($file);
52 ok($sth_insert->execute($file,$file_data{$file}), "insert $file");
55 my $sql_filenames = qq{
76 system "fusermount -q -u $mount" || diag "nothing mounted at $mount, ok";
78 my $mnt = Fuse::DBI->mount({
79 filenames => $sql_filenames,
81 update => $sql_update,
90 my $f = $File::Find::name;
94 return unless (-f $f);
96 ok(open(F, $f), "open read $f");
101 ok(close(F), "close");
104 $f =~ s#^\Q$mount\E/##;
106 ok($file_data{$f}, "$f exists");
108 cmp_ok(length($file_data{$f}), '==', length($tmp), "size");
109 cmp_ok($file_data{$f}, 'eq', $tmp, "content");
114 ok(open(F, "> $mount/$f"), "open write $mount/$f");
116 ok(close(F), "close");
118 ok($sth_select->execute($f), "select $f");
119 cmp_ok($sth_select->fetchrow_array(), 'eq', $tmp, "updated content");
122 # small delay so that filesystem could mount
125 find({ wanted => \&test_file, no_chdir => 1 }, $mount);
127 ok($mnt->umount,"umount");
132 ok($dbh->disconnect, "disconnect");