10 eval "use DBD::SQLite";
11 plan skip_all => "DBD::SQLite required for testing" if $@;
17 my $test_db = 'fusedbi.db';
18 my $dsn = "DBI:SQLite:dbname=$test_db";
19 my $mount = '/tmp/fuse_dbi_mnt';
21 ok((! -e $test_db || unlink $test_db), "test db: $test_db");
23 ok((! -e $mount || rmdir $mount), "mount point $mount");
25 mkdir $mount || die "mkdir $mount: $!";
26 ok(-d $mount, "mkdir $mount");
28 ok(my $dbh = DBI->connect($dsn, , '', '', { RaiseError => 1 }),
29 "connect fusedbi test database");
33 name text primary key,
36 }), "create table files");
38 ok(my $sth_insert = $dbh->prepare(qq{
39 insert into files (name,data) values (?,?)
40 }), "prepare insert");
42 ok(my $sth_select = $dbh->prepare(qq{
43 select data from files where name = ?
44 }), "prepare select");
46 my @files = qw(file dir/file dir/subdir/file);
49 foreach my $file (@files) {
50 $file_data{$file} = ("this is test data on ".localtime()."\n") x length($file);
51 ok($sth_insert->execute($file,$file_data{$file}), "insert $file");
54 my $sql_filenames = qq{
75 system "fusermount -q -u $mount" || diag "nothing mounted at $mount, ok";
77 my $mnt = Fuse::DBI->mount({
78 filenames => $sql_filenames,
80 update => $sql_update,
89 my $f = $File::Find::name;
93 return unless (-f $f);
95 ok(open(F, $f), "open read $f");
100 ok(close(F), "close");
103 $f =~ s#^\Q$mount\E/##;
105 ok($file_data{$f}, "$f exists");
107 cmp_ok(length($file_data{$f}), '==', length($tmp), "size");
108 cmp_ok($file_data{$f}, 'eq', $tmp, "content");
113 ok(open(F, "> $mount/$f"), "open write $mount/$f");
115 ok(close(F), "close");
117 ok($sth_select->execute($f), "select $f");
118 cmp_ok($sth_select->fetchrow_array(), 'eq', $tmp, "updated content");
121 # small delay so that filesystem could mount
124 find({ wanted => \&test_file, no_chdir => 1 }, $mount);
126 ok($mnt->umount,"umount");
131 ok($dbh->disconnect, "disconnect");
133 ok(unlink $test_db,"rm $test_db");
135 ok(!-e $test_db,"cleanup");