| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Test::Fatal; |
| 5 |
use Carp 'croak'; |
| 6 |
|
| 7 |
use Path::Tiny qw< path >; |
| 8 |
use Dancer2::Core::Runner; |
| 9 |
|
| 10 |
# undefine ENV vars used as defaults for app environment in these tests |
| 11 |
local $ENV{DANCER_ENVIRONMENT}; |
| 12 |
local $ENV{PLACK_ENV}; |
| 13 |
|
| 14 |
my $runner = Dancer2::Core::Runner->new(); |
| 15 |
my $location = path( __FILE__ )->parent->child('config')->stringify; |
| 16 |
my $location2 = path( __FILE__ )->parent->child('config2')->stringify; |
| 17 |
|
| 18 |
{ |
| 19 |
package Dancer2::Test::TestRoleOne; |
| 20 |
use Moo; |
| 21 |
with 'Dancer2::Core::Role::HasEnvironment'; |
| 22 |
} |
| 23 |
|
| 24 |
{ |
| 25 |
undef $ENV{DANCER_ENVIRONMENT}; |
| 26 |
undef $ENV{PLACK_ENV}; |
| 27 |
my $test_one = Dancer2::Test::TestRoleOne->new(); |
| 28 |
is( $test_one->environment, 'development', 'Default env is OK' ); |
| 29 |
} |
| 30 |
{ |
| 31 |
$ENV{DANCER_ENVIRONMENT} = 'staging'; |
| 32 |
undef $ENV{PLACK_ENV}; |
| 33 |
my $test_one = Dancer2::Test::TestRoleOne->new(); |
| 34 |
is( $test_one->environment, q{staging}, 'Dancer env is OK when dancer env has value and plack env is not defined' ); |
| 35 |
} |
| 36 |
{ |
| 37 |
$ENV{DANCER_ENVIRONMENT} = 'staging'; |
| 38 |
$ENV{PLACK_ENV} = 'other_env'; |
| 39 |
my $test_one = Dancer2::Test::TestRoleOne->new(); |
| 40 |
is( $test_one->environment, q{staging}, 'Dancer env is OK when dancer and plack env vars are both used' ); |
| 41 |
} |
| 42 |
{ |
| 43 |
undef $ENV{DANCER_ENVIRONMENT}; |
| 44 |
$ENV{PLACK_ENV} = 'plack_env'; |
| 45 |
my $test_one = Dancer2::Test::TestRoleOne->new(); |
| 46 |
is( $test_one->environment, q{plack_env}, 'Dancer env is OK when dancer env var is not defined' ); |
| 47 |
} |
| 48 |
{ |
| 49 |
$ENV{DANCER_ENVIRONMENT} = ''; |
| 50 |
$ENV{PLACK_ENV} = 'plack_env'; |
| 51 |
my $test_one = Dancer2::Test::TestRoleOne->new(); |
| 52 |
is( $test_one->environment, q{plack_env}, 'Dancer env is OK when one env var is empty string' ); |
| 53 |
} |
| 54 |
{ |
| 55 |
$ENV{DANCER_ENVIRONMENT} = ''; |
| 56 |
$ENV{PLACK_ENV} = ''; |
| 57 |
my $test_one = Dancer2::Test::TestRoleOne->new(); |
| 58 |
is( $test_one->environment, q{development}, 'Dancer env is OK when both env vars are empty string' ); |
| 59 |
} |
| 60 |
|
| 61 |
done_testing; |