9 |
|
|
10 |
eval "use DBD::SQLite"; |
eval "use DBD::SQLite"; |
11 |
plan skip_all => "DBD::SQLite required for testing" if $@; |
plan skip_all => "DBD::SQLite required for testing" if $@; |
12 |
plan tests => 37; |
plan tests => 50; |
13 |
|
|
14 |
use_ok('DBI'); |
use_ok('DBI'); |
15 |
use_ok('Fuse::DBI'); |
use_ok('Fuse::DBI'); |
35 |
) |
) |
36 |
}), "create table files"); |
}), "create table files"); |
37 |
|
|
38 |
ok(my $sth = $dbh->prepare(qq{ |
ok(my $sth_insert = $dbh->prepare(qq{ |
39 |
insert into files (name,data) values (?,?) |
insert into files (name,data) values (?,?) |
40 |
}), "prepare"); |
}), "prepare insert"); |
41 |
|
|
42 |
|
ok(my $sth_select = $dbh->prepare(qq{ |
43 |
|
select data from files where name = ? |
44 |
|
}), "prepare select"); |
45 |
|
|
46 |
my @files = qw(file dir/file dir/subdir/file); |
my @files = qw(file dir/file dir/subdir/file); |
47 |
my %file_data; |
my %file_data; |
48 |
|
|
49 |
foreach my $file (@files) { |
foreach my $file (@files) { |
50 |
$file_data{$file} = ("this is test data on ".localtime()."\n") x length($file); |
$file_data{$file} = ("this is test data on ".localtime()."\n") x length($file); |
51 |
ok($sth->execute($file,$file_data{$file}), "insert $file"); |
ok($sth_insert->execute($file,$file_data{$file}), "insert $file"); |
52 |
} |
} |
53 |
|
|
|
ok($dbh->disconnect, "disconnect after insert"); |
|
|
|
|
54 |
my $sql_filenames = qq{ |
my $sql_filenames = qq{ |
55 |
select |
select |
56 |
name as id, |
name as id, |
92 |
|
|
93 |
return unless (-f $f); |
return unless (-f $f); |
94 |
|
|
95 |
ok(open(F, $f), "open"); |
ok(open(F, $f), "open read $f"); |
96 |
my $tmp = ''; |
my $tmp = ''; |
97 |
while(<F>) { |
while(<F>) { |
98 |
$tmp .= $_; |
$tmp .= $_; |
106 |
|
|
107 |
cmp_ok(length($file_data{$f}), '==', length($tmp), "size"); |
cmp_ok(length($file_data{$f}), '==', length($tmp), "size"); |
108 |
cmp_ok($file_data{$f}, 'eq', $tmp, "content"); |
cmp_ok($file_data{$f}, 'eq', $tmp, "content"); |
109 |
|
|
110 |
|
$tmp =~ tr/a-z/A-Z/; |
111 |
|
$tmp .= $f; |
112 |
|
|
113 |
|
ok(open(F, "> $mount/$f"), "open write $mount/$f"); |
114 |
|
print F $tmp; |
115 |
|
ok(close(F), "close"); |
116 |
|
|
117 |
|
ok($sth_select->execute($f), "select $f"); |
118 |
|
cmp_ok($sth_select->fetchrow_array(), 'eq', $tmp, "updated content"); |
119 |
} |
} |
120 |
|
|
121 |
# small delay so that filesystem could mount |
# small delay so that filesystem could mount |
125 |
|
|
126 |
ok($mnt->umount,"umount"); |
ok($mnt->umount,"umount"); |
127 |
|
|
128 |
|
undef $sth_select; |
129 |
|
undef $sth_insert; |
130 |
|
|
131 |
|
ok($dbh->disconnect, "disconnect"); |
132 |
|
|
133 |
ok(unlink $test_db,"rm $test_db"); |
ok(unlink $test_db,"rm $test_db"); |
134 |
|
|
135 |
ok(!-e $test_db,"cleanup"); |
ok(!-e $test_db,"cleanup"); |
136 |
|
|