From 23aa4c6208f4c14bc204d334977eaf6a4883c4b4 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 20 Jun 2005 21:15:05 +0000 Subject: [PATCH] added tests for write to file (update database) git-svn-id: svn://svn.rot13.org/fuse_dbi/trunk@59 17f4e80c-d0e0-0310-8903-bfc3ae804c12 --- t/02sqlite.t | 32 +++++++++++++++++++++++++------- t/03pgsql.t | 30 +++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/t/02sqlite.t b/t/02sqlite.t index 55d74f8..d8d7010 100755 --- a/t/02sqlite.t +++ b/t/02sqlite.t @@ -9,7 +9,7 @@ use blib; eval "use DBD::SQLite"; plan skip_all => "DBD::SQLite required for testing" if $@; -plan tests => 37; +plan tests => 50; use_ok('DBI'); use_ok('Fuse::DBI'); @@ -35,20 +35,22 @@ ok($dbh->do(qq{ ) }), "create table files"); -ok(my $sth = $dbh->prepare(qq{ +ok(my $sth_insert = $dbh->prepare(qq{ insert into files (name,data) values (?,?) -}), "prepare"); +}), "prepare insert"); + +ok(my $sth_select = $dbh->prepare(qq{ + select data from files where name = ? +}), "prepare select"); 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($sth_insert->execute($file,$file_data{$file}), "insert $file"); } -ok($dbh->disconnect, "disconnect after insert"); - my $sql_filenames = qq{ select name as id, @@ -90,7 +92,7 @@ sub test_file { return unless (-f $f); - ok(open(F, $f), "open"); + ok(open(F, $f), "open read $f"); my $tmp = ''; while() { $tmp .= $_; @@ -104,6 +106,16 @@ sub test_file { cmp_ok(length($file_data{$f}), '==', length($tmp), "size"); cmp_ok($file_data{$f}, 'eq', $tmp, "content"); + + $tmp =~ tr/a-z/A-Z/; + $tmp .= $f; + + ok(open(F, "> $mount/$f"), "open write $mount/$f"); + print F $tmp; + ok(close(F), "close"); + + ok($sth_select->execute($f), "select $f"); + cmp_ok($sth_select->fetchrow_array(), 'eq', $tmp, "updated content"); } # small delay so that filesystem could mount @@ -113,6 +125,12 @@ find({ wanted => \&test_file, no_chdir => 1 }, $mount); ok($mnt->umount,"umount"); +undef $sth_select; +undef $sth_insert; + +ok($dbh->disconnect, "disconnect"); + ok(unlink $test_db,"rm $test_db"); ok(!-e $test_db,"cleanup"); + diff --git a/t/03pgsql.t b/t/03pgsql.t index 7fbc157..ec01060 100755 --- a/t/03pgsql.t +++ b/t/03pgsql.t @@ -9,7 +9,7 @@ use blib; eval "use DBD::Pg"; plan skip_all => "DBD::Pg required for testing" if $@; -plan tests => 34; +plan tests => 47; use_ok('DBI'); use_ok('Fuse::DBI'); @@ -36,20 +36,22 @@ ok($dbh->do(qq{ ) }), "create table files"); -ok(my $sth = $dbh->prepare(qq{ +ok(my $sth_insert = $dbh->prepare(qq{ insert into files (name,data) values (?,?) -}), "prepare"); +}), "prepare insert"); + +ok(my $sth_select = $dbh->prepare(qq{ + select data from files where name = ? +}), "prepare select"); 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($sth_insert->execute($file,$file_data{$file}), "insert $file"); } -ok($dbh->disconnect, "disconnect after insert"); - my $sql_filenames = qq{ select name as id, @@ -91,7 +93,7 @@ sub test_file { return unless (-f $f); - ok(open(F, $f), "open"); + ok(open(F, $f), "open read $f"); my $tmp = ''; while() { $tmp .= $_; @@ -105,6 +107,16 @@ sub test_file { cmp_ok(length($file_data{$f}), '==', length($tmp), "size"); cmp_ok($file_data{$f}, 'eq', $tmp, "content"); + + $tmp =~ tr/a-z/A-Z/; + $tmp .= $f; + + ok(open(F, "> $mount/$f"), "open write $mount/$f"); + print F $tmp; + ok(close(F), "close"); + + ok($sth_select->execute($f), "select $f"); + cmp_ok($sth_select->fetchrow_array(), 'eq', $tmp, "updated content"); } # small delay so that filesystem could mount @@ -114,3 +126,7 @@ find({ wanted => \&test_file, no_chdir => 1 }, $mount); ok($mnt->umount,"umount"); +undef $sth_select; +undef $sth_insert; + +ok($dbh->disconnect, "disconnect"); -- 2.20.1