This repository was archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo_cf_api_yml_spec.rb
More file actions
248 lines (212 loc) · 9.23 KB
/
Copy pathgo_cf_api_yml_spec.rb
File metadata and controls
248 lines (212 loc) · 9.23 KB
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
# frozen_string_literal: true
require_relative 'spec_helper'
describe 'go-cf-api' do
let(:job_name) { 'go-cf-api' }
let(:release) { Bosh::Template::Test::ReleaseDir.new(File.join(File.dirname(__FILE__), '..')) }
let(:job) { release.job(job_name) }
let(:template) { job.template('config/go-cf-api.yml') }
let(:ccdb_config) do
{
'db_scheme' => 'postgres',
'address' => 'db.example.com',
'port' => 1234,
'databases' => [{
'name' => 'ccdb', 'tag' => 'cc'
}],
'roles' => [{
'name' => 'admin_user', 'password' => 'admin_password', 'tag' => 'admin'
}]
}
end
let(:ccdb_link) do
Bosh::Template::Test::Link.new(
name: 'cloud_controller_db',
properties: {
'ccdb' => ccdb_config
}
)
end
let(:ccinternal_link) do
Bosh::Template::Test::Link.new(
name: 'cloud_controller_internal',
properties: {
'system_domain' => 'example.com',
'cc' => {
'external_host' => 'api',
'external_protocol' => 'https'
}
}
)
end
let(:database_link) do
Bosh::Template::Test::Link.new(
name: 'database',
instances: [{
'address' => '10.0.16.5'
}]
)
end
describe 'database configuration' do
subject(:rendering) { YAML.safe_load(template.render({}, consumes: [ccdb_link, ccinternal_link]))['db'] }
context 'db_scheme is postgres' do
it { is_expected.to include('connection_string' => 'host=db.example.com port=1234 user=admin_user dbname=ccdb password=admin_password sslmode=disable') }
end
context 'db_scheme is mysql' do
let(:ccdb_config) { super().merge({ 'db_scheme' => 'mysql' }) }
it { is_expected.to include('connection_string' => 'admin_user:admin_password@tcp(db.example.com:1234)/ccdb?tls=false&parseTime=true') }
end
context 'missing port property' do
let(:ccdb_config) { super().reject { |k, _| k == 'port' } }
it 'raises an error' do
expect { rendering }.to raise_error(KeyError, 'key not found: "port"')
end
end
end
describe 'database singleton VM configuration' do
subject(:rendering) { YAML.safe_load(template.render({}, consumes: [database_link, ccdb_link, ccinternal_link]))['db'] }
context 'db_scheme is postgres' do
let(:ccdb_config) { super().reject { |k, _| k == 'address' } }
it { is_expected.to include('connection_string' => 'host=10.0.16.5 port=1234 user=admin_user dbname=ccdb password=admin_password sslmode=disable') }
end
context 'db_scheme is mysql' do
let(:ccdb_config) { super().merge({ 'db_scheme' => 'mysql' }).reject { |k, _| k == 'address' } }
it { is_expected.to include('connection_string' => 'admin_user:admin_password@tcp(10.0.16.5:1234)/ccdb?tls=false&parseTime=true') }
end
end
describe 'uaa configuration' do
let(:uaa_config) do
{
'ca_cert' => <<~EOCERT
--- BEGIN CERT ---
cert contents
--- END CERT ---
EOCERT
}
end
subject(:rendering) { YAML.safe_load(template.render({ 'uaa' => uaa_config }, consumes: [ccdb_link, ccinternal_link]))['uaa'] }
context 'defaults are used' do
it { is_expected.to include('url' => 'https://uaa.service.cf.internal:8443') }
end
context 'url and port are provided' do
let(:uaa_config) do
super().merge({ 'internal_url' => 'custom.uaa.hostname', 'tls_port' => 8888 })
end
it { is_expected.to include('url' => 'https://custom.uaa.hostname:8888') }
end
context 'ca_cert is provided' do
it { is_expected.to include('client' => { 'tls_config' => { 'ca_file' => '/var/vcap/jobs/go-cf-api/tls/uaa/ca.crt' } }) }
end
end
describe 'cc info configuration' do
let(:cc_config) { {} }
subject(:rendering) { YAML.safe_load(template.render(cc_config, consumes: [ccdb_link, ccinternal_link]))['info'] }
context 'defaults are used' do
it { is_expected.to include('name' => '') }
it { is_expected.to include('build' => '') }
it { is_expected.to include('support_address' => '') }
it { is_expected.to include('version' => 0) }
it { is_expected.to include('description' => '') }
end
context 'info is provided' do
let(:cc_config) do
super().merge({
'name' => 'test',
'build' => 'custom',
'support_address' => 'help@example.com',
'version' => 1,
'description' => 'test'
})
end
it { is_expected.to include('name' => 'test') }
it { is_expected.to include('build' => 'custom') }
it { is_expected.to include('support_address' => 'help@example.com') }
it { is_expected.to include('version' => 1) }
it { is_expected.to include('description' => 'test') }
end
end
describe 'cc urls configuration' do
subject(:rendering) { YAML.safe_load(template.render(cc_config, consumes: [ccdb_link, ccinternal_link]))['urls'] }
context 'uses defaults based on system_domain from link' do
let(:cc_config) { {} }
it { is_expected.to include('log_cache' => 'https://log-cache.example.com') }
it { is_expected.to include('log_stream' => 'https://log-stream.example.com') }
it { is_expected.to include('doppler' => 'wss://doppler.example.com:443') }
it { is_expected.to include('login' => 'https://login.example.com') }
it { is_expected.to include('uaa' => 'https://uaa.example.com') }
end
context 'doppler config is provided' do
let(:cc_config) { { 'doppler' => { 'use_ssl' => false, 'port' => 4443 } } }
it { is_expected.to include('doppler' => 'ws://doppler.example.com:4443') }
end
context 'login is disabled' do
let(:cc_config) { { 'login' => { 'enabled' => false } } }
it { is_expected.to include('login' => 'https://uaa.example.com') }
end
context 'login protocol is provided' do
let(:cc_config) { { 'login' => { 'protocol' => 'http' } } }
it { is_expected.to include('login' => 'http://login.example.com') }
end
context 'login url is provided' do
let(:cc_config) { { 'login' => { 'url' => 'https://custom.login.url' } } }
it { is_expected.to include('login' => 'https://custom.login.url') }
end
context 'uaa url is provided' do
let(:cc_config) { { 'login' => { 'enabled' => false }, 'uaa' => { 'url' => 'https://custom.uaa.url' } } }
it { is_expected.to include('login' => 'https://custom.uaa.url') }
it { is_expected.to include('uaa' => 'https://custom.uaa.url') }
end
end
describe 'cc app_ssh configuration' do
subject(:rendering) { YAML.safe_load(template.render(cc_config, consumes: [ccdb_link, ccinternal_link]))['app_ssh'] }
context 'uses defaults based on system_domain from link' do
let(:cc_config) { {} }
it { is_expected.to include('endpoint' => 'ssh.example.com:2222') }
it { is_expected.to include('oauth_client' => 'ssh-proxy') }
it { is_expected.to include('host_key_fingerprint' => nil) }
end
context 'port is provided' do
let(:cc_config) { { 'app_ssh' => { 'port' => 22 } } }
it { is_expected.to include('endpoint' => 'ssh.example.com:22') }
end
context 'oauth_client_id is provided' do
let(:cc_config) { { 'app_ssh' => { 'oauth_client_id' => 'custom-client-id' } } }
it { is_expected.to include('oauth_client' => 'custom-client-id') }
end
context 'host_key_fingerprint is provided' do
let(:cc_config) { { 'app_ssh' => { 'host_key_fingerprint' => 'b8:80:2c:8c:d7:25:ad:2a:b4:8c:02:34:52:06:f7:ba:1f:0d:02:de' } } }
it { is_expected.to include('host_key_fingerprint' => 'b8:80:2c:8c:d7:25:ad:2a:b4:8c:02:34:52:06:f7:ba:1f:0d:02:de') }
end
end
describe 'cc configuration' do
subject(:rendering) { YAML.safe_load(template.render({}, consumes: [ccdb_link, ccinternal_link])) }
context 'link provides properties' do
it { is_expected.to include('external_domain' => 'api.example.com') }
it { is_expected.to include('external_protocol' => 'https') }
end
end
describe 'cc db configuration' do
let(:cc_config) { {} }
subject(:rendering) { YAML.safe_load(template.render(cc_config, consumes: [ccdb_link, ccinternal_link]))['db'] }
context 'defaults are used' do
it { is_expected.to include('max_connections' => 100) }
it { is_expected.to include('min_connections' => 20) }
end
context 'db config is provided' do
let(:cc_config) { super().merge({ 'db' => {'max_connections' => 50,'min_connections' => 10 }}) }
it { is_expected.to include('min_connections' => 10) }
it { is_expected.to include('max_connections' => 50) }
end
context 'min_connections is smaller than 1' do
let(:cc_config) { super().merge({ 'db' => {'min_connections' => 0 }}) }
it 'raises an error' do
expect { rendering }.to raise_error(RuntimeError, 'db.min_connections must be between 1 and 1000')
end
end
context 'min_connections is larger than max_connections' do
let(:cc_config) { super().merge({ 'db' => {'max_connections' => 1 }}) }
it 'raises an error' do
expect { rendering }.to raise_error(RuntimeError, 'db.min_connections must be larger or equal to db.max_connections')
end
end
end
end