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 = $dbh->prepare(qq{
39 insert into files (name,data) values (?,?)
42 my @files = qw(file dir/file dir/subdir/file);
45 foreach my $file (@files) {
46 $file_data{$file} = ("this is test data on ".localtime()."\n") x length($file);
47 ok($sth->execute($file,$file_data{$file}), "insert $file");
50 ok($dbh->disconnect, "disconnect after insert");
52 my $sql_filenames = qq{
73 system "fusermount -q -u $mount" || diag "nothing mounted at $mount, ok";
75 my $mnt = Fuse::DBI->mount({
76 filenames => $sql_filenames,
78 update => $sql_update,
87 my $f = $File::Find::name;
91 return unless (-f $f);
93 ok(open(F, $f), "open");
98 ok(close(F), "close");
101 $f =~ s#^\Q$mount\E/##;
103 ok($file_data{$f}, "$f exists");
105 cmp_ok(length($file_data{$f}), '==', length($tmp), "size");
106 cmp_ok($file_data{$f}, 'eq', $tmp, "content");
109 # small delay so that filesystem could mount
112 find({ wanted => \&test_file, no_chdir => 1 }, $mount);
114 ok($mnt->umount,"umount");
116 ok(unlink $test_db,"rm $test_db");