1 require 'spec_helper_acceptance'
3 describe 'force merge of file' do
5 @basedir = setup_test_directory
8 describe 'when run should not force' do
11 concat { '#{@basedir}/file':
16 concat::fragment { '1':
17 target => '#{@basedir}/file',
18 content => '{"one": "foo"}',
21 concat::fragment { '2':
22 target => '#{@basedir}/file',
23 content => '{"one": "bar"}',
28 it 'applies manifest twice with stderr check' do
29 expect(apply_manifest(pp, expect_failures: true).stderr).to match("Duplicate key 'one' found with values 'foo' and bar'. Use 'force' attribute to merge keys.")
30 expect(apply_manifest(pp, expect_failures: true).stderr).to match("Duplicate key 'one' found with values 'foo' and bar'. Use 'force' attribute to merge keys.")
31 expect(file("#{@basedir}/file")).to be_file
32 expect(file("#{@basedir}/file").content).to match 'file exists'
33 expect(file("#{@basedir}/file").content).not_to match 'one: foo'
34 expect(file("#{@basedir}/file").content).not_to match 'one: bar'
38 describe 'when run should not force by default' do
41 concat { '#{@basedir}/file':
45 concat::fragment { '1':
46 target => '#{@basedir}/file',
47 content => '{"one": "foo"}',
50 concat::fragment { '2':
51 target => '#{@basedir}/file',
52 content => '{"one": "bar"}',
57 it 'applies manifest twice with stderr check' do
58 expect(apply_manifest(pp, expect_failures: true).stderr).to match("Duplicate key 'one' found with values 'foo' and bar'. Use 'force' attribute to merge keys.")
59 expect(apply_manifest(pp, expect_failures: true).stderr).to match("Duplicate key 'one' found with values 'foo' and bar'. Use 'force' attribute to merge keys.")
60 expect(file("#{@basedir}/file")).to be_file
61 expect(file("#{@basedir}/file").content).to match 'file exists'
62 expect(file("#{@basedir}/file").content).not_to match 'one: foo'
63 expect(file("#{@basedir}/file").content).not_to match 'one: bar'
67 describe 'when run should force' do
70 concat { '#{@basedir}/file':
75 concat::fragment { '1':
76 target => '#{@basedir}/file',
77 content => '{"one": "foo"}',
80 concat::fragment { '2':
81 target => '#{@basedir}/file',
82 content => '{"one": "bar"}',
87 it 'applies the manifest twice with no stderr' do
89 expect(file("#{@basedir}/file")).to be_file
90 expect(file("#{@basedir}/file").content).to match 'one: foo'
94 describe 'when run should force merge nested arrays' do
97 concat { '#{@basedir}/file':
102 concat::fragment { '1':
103 target => '#{@basedir}/file',
104 content => '{"one": [1]}',
107 concat::fragment { '2':
108 target => '#{@basedir}/file',
109 content => '{"one": [2]}',
114 it 'applies the manifest twice with no stderr' do
116 expect(file("#{@basedir}/file")).to be_file
117 expect(file("#{@basedir}/file").content).to contain '{"one":\[1,2\]}'
121 describe 'when run should not force on plain' do
124 concat { '#{@basedir}/file':
129 concat::fragment { '1':
130 target => '#{@basedir}/file',
131 content => '{"one": "foo"}',
134 concat::fragment { '2':
135 target => '#{@basedir}/file',
136 content => '{"one": "bar"}',
141 it 'applies the manifest twice with no stderr' do
143 expect(file("#{@basedir}/file")).to be_file
144 expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}'