File Coverage

blib/lib/Tapper/Schema/TestTools.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 2 2 100.0
total 49 49 100.0


line stmt bran cond sub pod time code
1             package Tapper::Schema::TestTools;
2             our $AUTHORITY = 'cpan:TAPPER';
3             $Tapper::Schema::TestTools::VERSION = '5.0.9';
4             # inspired by Test::Fixture::DBIC::Schema
5              
6 7     7   165984 use strict;
  7         10  
  7         165  
7 7     7   19 use warnings;
  7         11  
  7         161  
8              
9             BEGIN {
10 7     7   1973 use Class::C3;
  7         9885  
  7         34  
11 7     7   1947 use MRO::Compat;
  7         5804  
  7         167  
12 7     7   91 $DBD::SQLite::sqlite_version; # fix "used only once" warning
13             }
14              
15 7     7   1425 use Tapper::Config;
  7         98873  
  7         174  
16 7     7   2340 use Tapper::Schema::TestrunDB;
  7         25  
  7         1936  
17              
18             my $testrundb_schema;
19              
20              
21             sub setup_db
22             {
23             # explicitely prefix into {test} subhash of the config file,
24             # to avoid painful mistakes with deploy
25              
26 7     7 1 55 my ($db, $cfgbase) = @_;
27              
28 7         15 my $cfg = $cfgbase->{$db};
29 7         27 my $dsn = $cfg->{dsn};
30 7         63 my ($tmpfname) = $dsn =~ m,dbi:SQLite:dbname=([\w./]+),i;
31 7         2211 unlink $tmpfname;
32 7         80 my $schema = Tapper::Schema::TestrunDB->connect($dsn, $cfg->{username}, $cfg->{password}, { ignore_version => 1 });
33 7         450942 $schema->deploy;
34             # $schema->upgrade if $schema->schema_version > $schema->get_db_version;
35 7         18461521 return $schema;
36             }
37              
38              
39             sub setup_testrundb {
40 7     7 1 54 $testrundb_schema = setup_db("TestrunDB", Tapper::Config->subconfig->{test}{database});
41             }
42              
43              
44             sub import {
45 7     7   130 my $pkg = caller(0);
46 7     7   47 no strict 'refs'; ## no critic.
  7         9  
  7         797  
47 7     62   55 *{"$pkg\::testrundb_schema"} = sub () { $testrundb_schema };
  7         5636  
  62         307115  
48             }
49              
50             setup_testrundb;
51              
52             1;
53              
54             __END__
55              
56             =pod
57              
58             =encoding UTF-8
59              
60             =head1 NAME
61              
62             Tapper::Schema::TestTools
63              
64             =head2 setup_db
65              
66             Setup and connect a test database using SQLite.
67              
68             =head2 setup_testrundb
69              
70             Setup and connect a test TestrunDB using SQLite.
71              
72             =head1 AUTHORS
73              
74             =over 4
75              
76             =item *
77              
78             AMD OSRC Tapper Team <tapper@amd64.org>
79              
80             =item *
81              
82             Tapper Team <tapper-ops@amazon.com>
83              
84             =back
85              
86             =head1 COPYRIGHT AND LICENSE
87              
88             This software is Copyright (c) 2017 by Advanced Micro Devices, Inc..
89              
90             This is free software, licensed under:
91              
92             The (two-clause) FreeBSD License
93              
94             =cut