Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test::MockFile & DBD::SQLite #91

Open
atoomic opened this issue Jan 19, 2022 · 0 comments
Open

Test::MockFile & DBD::SQLite #91

atoomic opened this issue Jan 19, 2022 · 0 comments
Labels
Feature Request New feature or request

Comments

@atoomic
Copy link
Contributor

atoomic commented Jan 19, 2022

Would be nice to be able to use DBI with a mocked sqlite file.

The following sample is failing on ping and does not see the file as created.
Not sure how easy it would be to fix it.

note that it seems that we can write/read to it, probably because it fall back to in memory

#!perl

use Test::More;
use Test::MockFile;

use DBI;

my $f = q[/tmp/mydb.sqlite];

unlink $f;

# Comment me to run unmocked
my $mocked = Test::MockFile->file( $f );

my $dbh = DBI->connect("dbi:SQLite:dbname=$f","","", {
  AutoCommit => 1,
  RaiseError => 1,
});

ok $dbh->ping, 'ping';

ok $dbh->do( <<EOS ), 'create table';
CREATE TABLE groups (
   id INTEGER PRIMARY KEY,
   name TEXT NOT NULL
)
EOS


my $sth = $dbh->prepare("INSERT INTO groups VALUES (?, ?)");
ok $sth->execute(1 => q[group one] );

note explain [ $dbh->selectall_array("select * from groups") ];

ok -f $f, 'sqlite file created';

output

╰─> perl test.pl
not ok 1 - ping
#   Failed test 'ping'
#   at test.pl line 21.
ok 2 - create table
ok 3
# [
#   [
#     1,
#     'group one'
#   ]
# ]
not ok 4 - sqlite file created

note: consider running DBI_TRACE=2 perl test.pl

@toddr toddr added the Feature Request New feature or request label Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request
Development

No branches or pull requests

2 participants