/[fuse_dbi]/trunk/t/02database.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 /trunk/t/02database.t

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

revision 14 by dpavlin, Sun Aug 29 19:16:01 2004 UTC revision 15 by dpavlin, Sun Sep 5 16:04:35 2004 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use warnings;  use warnings;
5    
6  use Test::More tests => 3;  use Test::More;
7  use blib;  use blib;
8    
9    eval "use DBD::SQLite";
10    plan skip_all => "DBD::SQLite required for testing" if $@;
11    plan tests => 14;
12    
13    use_ok('DBI');
14  use_ok('Fuse::DBI');  use_ok('Fuse::DBI');
15    
16  my $sql_filenames = q{  my $test_db = 'fusedbi.db';
17    my $dsn = "DBI:SQLite:dbname=$test_db";
18    my $mount = '/tmp/fuse_dbi_mnt';
19    
20    ok((! -e $test_db || unlink $test_db), "test db: $test_db");
21    
22    ok((! -e $mount || rmdir $mount), "mount point $mount");
23    
24    mkdir $mount || die "mkdir $mount: $!";
25    ok(-d $mount, "mkdir $mount");
26    
27    ok(my $dbh = DBI->connect($dsn, , '', '', { RaiseError => 1 }),
28            "connect fusedbi test database");
29    
30    ok($dbh->do(qq{
31            create table files (
32                    name text primary key,
33                    data text
34            )
35    }), "create table files");
36    
37    ok(my $sth = $dbh->prepare(qq{
38            insert into files (name,data) values (?,?)
39    }), "prepare");
40    
41    foreach my $file (qw(file dir/file dir/subdir/file)) {
42            my $data = "this is test data\n" x length($file);
43            ok($sth->execute($file,$data), "insert $file");
44    }
45    
46    my $sql_filenames = qq{
47          select          select
48                  oid as id,                  name as id,
49                  namespace||'/'||name||' ['||oid||']' as filename,                  name as filename,
50                  length(template) as size,                  length(data) as size,
51                  iseditable as writable                  0 as writable
52          from template ;          from files
53  };  };
54    
55  my $sql_read = q{  my $sql_read = qq{
56          select template          select data
57                  from template                  from files
58                  where oid = ?;                  where name = ?;
59  };  };
60    
61  my $sql_update = q{  my $sql_update = qq{
62          update template          update files
63                  set template = ?                          set data = ?    
64                  where oid = ?;                  where name = ?;
65  };  };
66    
67    system "fusermount -q -u $mount" || diag "nothing mounted at $mount, ok";
68    
69  my $mnt = Fuse::DBI->mount({  my $mnt = Fuse::DBI->mount({
70          filenames => $sql_filenames,          filenames => $sql_filenames,
71          read => $sql_read,          read => $sql_read,
72          update => $sql_update,          update => $sql_update,
73          dsn => 'DBI:Pg:dbname=webgui',          dsn => $dsn,
74          mount => '/mnt2',          mount => $mount,
75  });  });
76    
77  ok($mnt, "mount");  ok($mnt, "mount");
# Line 44  my $foo = <STDIN>; Line 81  my $foo = <STDIN>;
81    
82  ok($mnt->umount,"umount");  ok($mnt->umount,"umount");
83    
84    ok(unlink $test_db,"rm $test_db");
85    

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

  ViewVC Help
Powered by ViewVC 1.1.26