From: Dobrica Pavlinusic Date: Mon, 15 Nov 2004 20:55:10 +0000 (+0000) Subject: SQLite test is finally working, X-Git-Url: http://git.rot13.org/?p=Fuse-DBI;a=commitdiff_plain;h=8b53b090ace163fc02e100998eda16f4a0c0435b SQLite test is finally working, bumped version to 0.05, you can really umount filesystem when using fork (which is still very experimental and useful only for tests anyway) git-svn-id: svn://svn.rot13.org/fuse_dbi/trunk@33 17f4e80c-d0e0-0310-8903-bfc3ae804c12 --- diff --git a/DBI.pm b/DBI.pm index ddc083f..3537bf0 100755 --- a/DBI.pm +++ b/DBI.pm @@ -13,7 +13,7 @@ use Carp; use Data::Dumper; -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 NAME @@ -148,6 +148,7 @@ sub mount { my $pid; if ($arg->{'fork'}) { + $self->{'mounted'} = 1; $pid = fork(); die "fork() failed: $!" unless defined $pid; # child will return to caller @@ -169,7 +170,7 @@ sub mount { $self->{'read_filenames'} = sub { $self->read_filenames }; $self->read_filenames; - $self->{'mounted'} = 1; + $self->{'mounted'} = 1 unless ($arg->{'fork'}); $fuse_self = \$self; @@ -211,7 +212,7 @@ sub umount { my $self = shift; if ($self->{'mounted'}) { - system "fusermount -u ".$self->{'mount'} || croak "umount error: $!"; + system "fusermount -u ".$self->{'mount'} || warn "umount error: $!" && return 0; } return 1; diff --git a/MANIFEST b/MANIFEST index 3f68082..4befab9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4,6 +4,7 @@ MANIFEST README DBI.pm t/01load.t +t/02sqlite.t t/99pod.t examples/webgui.pl META.yml Module meta-data (added by MakeMaker) diff --git a/Makefile.PL b/Makefile.PL index 3985582..5b9ae8f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -10,6 +10,7 @@ WriteMakefile( 'Fuse' => 0, 'DBI' => 0, 'Carp' => 0, + 'File::Find' => 0, }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'DBI.pm', # retrieve abstract from module diff --git a/t/02sqlite.t b/t/02sqlite.t index 28a58c4..4f0d593 100755 --- a/t/02sqlite.t +++ b/t/02sqlite.t @@ -4,11 +4,12 @@ use strict; use warnings; use Test::More; +use File::Find; use blib; eval "use DBD::SQLite"; plan skip_all => "DBD::SQLite required for testing" if $@; -plan tests => 15; +plan tests => 36; use_ok('DBI'); use_ok('Fuse::DBI'); @@ -38,9 +39,12 @@ ok(my $sth = $dbh->prepare(qq{ insert into files (name,data) values (?,?) }), "prepare"); -foreach my $file (qw(file dir/file dir/subdir/file)) { - my $data = "this is test data\n" x length($file); - ok($sth->execute($file,$data), "insert $file"); +my @files = qw(file dir/file dir/subdir/file); +my %file_data; + +foreach my $file (@files) { + $file_data{$file} = ("this is test data on ".localtime()."\n") x length($file); + ok($sth->execute($file,$file_data{$file}), "insert $file"); } ok($dbh->disconnect, "disconnect after insert"); @@ -79,8 +83,33 @@ my $mnt = Fuse::DBI->mount({ ok($mnt, "mount"); -diag "press enter to continue"; -my $foo = ; +sub test_file { + my $f = $File::Find::name; + + ok($f, "file $f"); + + return unless (-f $f); + + ok(open(F, $f), "open"); + my $tmp = ''; + while() { + $tmp .= $_; + } + ok(close(F), "close"); + + # strip mountpoint + $f =~ s#^\Q$mount\E/##; + + ok($file_data{$f}, "$f exists"); + + cmp_ok(length($file_data{$f}), '==', length($tmp), "size"); + cmp_ok($file_data{$f}, 'eq', $tmp, "content"); +} + +# small delay so that filesystem could mount +sleep(1); + +find({ wanted => \&test_file, no_chdir => 1 }, $mount); ok($mnt->umount,"umount");