| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Test::Fatal; |
| 5 |
use Carp 'croak'; |
| 6 |
|
| 7 |
# use Dancer2::Core::Runner; |
| 8 |
use Path::Tiny qw< path >; |
| 9 |
use Dancer2::ConfigReader; |
| 10 |
|
| 11 |
# undefine ENV vars used as defaults for app environment in these tests |
| 12 |
local $ENV{DANCER_ENVIRONMENT}; |
| 13 |
local $ENV{PLACK_ENV}; |
| 14 |
|
| 15 |
# my $runner = Dancer2::Core::Runner->new(); |
| 16 |
my $location = path( __FILE__ )->parent->child('config')->stringify; |
| 17 |
my $location2 = path( __FILE__ )->parent->child('config2')->stringify; |
| 18 |
|
| 19 |
{ |
| 20 |
my $cfgr = Dancer2::ConfigReader->new( |
| 21 |
environment => 'my_env', |
| 22 |
location => $location, |
| 23 |
default_config => { |
| 24 |
content_type => 'text/html', |
| 25 |
charset => 'UTF-8', |
| 26 |
}, |
| 27 |
); |
| 28 |
is( $cfgr->config->{'application'}->{'some_feature'}, 'foo', 'Ok config' ); |
| 29 |
is( $cfgr->config->{'charset'}, 'utf-8', 'Ok default config' ); |
| 30 |
} |
| 31 |
|
| 32 |
{ |
| 33 |
# note "bad YAML file: environments/failure.yml"; |
| 34 |
like( |
| 35 |
exception { |
| 36 |
Dancer2::ConfigReader->new( |
| 37 |
environment => 'failure', |
| 38 |
location => $location, |
| 39 |
default_config => { }, |
| 40 |
)->config; |
| 41 |
}, |
| 42 |
qr{Unable to parse the configuration file}, 'Configuration file parsing failure', |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
{ |
| 47 |
my $cfgr = Dancer2::ConfigReader->new( |
| 48 |
environment => 'any_env', |
| 49 |
location => $location, |
| 50 |
default_config => { }, |
| 51 |
); |
| 52 |
my $cfg = $cfgr->config; |
| 53 |
isnt( $cfg, undef, 'OK config read' ); |
| 54 |
} |
| 55 |
{ |
| 56 |
my $cfgr = Dancer2::ConfigReader->new( |
| 57 |
environment => 'merging', |
| 58 |
location => $location, |
| 59 |
default_config => { }, |
| 60 |
); |
| 61 |
# note "config merging"; |
| 62 |
# Check the 'application' top-level key; its the only key that |
| 63 |
# is currently a HoH in the test configurations |
| 64 |
is_deeply $cfgr->config->{application}, |
| 65 |
{ |
| 66 |
some_feature => 'bar', |
| 67 |
another_setting => 'baz', |
| 68 |
}, |
| 69 |
"full merging of configuration hashes"; |
| 70 |
} |
| 71 |
{ |
| 72 |
my $cfgr = Dancer2::ConfigReader->new( |
| 73 |
environment => 'lconfig', |
| 74 |
location => $location2, |
| 75 |
default_config => { }, |
| 76 |
); |
| 77 |
is_deeply $cfgr->config->{application}, |
| 78 |
{ feature_1 => 'foo', |
| 79 |
feature_2 => 'alpha', |
| 80 |
feature_3 => 'replacement', |
| 81 |
feature_4 => 'blat', |
| 82 |
feature_5 => 'beta', |
| 83 |
feature_6 => 'bar', |
| 84 |
feature_7 => 'baz', |
| 85 |
feature_8 => 'goober', |
| 86 |
}, |
| 87 |
"full merging of local configuration hashes"; |
| 88 |
} |
| 89 |
|
| 90 |
done_testing; |