3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
22 A database
class that creates the DBIC schema in a test database, and then
23 cleans up after itself.
25 Convenience methods prevent having to delve into DBIC guts for common activities
30 config_file =>
'filename_if_not_default.conf',
31 reuse => 1 # This prevents the test
DB cleanup, so you can
debug database content
36 package Xref::Test::TestDB;
41 use namespace::autoclean;
55 # On top of default config validator, inject a randomised test DB name
56 around
'_init_config' => sub {
57 my ($sub, $self, @args) = @_;
59 my $proto_config = $self->$sub();
61 if (! exists $proto_config->{db}) {
62 $proto_config->{db} = sprintf
'%s_xref_test_%s',$ENV{USER},int(rand(100000));
63 $proto_config->{create} = 1;
65 # return $proto_config;
66 $self->config($proto_config);
73 Description: It
's a destructor. It cleans up databases left behind by the test
74 Behaviour is overridden with $self->reuse(1)
79 if ($self->reuse == 0 && defined $self->config) {
80 if ( $self->config->{driver} eq 'SQLite
') {
81 unlink $self->config->{file};
82 } elsif ($self->config->{driver} eq 'mysql
') {
83 $self->schema->storage->dbh->do('drop database
'.$self->config->{db});
89 __PACKAGE__->meta->make_immutable;