SQLite test is finally working,
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 15 Nov 2004 20:55:10 +0000 (20:55 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 15 Nov 2004 20:55:10 +0000 (20:55 +0000)
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

DBI.pm
MANIFEST
Makefile.PL
t/02sqlite.t

diff --git a/DBI.pm b/DBI.pm
index ddc083f..3537bf0 100755 (executable)
--- a/DBI.pm
+++ b/DBI.pm
@@ -13,7 +13,7 @@ use Carp;
 use Data::Dumper;
 
 
 use Data::Dumper;
 
 
-our $VERSION = '0.04';
+our $VERSION = '0.05';
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -148,6 +148,7 @@ sub mount {
 
        my $pid;
        if ($arg->{'fork'}) {
 
        my $pid;
        if ($arg->{'fork'}) {
+               $self->{'mounted'} = 1;
                $pid = fork();
                die "fork() failed: $!" unless defined $pid;
                # child will return to caller
                $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->{'read_filenames'} = sub { $self->read_filenames };
        $self->read_filenames;
 
-       $self->{'mounted'} = 1;
+       $self->{'mounted'} = 1 unless ($arg->{'fork'});
 
        $fuse_self = \$self;
 
 
        $fuse_self = \$self;
 
@@ -211,7 +212,7 @@ sub umount {
        my $self = shift;
 
        if ($self->{'mounted'}) {
        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;
        }
 
        return 1;
index 3f68082..4befab9 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4,6 +4,7 @@ MANIFEST
 README
 DBI.pm
 t/01load.t
 README
 DBI.pm
 t/01load.t
+t/02sqlite.t
 t/99pod.t
 examples/webgui.pl
 META.yml                                 Module meta-data (added by MakeMaker)
 t/99pod.t
 examples/webgui.pl
 META.yml                                 Module meta-data (added by MakeMaker)
index 3985582..5b9ae8f 100644 (file)
@@ -10,6 +10,7 @@ WriteMakefile(
        'Fuse' => 0,
        'DBI' => 0,
        'Carp' => 0,
        '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
     }, # e.g., Module::Name => 1.1
     ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
       (ABSTRACT_FROM  => 'DBI.pm', # retrieve abstract from module
index 28a58c4..4f0d593 100755 (executable)
@@ -4,11 +4,12 @@ use strict;
 use warnings;
 
 use Test::More;
 use warnings;
 
 use Test::More;
+use File::Find;
 use blib;
 
 eval "use DBD::SQLite";
 plan skip_all => "DBD::SQLite required for testing" if $@;
 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');
 
 use_ok('DBI');
 use_ok('Fuse::DBI');
@@ -38,9 +39,12 @@ ok(my $sth = $dbh->prepare(qq{
        insert into files (name,data) values (?,?)
 }), "prepare");
 
        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");
 }
 
 ok($dbh->disconnect, "disconnect after insert");
@@ -79,8 +83,33 @@ my $mnt = Fuse::DBI->mount({
 
 ok($mnt, "mount");
 
 
 ok($mnt, "mount");
 
-diag "press enter to continue";
-my $foo = <STDIN>;
+sub test_file {
+       my $f = $File::Find::name;
+
+       ok($f, "file $f");
+
+       return unless (-f $f);
+
+       ok(open(F, $f), "open");
+       my $tmp = '';
+       while(<F>) {
+               $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");
 
 
 ok($mnt->umount,"umount");