Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / acceptance / force_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'force merge of file' do
4   before(:all) do
5     @basedir = setup_test_directory
6   end
7
8   describe 'when run should not force' do
9     let(:pp) do
10       <<-MANIFEST
11         concat { '#{@basedir}/file':
12           format => 'yaml',
13           force => false,
14         }
15
16         concat::fragment { '1':
17           target  => '#{@basedir}/file',
18           content => '{"one": "foo"}',
19         }
20
21         concat::fragment { '2':
22           target  => '#{@basedir}/file',
23           content => '{"one": "bar"}',
24         }
25       MANIFEST
26     end
27
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'
35     end
36   end
37
38   describe 'when run should not force by default' do
39     let(:pp) do
40       <<-MANIFEST
41         concat { '#{@basedir}/file':
42           format => 'yaml',
43         }
44
45         concat::fragment { '1':
46           target  => '#{@basedir}/file',
47           content => '{"one": "foo"}',
48         }
49
50         concat::fragment { '2':
51           target  => '#{@basedir}/file',
52           content => '{"one": "bar"}',
53         }
54       MANIFEST
55     end
56
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'
64     end
65   end
66
67   describe 'when run should force' do
68     let(:pp) do
69       <<-MANIFEST
70         concat { '#{@basedir}/file':
71           format => 'yaml',
72           force => true,
73         }
74
75         concat::fragment { '1':
76           target  => '#{@basedir}/file',
77           content => '{"one": "foo"}',
78         }
79
80         concat::fragment { '2':
81           target  => '#{@basedir}/file',
82           content => '{"one": "bar"}',
83         }
84       MANIFEST
85     end
86
87     it 'applies the manifest twice with no stderr' do
88       idempotent_apply(pp)
89       expect(file("#{@basedir}/file")).to be_file
90       expect(file("#{@basedir}/file").content).to match 'one: foo'
91     end
92   end
93
94   describe 'when run should force merge nested arrays' do
95     let(:pp) do
96       <<-MANIFEST
97         concat { '#{@basedir}/file':
98           format => 'json',
99           force => true,
100         }
101
102         concat::fragment { '1':
103           target  => '#{@basedir}/file',
104           content => '{"one": [1]}',
105         }
106
107         concat::fragment { '2':
108           target  => '#{@basedir}/file',
109           content => '{"one": [2]}',
110         }
111       MANIFEST
112     end
113
114     it 'applies the manifest twice with no stderr' do
115       idempotent_apply(pp)
116       expect(file("#{@basedir}/file")).to be_file
117       expect(file("#{@basedir}/file").content).to contain '{"one":\[1,2\]}'
118     end
119   end
120
121   describe 'when run should not force on plain' do
122     let(:pp) do
123       <<-MANIFEST
124         concat { '#{@basedir}/file':
125           force => true,
126           format => plain,
127         }
128
129         concat::fragment { '1':
130           target  => '#{@basedir}/file',
131           content => '{"one": "foo"}',
132         }
133
134         concat::fragment { '2':
135           target  => '#{@basedir}/file',
136           content => '{"one": "bar"}',
137         }
138       MANIFEST
139     end
140
141     it 'applies the manifest twice with no stderr' do
142       idempotent_apply(pp)
143       expect(file("#{@basedir}/file")).to be_file
144       expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}'
145     end
146   end
147 end