Skip to content

Commit 0c12f66

Browse files
committed
fix constant
1 parent 5f72668 commit 0c12f66

File tree

1 file changed

+70
-64
lines changed

1 file changed

+70
-64
lines changed

spec/cloud_controller_ng/storage_cli_config_jsons_spec.rb

Lines changed: 70 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,84 @@
1-
# spec/templates/storage_cli_config_jsons_spec.rb
1+
# frozen_string_literal: true
2+
23
require 'rspec'
3-
require 'json'
4+
require 'yaml'
45
require 'bosh/template/test'
56

6-
module Bosh::Template::Test
7-
RSpec.describe 'storage-cli JSON templates' do
8-
let(:release_path) { File.join(File.dirname(__FILE__), '../..') }
9-
let(:release) { ReleaseDir.new(release_path) }
10-
let(:job) { release.job('cloud_controller_ng') }
11-
let(:links) { {} }
12-
let(:props) do
13-
{
14-
'cc' => {
15-
'droplets' => { 'connection_config' => {} },
16-
'buildpacks' => { 'connection_config' => {} },
17-
'packages' => { 'connection_config' => {} },
18-
'resource_pool'=> { 'connection_config' => {} },
19-
}
20-
}
21-
end
7+
TEMPLATES = {
8+
droplets: ['config/storage_cli_config_droplets.json', %w[cc droplets connection_config]],
9+
buildpacks: ['config/storage_cli_config_buildpacks.json', %w[cc buildpacks connection_config]],
10+
packages: ['config/storage_cli_config_packages.json', %w[cc packages connection_config]],
11+
resource_pool: ['config/storage_cli_config_resource_pool.json', %w[cc resource_pool connection_config]]
12+
}.freeze
2213

23-
TEMPLATES = {
24-
droplets: ['config/storage_cli_config_droplets.json', %w[cc droplets connection_config]],
25-
buildpacks: ['config/storage_cli_config_buildpacks.json', %w[cc buildpacks connection_config]],
26-
packages: ['config/storage_cli_config_packages.json', %w[cc packages connection_config]],
27-
resource_pool: ['config/storage_cli_config_resource_pool.json', %w[cc resource_pool connection_config]],
28-
}.freeze
14+
module Bosh
15+
module Template
16+
module Test
17+
RSpec.describe 'storage-cli JSON templates' do
18+
let(:release_path) { File.join(File.dirname(__FILE__), '../..') }
19+
let(:release) { ReleaseDir.new(release_path) }
20+
let(:job) { release.job('cloud_controller_ng') }
21+
let(:links) { {} }
22+
let(:props) do
23+
{
24+
'cc' => {
25+
'droplets' => { 'connection_config' => {} },
26+
'buildpacks' => { 'connection_config' => {} },
27+
'packages' => { 'connection_config' => {} },
28+
'resource_pool' => { 'connection_config' => {} }
29+
}
30+
}
31+
end
2932

30-
TEMPLATES.each do |scope, (template_path, keypath)|
31-
describe template_path do
32-
let(:template) { job.template(template_path) }
33+
TEMPLATES.each_value do |(template_path, keypath)|
34+
describe template_path do
35+
let(:template) { job.template(template_path) }
3336

34-
def set(props, keypath, value)
35-
h = props
36-
keypath[0..-2].each { |k| h = (h[k] ||= {}) }
37-
h[keypath.last] = value
38-
end
37+
def set(hash, path, value)
38+
cursor = hash
39+
path[0..-2].each { |key| cursor = (cursor[key] ||= {}) }
40+
cursor[path.last] = value
41+
end
3942

40-
it 'renders and normalizes put_timeout_in_seconds to "41" when blank' do
41-
set(props, keypath, {
42-
'provider' => 'AzureRM',
43-
'azure_storage_account_name' => 'acc',
44-
'azure_storage_access_key' => 'key',
45-
'container_name' => 'cont',
46-
'put_timeout_in_seconds' => ''
47-
})
43+
it 'renders and normalizes put_timeout_in_seconds to "41" when blank' do
44+
set(props, keypath, {
45+
'provider' => 'AzureRM',
46+
'azure_storage_account_name' => 'acc',
47+
'azure_storage_access_key' => 'key',
48+
'container_name' => 'cont',
49+
'put_timeout_in_seconds' => ''
50+
})
4851

49-
json = JSON.parse(template.render(props, consumes: links))
50-
expect(json).to include(
51-
'provider' => 'AzureRM',
52-
'account_name' => 'acc',
53-
'account_key' => 'key',
54-
'container_name' => 'cont',
55-
'put_timeout_in_seconds' => '41'
56-
)
57-
end
52+
json = YAML.safe_load(template.render(props, consumes: links))
53+
expect(json).to include(
54+
'provider' => 'AzureRM',
55+
'account_name' => 'acc',
56+
'account_key' => 'key',
57+
'container_name' => 'cont',
58+
'put_timeout_in_seconds' => '41'
59+
)
60+
end
5861

59-
it 'keeps existing put_timeout_in_seconds when provided' do
60-
set(props, keypath, {
61-
'provider' => 'AzureRM',
62-
'azure_storage_account_name' => 'acc',
63-
'azure_storage_access_key' => 'key',
64-
'container_name' => 'cont',
65-
'put_timeout_in_seconds' => '7'
66-
})
62+
it 'keeps existing put_timeout_in_seconds when provided' do
63+
set(props, keypath, {
64+
'provider' => 'AzureRM',
65+
'azure_storage_account_name' => 'acc',
66+
'azure_storage_access_key' => 'key',
67+
'container_name' => 'cont',
68+
'put_timeout_in_seconds' => '7'
69+
})
6770

68-
json = JSON.parse(template.render(props, consumes: links))
69-
expect(json['put_timeout_in_seconds']).to eq('7')
70-
end
71+
json = YAML.safe_load(template.render(props, consumes: links))
72+
expect(json['put_timeout_in_seconds']).to eq('7')
73+
end
74+
75+
it 'renders {} for non-Azure providers' do
76+
set(props, keypath, { 'provider' => 'S3' })
7177

72-
it 'renders {} for non-Azure providers' do
73-
set(props, keypath, { 'provider' => 'S3' })
74-
json = JSON.parse(template.render(props, consumes: links))
75-
expect(json).to eq({})
78+
json = YAML.safe_load(template.render(props, consumes: links))
79+
expect(json).to eq({})
80+
end
81+
end
7682
end
7783
end
7884
end

0 commit comments

Comments
 (0)