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