3 describe 'concat', :type => :define do
5 shared_examples 'concat' do |title, params, id|
6 params = {} if params.nil?
22 :backup => p[:backup],
26 let(:params) { params }
30 :osfamily => 'Debian',
31 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
37 if p[:ensure] == 'present'
39 should contain_concat(title).with(file_defaults.merge({
45 :backup => p[:backup],
46 :replace => p[:replace],
47 :selinux_ignore_defaults => p[:selinux_ignore_defaults],
48 :selrange => p[:selrange],
49 :selrole => p[:selrole],
50 :seltype => p[:seltype],
51 :seluser => p[:seluser],
56 should contain_concat(title).with(file_defaults.merge({
58 :backup => p[:backup],
65 context '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|
78 expect { catalogue }.to raise_error(Puppet::Error, /Stdlib::Unixpath/)
84 context 'with path param' do
85 ['/foo', 'foo', 'foo/bar'].each do |title|
87 it_behaves_like 'concat', title, { :path => '/etc/foo.bar' }
92 context 'with special characters in title' do
93 ['foo:bar', 'foo*bar', 'foo(bar)', 'foo@bar'].each do |title|
95 it_behaves_like 'concat', title, { :path => '/etc/foo.bar' }
101 context 'as non-root user' do
102 it_behaves_like 'concat', '/etc/foo.bar', {}, 'bob'
105 context 'ensure =>' do
106 ['present', 'absent'].each do |ens|
108 it_behaves_like 'concat', '/etc/foo.bar', { :ensure => ens }
113 let(:title) { '/etc/foo.bar' }
114 let(:params) {{ :ensure => 'invalid' }}
116 expect { catalogue }.to raise_error(Puppet::Error, /expects a match for Enum\['absent', 'present'\]/)
123 it_behaves_like 'concat', '/etc/foo.bar', { :path => '/foo' }
127 let(:title) { '/etc/foo.bar' }
128 let(:params) {{ :path => false }}
130 expect { catalogue }.to raise_error(Puppet::Error, /Stdlib::Unixpath/)
134 ['./foo', 'foo', 'foo/bar'].each do |path|
136 let(:title) { '/etc/foo.bar' }
137 let(:params) {{ :path => path }}
139 expect { catalogue }.to raise_error(Puppet::Error, /Stdlib::Unixpath/)
145 context 'owner =>' do
146 ['apenney',1000,'1001'].each do |owner|
148 it_behaves_like 'concat', '/etc/foo.bar', { :owner => owner }
153 let(:title) { '/etc/foo.bar' }
154 let(:params) {{ :owner => false }}
156 expect { catalogue }.to raise_error(Puppet::Error, /Evaluation Error.*expects.*String.*Boolean.*/)
161 context 'group =>' do
162 ['apenney',1000,'1001'].each do |group|
164 it_behaves_like 'concat', '/etc/foo.bar', { :group => group }
169 let(:title) { '/etc/foo.bar' }
170 let(:params) {{ :group => false }}
172 expect { catalogue }.to raise_error(Puppet::Error, /Evaluation Error.*expects.*String.*Boolean.*/)
179 it_behaves_like 'concat', '/etc/foo.bar', { :mode => '1755' }
183 let(:title) { '/etc/foo.bar' }
184 let(:params) {{ :mode => false }}
186 expect { catalogue }.to raise_error(Puppet::Error, /parameter 'mode' expects .*String.*/)
192 [true, false, '# foo'].each do |warn|
194 it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
198 context '(stringified boolean)' do
199 ['true', 'yes', 'on', 'false', 'no', 'off'].each do |warn|
201 it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
203 it 'should create a warning' do
204 skip('rspec-puppet support for testing warning()')
211 let(:title) { '/etc/foo.bar' }
212 let(:params) {{ :warn => 123 }}
214 expect { catalogue }.to raise_error(Puppet::Error, /parameter 'warn' expects .*Boolean.*String.*/)
219 context 'show_diff =>' do
220 [true, false].each do |show_diff|
222 it_behaves_like 'concat', '/etc/foo.bar', { :show_diff => show_diff }
227 let(:title) { '/etc/foo.bar' }
228 let(:params) {{ :show_diff => 123 }}
230 expect { catalogue }.to raise_error(Puppet::Error, /parameter 'show_diff' expects .*Boolean.*/)
235 context 'backup =>' do
236 ['reverse',false,true].each do |backup|
237 context "#{backup}" do
238 it_behaves_like 'concat', '/etc/foo.bar', { :backup => backup }
243 let(:title) { '/etc/foo.bar' }
244 let(:params) {{ :backup => [] }}
246 expect { catalogue }.to raise_error(Puppet::Error, /parameter 'backup' expects .*Boolean.*String.*/)
251 context 'replace =>' do
252 [true, false].each do |replace|
254 it_behaves_like 'concat', '/etc/foo.bar', { :replace => replace }
259 let(:title) { '/etc/foo.bar' }
260 let(:params) {{ :replace => 123 }}
262 expect { catalogue }.to raise_error(Puppet::Error, /parameter 'replace' expects .*Boolean.*/)
267 context 'order =>' do
268 ['alpha', 'numeric'].each do |order|
270 it_behaves_like 'concat', '/etc/foo.bar', { :order => order }
275 let(:title) { '/etc/foo.bar' }
276 let(:params) {{ :order => 'invalid' }}
278 expect { catalogue }.to raise_error(Puppet::Error, /expects a match for Enum\['alpha', 'numeric'\]/)
283 context 'ensure_newline =>' do
284 [true, false].each do |ensure_newline|
286 it_behaves_like 'concat', '/etc/foo.bar', { :ensure_newline => ensure_newline}
291 let(:title) { '/etc/foo.bar' }
292 let(:params) {{ :ensure_newline => 123 }}
294 expect { catalogue }.to raise_error(Puppet::Error, /parameter 'ensure_newline' expects a Boolean value/)
297 end # ensure_newline =>
299 context 'validate_cmd =>' do
300 context '/usr/bin/test -e %' do
301 it_behaves_like 'concat', '/etc/foo.bar', { :validate_cmd => '/usr/bin/test -e %' }
304 [ 1234, true ].each do |cmd|
306 let(:title) { '/etc/foo.bar' }
307 let(:params) {{ :validate_cmd => cmd }}
309 expect { catalogue }.to raise_error(Puppet::Error, /parameter 'validate_cmd' expects.*String.*/)
313 end # validate_cmd =>
315 context 'selinux_ignore_defaults =>' do
316 let(:title) { '/etc/foo.bar' }
318 [true, false].each do |v|
320 it_behaves_like 'concat', '/etc/foo.bar', { :selinux_ignore_defaults => v }
325 let(:title) { '/etc/foo.bar' }
326 let(:params) {{ :selinux_ignore_defaults => 123 }}
328 expect { catalogue }.to raise_error(Puppet::Error, /Evaluation Error.*expects.*Boolean.*/)
331 end # selinux_ignore_defaults =>
339 context " #{p} =>" do
340 let(:title) { '/etc/foo.bar' }
343 it_behaves_like 'concat', '/etc/foo.bar', { p => 'foo' }
347 let(:title) { '/etc/foo.bar' }
348 let(:params) {{ p => false }}
350 expect { catalogue }.to raise_error(Puppet::Error, /parameter '#{p}' expects.*String.*/)