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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
# testing options while respecting external ENV variables
#
# KEEP_DB=1
# keep all databases created
# BASE_DIR=1
# use the specified base dir
# don't emit diag (we know where the databases are created)
# KEEP_DB=1 && BASE_DIR=0
# emit diag (so we can see where databases are created)
# KEEP_DB=0
# clean up all databases created
# don't emit diag (we don't need to know where the databases are created)
use Test::More; {
use strict;
use warnings;
BEGIN {
eval "use Test::Postgresql58"; if($@) {
plan skip_all => 'Test::Postgresql58 not installed';
}
}
use File::Path qw!rmtree!;
use FindBin qw($Bin);
use lib "$Bin/lib";
use TDBICOptions;
my $env_keep_db = $ENV{KEEP_DB};
my $env_base_dir = $ENV{BASE_DIR};
#TDBICOptions::check_base_dir();
require_ok 'Test::DBIx::Class';
TDBICOptions::notify();
my $dirs_created = {};
my $builder = Test::DBIx::Class->builder;
my $fh;
$builder->failure_output(\$fh);
ok my $config = {
schema_class => 'Test::DBIx::Class::Example::Schema',
traits => [qw!Testpostgresql!],
tdbic_debug => 0,
keep_db => $env_keep_db,
connect_opts => {
on_connect_do => 'SET client_min_messages=WARNING;',
},
}, 'Created Sample inline configuration';
#-------------------
note('tdbic_debug=1');
$config->{tdbic_debug} = 1;
$fh = '';
my $manager;
eval {
$manager = Test::DBIx::Class::SchemaManager->initialize_schema({
%$config,
builder => $builder,
});
};
if ($@ or !$manager) {
Test::More::diag("Can't initialize a schema with the given configuration");
Test::More::diag("Returned Error: ".$@) if $@;
Test::More::diag(
Test::More::explain("configuration: " => $config)
);
done_testing;
exit;
}
undef $manager;
cmp_ok $fh, '=~', '# Starting postgresql with:', 'diag emitted';
print ("$fh\n") if $env_keep_db;
my $dir = dir_created($fh);
print "# ERROR: could not identify dir from diag:\n$fh\n" unless $dir;
#-------------------
note('tdbic_debug=0');
$config->{tdbic_debug} = 0;
$fh = '';
$manager = Test::DBIx::Class::SchemaManager->initialize_schema({
%$config,
builder => $builder,
});
undef $manager;
if ($env_keep_db && !$env_base_dir){
ok $fh, 'diag emitted as KEEP_DB was true and BASE_DIR was not';
print ("$fh\n");
my $dir = dir_created($fh);
print "# ERROR: could not identify dir from diag:\n$fh\n" unless $dir;
} else{
ok !$fh, 'no diag emitted';
}
#-------------------
note('keep_db=1');
$config->{keep_db} = 1;
$fh = '';
$manager = Test::DBIx::Class::SchemaManager->initialize_schema({
%$config,
builder => $builder,
});
undef $manager;
if ($env_base_dir){
ok !$fh, 'no diag emitted as BASE_DIR was true';
} else {
cmp_ok ($fh, '=~', '# Starting postgresql with:', 'diag emitted') or diag $fh;
print ("$fh\n") if $env_keep_db;
}
$dir = dir_created($fh);
print "# ERROR: could not identify dir from diag:\n$fh\n" unless $dir;
TDBICOptions::print_dirs_created($dirs_created);
done_testing();
sub dir_created{
my $diag = $_[0];
my $regex = qr!\s\-D\s(/tmp/\w+)/data!;
return TDBICOptions::dir_created($dirs_created, $regex, $diag);
}
}
|