|
3 | 3 |
|
4 | 4 | describe Config::CFManifestMerger do |
5 | 5 |
|
6 | | - after do |
7 | | - Settings.reload_from_files("#{fixture_path}/settings.yml") |
8 | | - end |
9 | | - |
10 | | - it 'raises an argument error if you do not specify an app name' do |
11 | | - expect { |
12 | | - Config::CFManifestMerger.new(nil, load_manifest('cf_manifest.yml')) |
13 | | - }.to raise_error(ArgumentError, 'Manifest path & app name must be specified') |
14 | | - end |
| 6 | + let(:mocked_rails_root_path) { "#{fixture_path}/cf/" } |
| 7 | + let(:manifest_hash) { load_manifest('cf_manifest.yml') } |
15 | 8 |
|
16 | | - it 'raises an argument error if the application name is not found in the manifest' do |
| 9 | + it 'raises an argument error if you do not specify a target environment' do |
17 | 10 | expect { |
18 | | - Config::CFManifestMerger.new('undefined', load_manifest('cf_manifest.yml')).add_to_env |
19 | | - }.to raise_error(ArgumentError, "Application 'undefined' is not specified in your manifest") |
| 11 | + Config::CFManifestMerger.new(nil, manifest_hash) |
| 12 | + }.to raise_error(ArgumentError, 'Target environment & manifest path must be specified') |
20 | 13 | end |
21 | 14 |
|
22 | | - it 'returns the cf manifest template if no settings available' do |
23 | | - merger = Config::CFManifestMerger.new('app_name', load_manifest('cf_manifest.yml')) |
24 | | - Config.load_and_set_settings '' |
| 15 | + it 'returns the cf manifest unmodified if no settings are available' do |
| 16 | + merger = Config::CFManifestMerger.new('test', manifest_hash) |
25 | 17 |
|
26 | 18 | resulting_hash = merger.add_to_env |
27 | | - expect(resulting_hash).to eq(load_manifest('cf_manifest.yml')) |
| 19 | + expect(resulting_hash).to eq(manifest_hash) |
28 | 20 | end |
29 | 21 |
|
30 | | - it 'merges the given YAML file with the cf manifest YAML file' do |
31 | | - merger = Config::CFManifestMerger.new('some-cf-app', load_manifest('cf_manifest.yml')) |
32 | | - Config.load_and_set_settings "#{fixture_path}/cf/cf_multilevel.yml" |
| 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) |
33 | 26 |
|
34 | 27 | resulting_hash = merger.add_to_env |
35 | 28 | expect(resulting_hash).to eq({ |
36 | | - "applications" => [ |
| 29 | + 'applications' => [ |
37 | 30 | { |
38 | | - "name" => "some-cf-app", |
39 | | - "instances" => 1, |
40 | | - "env" => { |
41 | | - "DEFAULT_HOST" => "host", |
42 | | - "DEFAULT_PORT" => "port", |
43 | | - "FOO" => "BAR", |
44 | | - "Settings.world.capitals.europe.germany" => "Berlin", |
45 | | - "Settings.world.capitals.europe.poland" => "Warsaw", |
46 | | - "Settings.world.array.0.name" => "Alan", |
47 | | - "Settings.world.array.1.name" => "Gam", |
48 | | - "Settings.world.array_with_index.0.name" => "Bob", |
49 | | - "Settings.world.array_with_index.1.name" => "William" |
| 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' |
50 | 43 | } |
51 | 44 | }, |
52 | | - {"name"=>"app_name", "env"=>{"DEFAULT_HOST"=>"host"}} |
| 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 | + } |
53 | 57 | ] |
54 | 58 | }) |
55 | 59 | end |
56 | 60 |
|
57 | 61 | it 'raises an exception if there is conflicting keys' do |
58 | | - merger = Config::CFManifestMerger.new('some-cf-app', load_manifest('cf_manifest.yml')) |
59 | | - Config.load_and_set_settings "#{fixture_path}/cf/cf_conflict.yml" |
| 62 | + allow(Rails).to receive(:root).and_return(mocked_rails_root_path) |
| 63 | + |
| 64 | + merger = Config::CFManifestMerger.new('conflict_settings', manifest_hash) |
60 | 65 |
|
| 66 | + # Config.load_and_set_settings "#{fixture_path}/cf/conflict_settings.yml" |
61 | 67 | expect { |
62 | 68 | merger.add_to_env |
63 | 69 | }.to raise_error(ArgumentError, 'Conflicting keys: DEFAULT_HOST, DEFAULT_PORT') |
|
0 commit comments