/[fuse_dbi]/trunk/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

Annotation of /trunk/t/02sqlite.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (hide annotations)
Sun Sep 5 16:04:35 2004 UTC (18 years, 3 months ago) by dpavlin
Original Path: trunk/t/02database.t
File MIME type: application/x-troff
File size: 1576 byte(s)
use DBD::SQLite to run tests (if installed)

1 dpavlin 11 #!/usr/bin/perl -w
2    
3     use strict;
4     use warnings;
5    
6 dpavlin 15 use Test::More;
7 dpavlin 11 use blib;
8    
9 dpavlin 15 eval "use DBD::SQLite";
10     plan skip_all => "DBD::SQLite required for testing" if $@;
11     plan tests => 14;
12    
13     use_ok('DBI');
14 dpavlin 11 use_ok('Fuse::DBI');
15    
16 dpavlin 15 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 dpavlin 11 select
48 dpavlin 15 name as id,
49     name as filename,
50     length(data) as size,
51     0 as writable
52     from files
53 dpavlin 11 };
54    
55 dpavlin 15 my $sql_read = qq{
56     select data
57     from files
58     where name = ?;
59 dpavlin 11 };
60    
61 dpavlin 15 my $sql_update = qq{
62     update files
63     set data = ?
64     where name = ?;
65 dpavlin 11 };
66    
67 dpavlin 15 system "fusermount -q -u $mount" || diag "nothing mounted at $mount, ok";
68    
69 dpavlin 11 my $mnt = Fuse::DBI->mount({
70     filenames => $sql_filenames,
71     read => $sql_read,
72     update => $sql_update,
73 dpavlin 15 dsn => $dsn,
74     mount => $mount,
75 dpavlin 11 });
76    
77     ok($mnt, "mount");
78    
79 dpavlin 12 diag "press enter to continue";
80     my $foo = <STDIN>;
81 dpavlin 11
82     ok($mnt->umount,"umount");
83 dpavlin 12
84 dpavlin 15 ok(unlink $test_db,"rm $test_db");
85    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26