4 shared_examples 'concat' do |title, params, id|
5 params = {} if params.nil?
33 selinux_ignore_defaults: p[:selinux_ignore_defaults],
34 selrange: p[:selrange],
42 let(:params) { params }
47 path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
53 if p[:ensure] == 'present'
55 is_expected.to contain_concat(title).with(file_defaults.merge(present_expect))
59 is_expected.to contain_concat(title).with(file_defaults.merge(ensure: 'absent',
65 context 'when title without path param' do
66 # title/name is the default value for the path param. therefore, the
67 # title must be an absolute path unless path is specified
68 ['/foo', '/foo/bar', '/foo/bar/baz'].each do |title|
70 it_behaves_like 'concat', '/etc/foo.bar'
74 ['./foo', 'foo', 'foo/bar'].each do |title|
79 expect { catalogue }.to raise_error(Puppet::Error, %r{Stdlib::Unixpath})
85 context 'when title with path param' do
86 ['/foo', 'foo', 'foo/bar'].each do |title|
88 it_behaves_like 'concat', title, path: '/etc/foo.bar'
93 context 'when title with special characters in title' do
94 ['foo:bar', 'foo*bar', 'foo(bar)', 'foo@bar'].each do |title|
96 it_behaves_like 'concat', title, path: '/etc/foo.bar'
101 context 'when as non-root user' do
102 it_behaves_like 'concat', '/etc/foo.bar', {}, 'bob'
105 context 'when ensure =>' do
106 ['present', 'absent'].each do |ens|
108 it_behaves_like 'concat', '/etc/foo.bar', ensure: ens
112 context 'when invalid' do
113 let(:title) { '/etc/foo.bar' }
114 let(:params) { { ensure: 'invalid' } }
117 expect { catalogue }.to raise_error(Puppet::Error, %r{expects a match for Enum\['absent', 'present'\]})
123 context 'when path =>' do
124 context 'when /foo' do
125 it_behaves_like 'concat', '/etc/foo.bar', path: '/foo'
128 context 'when false' do
129 let(:title) { '/etc/foo.bar' }
130 let(:params) { { path: false } }
133 expect { catalogue }.to raise_error(Puppet::Error, %r{Stdlib::Unixpath})
137 ['./foo', 'foo', 'foo/bar'].each do |path|
139 let(:title) { '/etc/foo.bar' }
140 let(:params) { { path: path } }
143 expect { catalogue }.to raise_error(Puppet::Error, %r{Stdlib::Unixpath})
150 context 'when owner =>' do
151 ['apenney', 1000, '1001'].each do |owner|
153 it_behaves_like 'concat', '/etc/foo.bar', owner: owner
157 context 'when false' do
158 let(:title) { '/etc/foo.bar' }
159 let(:params) { { owner: false } }
162 expect { catalogue }.to raise_error(Puppet::Error, %r{Evaluation Error.*expects.*String.*Boolean.*})
168 context 'when group =>' do
169 ['apenney', 1000, '1001'].each do |group|
171 it_behaves_like 'concat', '/etc/foo.bar', group: group
175 context 'when false' do
176 let(:title) { '/etc/foo.bar' }
177 let(:params) { { group: false } }
180 expect { catalogue }.to raise_error(Puppet::Error, %r{Evaluation Error.*expects.*String.*Boolean.*})
186 context 'when mode =>' do
187 context 'when 1755' do
188 it_behaves_like 'concat', '/etc/foo.bar', mode: '1755'
191 context 'when false' do
192 let(:title) { '/etc/foo.bar' }
193 let(:params) { { mode: false } }
196 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'mode' expects .*String.*})
202 context 'when warn =>' do
203 [true, false, '# foo'].each do |warn|
205 it_behaves_like 'concat', '/etc/foo.bar', warn: warn
209 context 'when (stringified boolean)' do
210 ['true', 'yes', 'on', 'false', 'no', 'off'].each do |warn|
212 it_behaves_like 'concat', '/etc/foo.bar', warn: warn
214 it 'creates a warning' do
215 skip('rspec-puppet support for testing warning()')
221 context 'when 123' do
222 let(:title) { '/etc/foo.bar' }
223 let(:params) { { warn: 123 } }
226 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'warn' expects .*Boolean.*String.*})
232 context 'when show_diff =>' do
233 [true, false].each do |show_diff|
235 it_behaves_like 'concat', '/etc/foo.bar', show_diff: show_diff
239 context 'when 123' do
240 let(:title) { '/etc/foo.bar' }
241 let(:params) { { show_diff: 123 } }
244 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'show_diff' expects .*Boolean.*})
250 context 'when backup =>' do
251 ['reverse', false, true].each do |backup|
252 context backup.to_s do
253 it_behaves_like 'concat', '/etc/foo.bar', backup: backup
257 context 'when true' do
258 let(:title) { '/etc/foo.bar' }
259 let(:params) { { backup: [] } }
262 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'backup' expects .*Boolean.*String.*})
268 context 'when replace =>' do
269 [true, false].each do |replace|
271 it_behaves_like 'concat', '/etc/foo.bar', replace: replace
275 context 'when 123' do
276 let(:title) { '/etc/foo.bar' }
277 let(:params) { { replace: 123 } }
280 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'replace' expects .*Boolean.*})
286 context 'when force =>' do
287 [true, false].each do |force|
289 it_behaves_like 'concat', '/etc/foo.bar', force: force
293 context 'when 123' do
294 let(:title) { '/etc/foo.bar' }
295 let(:params) { { force: 123 } }
298 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'force' expects .*Boolean.*})
304 context 'when order =>' do
305 ['alpha', 'numeric'].each do |order|
307 it_behaves_like 'concat', '/etc/foo.bar', order: order
311 context 'when invalid' do
312 let(:title) { '/etc/foo.bar' }
313 let(:params) { { order: 'invalid' } }
316 expect { catalogue }.to raise_error(Puppet::Error, %r{expects a match for Enum\['alpha', 'numeric'\]})
322 context 'when ensure_newline =>' do
323 [true, false].each do |ensure_newline|
324 context 'when true' do
325 it_behaves_like 'concat', '/etc/foo.bar', ensure_newline: ensure_newline
329 context 'when 123' do
330 let(:title) { '/etc/foo.bar' }
331 let(:params) { { ensure_newline: 123 } }
334 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'ensure_newline' expects a Boolean value})
340 context 'when validate_cmd =>' do
341 context 'when /usr/bin/test -e %' do
342 it_behaves_like 'concat', '/etc/foo.bar', validate_cmd: '/usr/bin/test -e %'
345 [1234, true].each do |cmd|
347 let(:title) { '/etc/foo.bar' }
348 let(:params) { { validate_cmd: cmd } }
351 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'validate_cmd' expects.*String.*})
358 context 'when selinux_ignore_defaults =>' do
359 let(:title) { '/etc/foo.bar' }
361 [true, false].each do |v|
363 it_behaves_like 'concat', '/etc/foo.bar', selinux_ignore_defaults: v
367 context 'when 123' do
368 let(:title) { '/etc/foo.bar' }
369 let(:params) { { selinux_ignore_defaults: 123 } }
372 expect { catalogue }.to raise_error(Puppet::Error, %r{Evaluation Error.*expects.*Boolean.*})
376 # selinux_ignore_defaults =>
384 context " #{p} =>" do
385 let(:title) { '/etc/foo.bar' }
387 context 'when foo' do
388 it_behaves_like 'concat', '/etc/foo.bar', p => 'foo'
391 context 'when false' do
392 let(:title) { '/etc/foo.bar' }
393 let(:params) { { p => false } }
396 expect { catalogue }.to raise_error(Puppet::Error, %r{parameter '#{p}' expects.*String.*})