Commit | Line | Data |
f84ac410 |
1 | #!/usr/bin/env perl |
2 | use warnings; |
3 | use strict; |
4 | use Test::More; |
5 | use Catalyst::IOC::Container; |
6 | use FindBin '$Bin'; |
7 | use lib "$Bin/../lib"; |
8 | use TestAppSetupHome; |
9 | use vars '%ENV'; |
10 | |
11 | my $lib = "$Bin/../lib"; |
12 | my @homes_and_roots = ( |
13 | [ |
14 | "$lib/TestAppSetupHome", |
15 | "$lib/TestAppSetupHome/root", |
16 | ], |
17 | [ |
18 | "$lib/TestAppSetupHomeENV", |
19 | "$lib/TestAppSetupHomeENV/root", |
20 | ], |
21 | [ |
22 | "$lib/TestAppSetupHomeFLAG", |
23 | "$lib/TestAppSetupHomeFLAG/root", |
24 | ], |
25 | ); |
26 | |
27 | for my $home_and_root (@homes_and_roots) { |
28 | for (@$home_and_root) { |
29 | mkdir $_; |
30 | } |
31 | } |
32 | |
33 | { |
34 | my $home_flag; |
35 | delete $ENV{CATALYST_HOME} if exists $ENV{CATALYST_HOME}; |
36 | |
37 | my $c = Catalyst::IOC::Container->new(name => 'TestAppSetupHome'); |
38 | ok(my $home = $c->resolve(service => 'home', parameters => { home_flag => $home_flag }), 'home service returns ok'); |
39 | is($home, $homes_and_roots[0][0], 'value is expected'); |
40 | ok(my $root = $c->resolve(service => 'root_dir'), 'root service returns ok'); |
41 | is($root, $homes_and_roots[0][1], 'value is expected'); |
42 | } |
43 | |
44 | { |
45 | my $home_flag; |
46 | $ENV{CATALYST_HOME} = $homes_and_roots[1][0]; |
47 | |
48 | my $c = Catalyst::IOC::Container->new(name => 'TestAppSetupHome'); |
49 | ok(my $home = $c->resolve(service => 'home', parameters => { home_flag => $home_flag }), 'home service returns ok'); |
50 | is($home, $homes_and_roots[1][0], 'value is expected'); |
51 | ok(my $root = $c->resolve(service => 'root_dir'), 'root service returns ok'); |
52 | is($root, $homes_and_roots[1][1], 'value is expected'); |
53 | } |
54 | |
55 | { |
56 | my $home_flag = $homes_and_roots[2][0]; |
57 | delete $ENV{CATALYST_HOME} if exists $ENV{CATALYST_HOME}; |
58 | |
59 | my $c = Catalyst::IOC::Container->new(name => 'TestAppSetupHome'); |
60 | ok(my $home = $c->resolve(service => 'home', parameters => { home_flag => $home_flag }), 'home service returns ok'); |
61 | is($home, $homes_and_roots[2][0], 'value is expected'); |
62 | ok(my $root = $c->resolve(service => 'root_dir'), 'root service returns ok'); |
63 | is($root, $homes_and_roots[2][1], 'value is expected'); |
64 | } |
65 | |
66 | { |
67 | my $home_flag = $homes_and_roots[2][0]; |
68 | $ENV{CATALYST_HOME} = $homes_and_roots[1][0]; |
69 | |
70 | my $c = Catalyst::IOC::Container->new(name => 'TestAppSetupHome'); |
71 | ok(my $home = $c->resolve(service => 'home', parameters => { home_flag => $home_flag }), 'home service returns ok'); |
48e17d26 |
72 | is($home, $homes_and_roots[1][0], 'value is expected'); |
f84ac410 |
73 | ok(my $root = $c->resolve(service => 'root_dir'), 'root service returns ok'); |
48e17d26 |
74 | is($root, $homes_and_roots[1][1], 'value is expected'); |
f84ac410 |
75 | } |
76 | |
77 | for my $home_and_root (@homes_and_roots) { |
78 | for (@$home_and_root) { |
79 | rmdir $_; |
80 | } |
81 | } |
82 | |
83 | done_testing; |