/
13-configuration.t
171 lines (127 loc) · 4.81 KB
/
13-configuration.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
use v6.c;
use Test;
use Bailador;
use Bailador::Test;
plan 8;
## Test default configuration
subtest {
plan 11;
my $app = Bailador::App.new;
isa-ok $app, Bailador::App;
my $config = $app.config;
isa-ok $config, Bailador::Configuration;
is $config.mode, 'production', 'Default mode is production';
is $config.host, '127.0.0.1', 'Default host is 127.0.0.1';
is $config.port, 3000, 'Default port is 3000';
is $config.config-file, 'settings.yaml', 'Default configuration filename is settings.yaml';
is $config.cookie-name, 'bailador', 'Default cookie name is bailador';
is $config.cookie-path, '/', 'Default cookie path is /';
is $config.cookie-expiration, 3600, 'Default cookie expiration is 3600';
is $config.hmac-key, 'changeme', 'Default hmac-key is changeme';
is $config.backend, 'Bailador::Sessions::Store::Memory', 'Default backend is Bailador::Sessions::Store::Memory';
}
my $file = "t/settings.yaml";
my $content = q:to/EOT/;
mode: 'development'
host: 'localhost'
port: 8080
cookie-name: 'Bailador-cookie'
cookie-expiration: 2800
EOT
END {
# remove the file after the tests
unlink $file;
}
spurt $file, $content;
# test 2
## Test configuration from a file
if $*DISTRO.is-win {
skip "Skipping failing Windows test...";
}
else {
subtest {
plan 10;
my $app = Bailador::App.new;
isa-ok $app, Bailador::App;
$app.load-config();
my $config = $app.config;
isa-ok $config, Bailador::Configuration;
is $config.mode, 'development', 'Mode from configuration file is development';
is $config.host, 'localhost', 'Host from configuration file is localhost';
is $config.port, 8080, 'Port from configuration file is 8080';
is $config.cookie-name, 'Bailador-cookie', 'Cookie name is now Bailador-cookie';
is $config.cookie-path, '/', 'Cookie path is still /';
is $config.cookie-expiration, 2800, 'Cookie expiration is now 2800';
is $config.hmac-key, 'changeme', 'Hmac-key is still changeme';
is $config.backend, 'Bailador::Sessions::Store::Memory', 'Backend is still Bailador::Sessions::Store::Memory';
}
}
## Test configuration ENV must override settings.yaml
subtest {
plan 5;
# Prepare ENV
temp %*ENV<BAILADOR> = 'port:9090';
my $app = Bailador::App.new;
isa-ok $app, Bailador::App;
$app.location( $*PROGRAM.parent.absolute );
$app.load-config();
my $config = $app.config;
isa-ok $config, Bailador::Configuration;
is $config.mode, 'development', 'Mode from configuration file is development';
is $config.host, 'localhost', 'Host from configuration file is localhost';
is $config.port, 9090, 'Port from configuration from ENV is 9090 - override settings.yaml';
}
## Change config dir relative to application location
subtest {
plan 2;
temp %*ENV<BAILADOR_CONFIGDIR> = 'config';
my $app = Bailador::App.new;
$app.location( $*PROGRAM.parent.absolute );
$app.load-config();
my $config = $app.config;
is $config.port, 9090, 'Port from alternate config directory is 9090';
is $config.host, 'www.example.com', 'Host from alternate config directory is www.example.com';
}
## Change config dir absolute
subtest {
plan 2;
temp %*ENV<BAILADOR_CONFIGDIR> = $*PROGRAM.parent.child("config").absolute;
my $app = Bailador::App.new;
$app.location( $*PROGRAM.parent.absolute);
$app.load-config();
my $config = $app.config;
is $config.port, 9090, 'Port from absolute alternate config directory is 9090';
is $config.host, 'www.example.com', 'Host from absolute alternate config directory is www.example.com';
}
## Specify config file relative to application location
subtest {
plan 2;
temp %*ENV<BAILADOR_CONFIGFILE> = 'config/config.yaml';
my $app = Bailador::App.new;
$app.location( $*PROGRAM.parent.absolute );
$app.load-config();
my $config = $app.config;
is $config.host, 'localhost', 'Host from relative config file is localhost';
is $config.name, 'Fred', 'Name from relative config file is Fred';
}
## Specify absolute config file
subtest {
plan 2;
temp %*ENV<BAILADOR_CONFIGFILE> = $*PROGRAM.parent.child("config").child('config.yaml').absolute;
my $app = Bailador::App.new;
$app.location( $*PROGRAM.parent.absolute );
$app.load-config();
my $config = $app.config;
is $config.host, 'localhost', 'Host from absolute config file is localhost';
is $config.name, 'Fred', 'Name from absolute config file is Fred';
}
## Settings in -local override
subtest {
plan 1;
temp %*ENV<BAILADOR_CONFIGFILE> = 'config/config.yaml';
my $app = Bailador::App.new;
$app.location( $*PROGRAM.parent.absolute );
$app.load-config();
my $config = $app.config;
is $config.port, 9999, 'Port from alternate config directory is 9999';
}