/[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

Contents of /trunk/t/02sqlite.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (show annotations)
Sat Oct 2 16:30:16 2004 UTC (18 years, 1 month ago) by dpavlin
File MIME type: application/x-troff
File size: 1638 byte(s)
fixed fork option and tests

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26