File: sqlite.t

package info (click to toggle)
libtest-roo-perl 1.004-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 376 kB
  • sloc: perl: 522; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 919 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use Test::Roo;
use DBI;
use Path::Tiny;

has tempdir => (
    is      => 'ro',
    clearer => 1,
    default => sub { Path::Tiny->tempdir },
);

has dbfile => (
    is      => 'lazy',
    default => sub { shift->tempdir->child('test.sqlite3') },
);

has dbh => ( is => 'lazy', );

sub _build_dbh {
    my $self = shift;
    DBI->connect(
        "dbi:SQLite:dbname=" . $self->dbfile, { RaiseError => 1 }
    );
}

before 'setup' => sub {
    my $self = shift;
    $self->dbh->do("CREATE TABLE f (f1, f2, f3)");
};

after 'teardown' => sub { shift->clear_tempdir };

test 'first' => sub {
    my $self = shift;
    my $dbh  = $self->dbh;
    my $sth  = $dbh->prepare("INSERT INTO f(f1,f2,f3) VALUES (?,?,?)");
    ok( $sth->execute( "one", "two", "three" ), "inserted data" );

    my $got = $dbh->selectrow_arrayref("SELECT * FROM f");
    is_deeply( $got, [qw/one two three/], "read data" );
};

run_me;
done_testing;