-
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathcf_manifest_merger_spec.rb
More file actions
76 lines (64 loc) · 3.69 KB
/
cf_manifest_merger_spec.rb
File metadata and controls
76 lines (64 loc) · 3.69 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
require 'spec_helper'
require_relative '../../../lib/config/integrations/helpers/cf_manifest_merger'
describe Config::CFManifestMerger do
let(:mocked_rails_root_path) { "#{fixture_path}/cf/" }
let(:manifest_hash) { load_manifest('cf_manifest.yml') }
it 'raises an argument error if you do not specify a target environment' do
expect {
Config::CFManifestMerger.new(nil, manifest_hash)
}.to raise_error(ArgumentError, 'Target environment & manifest path must be specified')
end
it 'returns the cf manifest unmodified if no settings are available' do
merger = Config::CFManifestMerger.new('test', manifest_hash)
resulting_hash = merger.add_to_env
expect(resulting_hash).to eq(manifest_hash)
end
it 'adds the settings for the target_env to the manifest_hash' do
allow(Rails).to receive(:root).and_return(mocked_rails_root_path)
# we use the target_env to load the proper settings file
merger = Config::CFManifestMerger.new('multilevel_settings', manifest_hash)
resulting_hash = merger.add_to_env
expect(resulting_hash).to eq({
'applications' => [
{
'name' => 'some-cf-app',
'instances' => 1,
'env' => {
'DEFAULT_HOST' => 'host',
'DEFAULT_PORT' => 'port',
'FOO' => 'BAR',
'Settings.world.capitals.europe.germany' => 'Berlin',
'Settings.world.capitals.europe.poland' => 'Warsaw',
'Settings.world.array.0.name' => 'Alan',
'Settings.world.array.1.name' => 'Gam',
'Settings.world.array_with_index.0.name' => 'Bob',
'Settings.world.array_with_index.1.name' => 'William'
}
},
{
'name' => 'app_name',
'env' => {
'DEFAULT_HOST' => 'host',
'Settings.world.capitals.europe.germany' => 'Berlin',
'Settings.world.capitals.europe.poland' => 'Warsaw',
'Settings.world.array.0.name' => 'Alan',
'Settings.world.array.1.name' => 'Gam',
'Settings.world.array_with_index.0.name' => 'Bob',
'Settings.world.array_with_index.1.name' => 'William'
}
}
]
})
end
it 'raises an exception if there is conflicting keys' do
allow(Rails).to receive(:root).and_return(mocked_rails_root_path)
merger = Config::CFManifestMerger.new('conflict_settings', manifest_hash)
# Config.load_and_set_settings "#{fixture_path}/cf/conflict_settings.yml"
expect {
merger.add_to_env
}.to raise_error(ArgumentError, 'Conflicting keys: DEFAULT_HOST, DEFAULT_PORT')
end
def load_manifest filename
YAML.load(IO.read("#{fixture_path}/cf/#{filename}"))
end
end