Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let the user set the environments to another path
By default, Dancer will load the environment configuration from path(setting('appdir'), 'environments') This change let the user to set the environments in another directory. This is particulary useful when your configuration is managed outside the application (like a repository managed by Ops). A new test file is added to test this feature, and a short documentation about `DANCER_CONFDIR` and `DANCER_ENVDIR` is added.
- Loading branch information
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More import => ['!pass']; | ||
|
||
plan tests => 5; | ||
|
||
use File::Spec; | ||
use Dancer ':syntax'; | ||
use lib File::Spec->catdir('t', 'lib'); | ||
use TestUtils; | ||
|
||
my $app_dir = File::Temp::tempdir(CLEANUP => 1, TMPDIR => 1); | ||
my $env_dir = File::Temp::tempdir(CLEANUP => 1, TMPDIR => 1); | ||
|
||
set appdir => $app_dir; | ||
set envdir => $env_dir; | ||
|
||
my $conffile = Dancer::Config->conffile; | ||
my $conf = ' | ||
port: 4500 | ||
startup_info: 0 | ||
charset: "UTF8" | ||
logger: file | ||
log: "debug" | ||
'; | ||
write_file($conffile => $conf); | ||
|
||
ok(Dancer::Config->load, 'Config load works without conffile'); | ||
|
||
is(setting('log'), 'debug', 'log setting looks good'); | ||
|
||
my $prod_env = ' | ||
log: "warning" | ||
startup_info: 0 | ||
foo_prod: 42 | ||
'; | ||
|
||
setting('environment' => 'prod'); | ||
write_file(Dancer::Config->environment_file, $prod_env); | ||
|
||
my $path = File::Spec->catfile($env_dir, 'prod.yml'); | ||
ok -f $path; | ||
|
||
ok(Dancer::Config->load, 'load prod environment'); | ||
is(setting('log'), 'warning', 'log setting looks good'); | ||
File::Temp::cleanup(); |