1
+ require 'spec_helper'
2
+ require_relative '../../../lib/config/integrations/helpers/cf_manifest_merger'
3
+
4
+ describe Config ::CFManifestMerger do
5
+
6
+ let ( :mocked_rails_root_path ) { "#{ fixture_path } /cf/" }
7
+ let ( :manifest_hash ) { load_manifest ( 'cf_manifest.yml' ) }
8
+
9
+ it 'raises an argument error if you do not specify a target environment' do
10
+ expect {
11
+ Config ::CFManifestMerger . new ( nil , manifest_hash )
12
+ } . to raise_error ( ArgumentError , 'Target environment & manifest path must be specified' )
13
+ end
14
+
15
+ it 'returns the cf manifest unmodified if no settings are available' do
16
+ merger = Config ::CFManifestMerger . new ( 'test' , manifest_hash )
17
+
18
+ resulting_hash = merger . add_to_env
19
+ expect ( resulting_hash ) . to eq ( manifest_hash )
20
+ end
21
+
22
+ it 'adds the settings for the target_env to the manifest_hash' do
23
+ allow ( Rails ) . to receive ( :root ) . and_return ( mocked_rails_root_path )
24
+
25
+ merger = Config ::CFManifestMerger . new ( 'multilevel_settings' , manifest_hash )
26
+
27
+ resulting_hash = merger . add_to_env
28
+ expect ( resulting_hash ) . to eq ( {
29
+ 'applications' => [
30
+ {
31
+ 'name' => 'some-cf-app' ,
32
+ 'instances' => 1 ,
33
+ 'env' => {
34
+ 'DEFAULT_HOST' => 'host' ,
35
+ 'DEFAULT_PORT' => 'port' ,
36
+ 'FOO' => 'BAR' ,
37
+ 'Settings.world.capitals.europe.germany' => 'Berlin' ,
38
+ 'Settings.world.capitals.europe.poland' => 'Warsaw' ,
39
+ 'Settings.world.array.0.name' => 'Alan' ,
40
+ 'Settings.world.array.1.name' => 'Gam' ,
41
+ 'Settings.world.array_with_index.0.name' => 'Bob' ,
42
+ 'Settings.world.array_with_index.1.name' => 'William'
43
+ }
44
+ } ,
45
+ {
46
+ 'name' => 'app_name' ,
47
+ 'env' => {
48
+ 'DEFAULT_HOST' => 'host' ,
49
+ 'Settings.world.capitals.europe.germany' => 'Berlin' ,
50
+ 'Settings.world.capitals.europe.poland' => 'Warsaw' ,
51
+ 'Settings.world.array.0.name' => 'Alan' ,
52
+ 'Settings.world.array.1.name' => 'Gam' ,
53
+ 'Settings.world.array_with_index.0.name' => 'Bob' ,
54
+ 'Settings.world.array_with_index.1.name' => 'William'
55
+ }
56
+ }
57
+ ]
58
+ } )
59
+ end
60
+
61
+ it 'raises an exception if there is conflicting keys' do
62
+ allow ( Rails ) . to receive ( :root ) . and_return ( mocked_rails_root_path )
63
+
64
+ merger = Config ::CFManifestMerger . new ( 'conflict_settings' , manifest_hash )
65
+
66
+ # Config.load_and_set_settings "#{fixture_path}/cf/conflict_settings.yml"
67
+ expect {
68
+ merger . add_to_env
69
+ } . to raise_error ( ArgumentError , 'Conflicting keys: DEFAULT_HOST, DEFAULT_PORT' )
70
+ end
71
+
72
+ def load_manifest filename
73
+ YAML . load ( IO . read ( "#{ fixture_path } /cf/#{ filename } " ) )
74
+ end
75
+ end
0 commit comments