Dancer2

 view release on metacpan or  search on metacpan

t/config.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Carp 'croak';

# use Dancer2::Core::Runner;
use Path::Tiny qw< path >;
use Dancer2::ConfigReader;

# undefine ENV vars used as defaults for app environment in these tests
local $ENV{DANCER_ENVIRONMENT};
local $ENV{PLACK_ENV};

# my $runner = Dancer2::Core::Runner->new();
my $location  = path( __FILE__ )->parent->child('config')->stringify;
my $location2 = path( __FILE__ )->parent->child('config2')->stringify;

{ 
    my $cfgr = Dancer2::ConfigReader->new(
        environment    => 'my_env',
        location       => $location,
        default_config => {
            content_type => 'text/html',
            charset      => 'UTF-8',
        },
    );
    is( $cfgr->config->{'application'}->{'some_feature'}, 'foo', 'Ok config' );
    is( $cfgr->config->{'charset'}, 'utf-8', 'Ok default config' );
}

{ 
    # note "bad YAML file: environments/failure.yml";
    like(
        exception {
            Dancer2::ConfigReader->new(
                environment    => 'failure',
                location       => $location,
                default_config => { },
            )->config;
        },
        qr{Unable to parse the configuration file}, 'Configuration file parsing failure',
    );
}

{
    my $cfgr = Dancer2::ConfigReader->new(
        environment    => 'any_env',
        location       => $location,
        default_config => { },
    );
    my $cfg = $cfgr->config;
    isnt( $cfg, undef, 'OK config read' );
}
{
    my $cfgr = Dancer2::ConfigReader->new(
        environment    => 'merging',
        location       => $location,
        default_config => { },
    );
    # note "config merging";
    # Check the 'application' top-level key; its the only key that
    # is currently a HoH in the test configurations
    is_deeply $cfgr->config->{application},



( run in 1.461 second using v1.01-cache-2.11-cpan-54e63673c56 )