This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
/
test_config.rb
264 lines (237 loc) · 8.33 KB
/
test_config.rb
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
require 'test/unit'
require 'chef'
require File.join(File.dirname(__FILE__), '../libraries', 'easybib.rb')
require File.join(File.dirname(__FILE__), '../libraries', 'config.rb')
# rubocop:disable ClassLength
class TestEasyBibConfig < Test::Unit::TestCase
include EasyBib
def test_config_no_doublequote
fake_node = Chef::Node.new
fake_node.set['fakeapp']['env']['database']['something'] = 'foo"bar'
assert_raises RuntimeError do
::EasyBib::Config.get_env('nginx', 'fakeapp', fake_node)
end
end
def test_get_vagrant_appdir
fake_node = Chef::Node.new
fake_node.set['vagrant']['applications']['app']['app_root_location'] = '/app/root/dir/'
assert_equal(
"/app/root/dir/",
::EasyBib::Config.get_vagrant_appdir(fake_node, "app")
)
fake_node = Chef::Node.new
fake_node.set['vagrant']['applications']['app']['doc_root_location'] = '/doc/root/dir/'
assert_equal(
"/doc/root/",
::EasyBib::Config.get_vagrant_appdir(fake_node, "app")
)
fake_node = Chef::Node.new
assert_equal(
"/vagrant_data/",
::EasyBib::Config.get_vagrant_appdir(fake_node, "app")
)
end
def test_get_domains
fake_node = Chef::Node.new
fake_node.set['vagrant']['applications']['app']['domain_name'] = 'whatever.local'
assert_equal(
"whatever.local",
::EasyBib::Config.get_domains(fake_node, "app")
)
fake_node = Chef::Node.new
fake_node.set['vagrant']['applications']['app']['domain_name'] = ['whatever.local', 'thing.local']
assert_equal(
"whatever.local thing.local",
::EasyBib::Config.get_domains(fake_node, "app")
)
fake_node = Chef::Node.new
fake_node.set['deploy']['app']['domains'] = ['whatever.local', 'thing.local']
assert_equal(
"whatever.local thing.local",
::EasyBib::Config.get_domains(fake_node, "app")
)
fake_node = Chef::Node.new
fake_node.set['foo']['domain']['app'] = 'bla.local'
assert_equal(
'bla.local',
::EasyBib::Config.get_domains(fake_node, 'app', 'foo')
)
fake_node = Chef::Node.new
fake_node.set['getcourse']['domain']['consumer'] = 'bla.local'
assert_equal(
'bla.local *.bla.local',
::EasyBib::Config.get_domains(fake_node, 'consumer')
)
end
def test_ini_config
fake_node = Chef::Node.new
fake_node.set['fakeapp']['env']['database'] = {
'something' => 'foobar',
'whatever' => 'bar'
}
assert_equal(
::EasyBib::Config.get_env('ini', 'fakeapp', fake_node),
"DATABASE_SOMETHING = \"foobar\"\nDATABASE_WHATEVER = \"bar\"\n"
)
end
def test_config_to_ini
assert_equal(
"[deployed_application]
appname = \"some_app\"
domains = \"foo.tld bar.tld\"
deploy_dir = \"/tmp/bla/\"
app_dir = \"/tmp/bla/current/\"
doc_root_dir = \"/tmp/bla/current/www/\"
[deployed_stack]
stackname = \"opsworks-stack\"
environment = \"playground\"
[settings]
BLA_SOMEKEY = \"somevalue\"
BLA_SOMEGROUP_SOMEOTHERKEY = \"someothervalue\"\n",
::EasyBib::Config.get_configcontent('ini', 'some_app', get_fakenode_config)
)
end
def test_config_with_rds_to_ini
# IMPORTANT: Do not use port as string, since we want to check if no
# Fixnum to string error happens
fake_node = get_fakenode_config
fake_node.set['deploy']['some_app']['database'] = {
'host' => 'some.db.tld',
'user' => 'dbuser',
'port' => 1234
}
assert_equal(
"[deployed_application]
appname = \"some_app\"
domains = \"foo.tld bar.tld\"
deploy_dir = \"/tmp/bla/\"
app_dir = \"/tmp/bla/current/\"
doc_root_dir = \"/tmp/bla/current/www/\"
[deployed_stack]
stackname = \"opsworks-stack\"
environment = \"playground\"
[settings]
BLA_SOMEKEY = \"somevalue\"
BLA_SOMEGROUP_SOMEOTHERKEY = \"someothervalue\"
DB_HOST = \"some.db.tld\"
DB_USER = \"dbuser\"
DB_PORT = \"1234\"\n",
::EasyBib::Config.get_configcontent('ini', 'some_app', fake_node)
)
end
def test_config_to_shell
assert_equal("export DEPLOYED_APPLICATION_APPNAME=\"some_app\"
export DEPLOYED_APPLICATION_DOMAINS=\"foo.tld bar.tld\"
export DEPLOYED_APPLICATION_DEPLOY_DIR=\"/tmp/bla/\"
export DEPLOYED_APPLICATION_APP_DIR=\"/tmp/bla/current/\"
export DEPLOYED_APPLICATION_DOC_ROOT_DIR=\"/tmp/bla/current/www/\"
export DEPLOYED_STACK_STACKNAME=\"opsworks-stack\"
export DEPLOYED_STACK_ENVIRONMENT=\"playground\"
export BLA_SOMEKEY=\"somevalue\"
export BLA_SOMEGROUP_SOMEOTHERKEY=\"someothervalue\"\n",
::EasyBib::Config.get_configcontent('shell', 'some_app', get_fakenode_config)
)
end
def test_config_to_nginx
assert_equal("fastcgi_param DEPLOYED_APPLICATION_APPNAME \"some_app\";
fastcgi_param DEPLOYED_APPLICATION_DOMAINS \"foo.tld bar.tld\";
fastcgi_param DEPLOYED_APPLICATION_DEPLOY_DIR \"/tmp/bla/\";
fastcgi_param DEPLOYED_APPLICATION_APP_DIR \"/tmp/bla/current/\";
fastcgi_param DEPLOYED_APPLICATION_DOC_ROOT_DIR \"/tmp/bla/current/www/\";
fastcgi_param DEPLOYED_STACK_STACKNAME \"opsworks-stack\";
fastcgi_param DEPLOYED_STACK_ENVIRONMENT \"playground\";
fastcgi_param BLA_SOMEKEY \"somevalue\";
fastcgi_param BLA_SOMEGROUP_SOMEOTHERKEY \"someothervalue\";\n",
::EasyBib::Config.get_configcontent('nginx', 'some_app', get_fakenode_config)
)
end
def test_config_to_nginx_empty_settings
fake_node = Chef::Node.new
fake_node.set['deploy'] = {
'some_app' => {
'application' => 'some_app',
'domains' => ['foo.tld', 'bar.tld'],
'deploy_to' => '/tmp/bla',
'document_root' => 'www'
}
}
fake_node.set['opsworks'] = { 'stack' => { 'name' => 'opsworks-stack' } }
fake_node.set['easybib_deploy'] = { 'envtype' => 'playground' }
assert_equal("fastcgi_param DEPLOYED_APPLICATION_APPNAME \"some_app\";
fastcgi_param DEPLOYED_APPLICATION_DOMAINS \"foo.tld bar.tld\";
fastcgi_param DEPLOYED_APPLICATION_DEPLOY_DIR \"/tmp/bla/\";
fastcgi_param DEPLOYED_APPLICATION_APP_DIR \"/tmp/bla/current/\";
fastcgi_param DEPLOYED_APPLICATION_DOC_ROOT_DIR \"/tmp/bla/current/www/\";
fastcgi_param DEPLOYED_STACK_STACKNAME \"opsworks-stack\";
fastcgi_param DEPLOYED_STACK_ENVIRONMENT \"playground\";\n",
::EasyBib::Config.get_configcontent('nginx', 'some_app', fake_node)
)
end
def test_config_vagrantenv
fake_node = Chef::Node.new
fake_node.set['deploy'] = {
'some_app' => {
'application' => 'some_app',
'domains' => ['foo.tld', 'bar.tld']
}
}
fake_node.set['vagrant'] = { 'applications' => { 'some_app' => { 'app_root_location' => '/some_path', 'doc_root_location' => '/some_path/foo' } } }
fake_node.set['easybib_deploy'] = { 'envtype' => 'playground' }
assert_equal("fastcgi_param DEPLOYED_APPLICATION_APPNAME \"some_app\";
fastcgi_param DEPLOYED_APPLICATION_DOMAINS \"foo.tld bar.tld\";
fastcgi_param DEPLOYED_APPLICATION_APP_DIR \"/some_path/\";
fastcgi_param DEPLOYED_APPLICATION_DEPLOY_DIR \"/some_path/\";
fastcgi_param DEPLOYED_APPLICATION_DOC_ROOT_DIR \"/some_path/foo/\";
fastcgi_param DEPLOYED_STACK_STACKNAME \"vagrant\";
fastcgi_param DEPLOYED_STACK_ENVIRONMENT \"playground\";\n",
::EasyBib::Config.get_configcontent('nginx', 'some_app', fake_node)
)
end
def test_config_to_php
assert_equal("<?php
return [
'deployed_application' => [
'appname'=>\"some_app\",
'domains'=>\"foo.tld bar.tld\",
'deploy_dir'=>\"/tmp/bla/\",
'app_dir'=>\"/tmp/bla/current/\",
'doc_root_dir'=>\"/tmp/bla/current/www/\",
],
'deployed_stack' => [
'stackname'=>\"opsworks-stack\",
'environment'=>\"playground\",
],
'settings' => [
'BLA_SOMEKEY'=>\"somevalue\",
'BLA_SOMEGROUP_SOMEOTHERKEY'=>\"someothervalue\",
],
];",
::EasyBib::Config.get_configcontent('php', 'some_app', get_fakenode_config)
)
end
protected
def get_fakenode_config
fake_node = Chef::Node.new
fake_node.set['deploy'] = {
'some_app' => {
'application' => 'some_app',
'domains' => ['foo.tld', 'bar.tld'],
'deploy_to' => '/tmp/bla',
'document_root' => 'www'
}
}
fake_node.set['some_app'] = {
'env' => {
'bla' => {
'somekey' => 'somevalue',
'somegroup' => {
'someotherkey' => 'someothervalue'
}
}
}
}
fake_node.set['opsworks'] = { 'stack' => { 'name' => 'opsworks-stack' } }
fake_node.set['easybib_deploy'] = { 'envtype' => 'playground' }
fake_node
end
end