/[fuse_dbi]/fuse-couchdb/t/02sqlite.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /fuse-couchdb/t/02sqlite.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/t/02database.t revision 15 by dpavlin, Sun Sep 5 16:04:35 2004 UTC fuse-couchdb/t/02sqlite.t revision 68 by dpavlin, Fri Apr 24 23:43:18 2009 UTC
# Line 4  use strict; Line 4  use strict;
4  use warnings;  use warnings;
5    
6  use Test::More;  use Test::More;
7    use File::Find;
8  use blib;  use blib;
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 => 14;  plan tests => 50;
13    
14  use_ok('DBI');  use_ok('DBI');
15  use_ok('Fuse::DBI');  use_ok('Fuse::DBI');
# Line 34  ok($dbh->do(qq{ Line 35  ok($dbh->do(qq{
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  foreach my $file (qw(file dir/file dir/subdir/file)) {  ok(my $sth_select = $dbh->prepare(qq{
43          my $data = "this is test data\n" x length($file);          select data from files where name = ?
44          ok($sth->execute($file,$data), "insert $file");  }), "prepare select");
45    
46    my @files = qw(file dir/file dir/subdir/file);
47    my %file_data;
48    
49    foreach my $file (@files) {
50            $file_data{$file} = ("this is test data on ".localtime()."\n") x length($file);
51            ok($sth_insert->execute($file,$file_data{$file}), "insert $file");
52  }  }
53    
54  my $sql_filenames = qq{  my $sql_filenames = qq{
# Line 48  my $sql_filenames = qq{ Line 56  my $sql_filenames = qq{
56                  name as id,                  name as id,
57                  name as filename,                  name as filename,
58                  length(data) as size,                  length(data) as size,
59                  0 as writable                  1 as writable
60          from files          from files
61  };  };
62    
# Line 72  my $mnt = Fuse::DBI->mount({ Line 80  my $mnt = Fuse::DBI->mount({
80          update => $sql_update,          update => $sql_update,
81          dsn => $dsn,          dsn => $dsn,
82          mount => $mount,          mount => $mount,
83            fork => 1,
84  });  });
85    
86  ok($mnt, "mount");  ok($mnt, "mount");
87    
88  diag "press enter to continue";  sub test_file {
89  my $foo = <STDIN>;          my $f = $File::Find::name;
90    
91            ok($f, "file $f");
92    
93            return unless (-f $f);
94    
95            ok(open(F, $f), "open read $f");
96            my $tmp = '';
97            while(<F>) {
98                    $tmp .= $_;
99            }
100            ok(close(F), "close");
101    
102            # strip mountpoint
103            $f =~ s#^\Q$mount\E/##;
104    
105            ok($file_data{$f}, "$f exists");
106    
107            cmp_ok(length($file_data{$f}), '==', length($tmp), "size");
108            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
122    sleep(1);
123    
124    find({ wanted => \&test_file, no_chdir => 1 }, $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");
136    

Legend:
Removed from v.15  
changed lines
  Added in v.68

  ViewVC Help
Powered by ViewVC 1.1.26