3 describe 'concat', :type => :define do
5 shared_examples 'concat' do |title, params, id|
6 params = {} if params.nil?
21 :ensure_newline => false,
25 safe_name = title.gsub('/', '_')
26 concatdir = '/var/lib/puppet/concat'
27 fragdir = "#{concatdir}/#{safe_name}"
28 concat_name = 'fragments.concat.out'
29 default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
32 :backup => p[:backup],
36 let(:params) { params }
39 :concat_basedir => concatdir,
41 :osfamily => 'Debian',
42 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
48 if p[:ensure] == 'present'
50 should contain_file(fragdir).with(file_defaults.merge({
51 :ensure => 'directory',
57 should contain_file("#{fragdir}/fragments").with(file_defaults.merge({
58 :ensure => 'directory',
61 :ignore => ['.svn', '.git', '.gitignore'],
68 "#{fragdir}/fragments.concat",
69 "#{fragdir}/#{concat_name}",
72 should contain_file(file).with(file_defaults.merge({
80 should contain_file(title).with(file_defaults.merge({
85 :replace => p[:replace],
87 :alias => "concat_#{title}",
88 :source => "#{fragdir}/#{concat_name}",
89 :validate_cmd => p[:validate_cmd],
90 :backup => p[:backup],
94 cmd = "#{concatdir}/bin/concatfragments.rb " +
95 "-o \"#{concatdir}/#{safe_name}/fragments.concat.out\" " +
96 "-d \"#{concatdir}/#{safe_name}\""
98 # flag order: fragdir, warnflag, forceflag, orderflag, newlineflag
102 message = default_warn_message
103 when 'true', 'yes', 'on'
104 # should generate a stringified boolean warning
105 message = default_warn_message
108 when 'false', 'no', 'off'
109 # should generate a stringified boolean warning
116 cmd += " -w \'#{message}\'"
120 cmd += " -f" if p[:force]
121 cmd += " -n" if p[:order] == 'numeric'
122 cmd += " -l" if p[:ensure_newline] == true
125 should contain_exec("concat_#{title}").with({
126 :alias => "concat_#{fragdir}",
128 :unless => "#{cmd} -t",
134 "#{fragdir}/fragments",
135 "#{fragdir}/fragments.concat",
136 "#{fragdir}/#{concat_name}",
139 should contain_file(file).with(file_defaults.merge({
147 should contain_file(title).with(file_defaults.merge({
149 :backup => p[:backup],
154 should contain_exec("concat_#{title}").with({
155 :alias => "concat_#{fragdir}",
158 :path => '/bin:/usr/bin',
165 context 'without path param' do
166 # title/name is the default value for the path param. therefore, the
167 # title must be an absolute path unless path is specified
168 ['/foo', '/foo/bar', '/foo/bar/baz'].each do |title|
170 it_behaves_like 'concat', '/etc/foo.bar'
174 ['./foo', 'foo', 'foo/bar'].each do |title|
176 let(:title) { title }
178 expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
184 context 'with path param' do
185 ['./foo', 'foo', 'foo/bar'].each do |title|
187 it_behaves_like 'concat', title, { :path => '/etc/foo.bar' }
193 context 'as non-root user' do
194 it_behaves_like 'concat', '/etc/foo.bar', {}, 'bob'
197 context 'ensure =>' do
198 ['present', 'absent'].each do |ens|
200 it_behaves_like 'concat', '/etc/foo.bar', { :ensure => ens }
205 let(:title) { '/etc/foo.bar' }
206 let(:params) {{ :ensure => 'invalid' }}
208 expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/)
215 it_behaves_like 'concat', '/etc/foo.bar', { :path => '/foo' }
218 ['./foo', 'foo', 'foo/bar', false].each do |path|
220 let(:title) { '/etc/foo.bar' }
221 let(:params) {{ :path => path }}
223 expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
229 context 'owner =>' do
231 it_behaves_like 'concat', '/etc/foo.bar', { :owner => 'apenny' }
235 let(:title) { '/etc/foo.bar' }
236 let(:params) {{ :owner => false }}
238 expect { should }.to raise_error(Puppet::Error, /is not a string/)
243 context 'group =>' do
245 it_behaves_like 'concat', '/etc/foo.bar', { :group => 'apenny' }
249 let(:title) { '/etc/foo.bar' }
250 let(:params) {{ :group => false }}
252 expect { should }.to raise_error(Puppet::Error, /is not a string/)
259 it_behaves_like 'concat', '/etc/foo.bar', { :mode => '1755' }
263 let(:title) { '/etc/foo.bar' }
264 let(:params) {{ :mode => false }}
266 expect { should }.to raise_error(Puppet::Error, /is not a string/)
272 [true, false, '# foo'].each do |warn|
274 it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
278 context '(stringified boolean)' do
279 ['true', 'yes', 'on', 'false', 'no', 'off'].each do |warn|
281 it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
283 it 'should create a warning' do
284 skip('rspec-puppet support for testing warning()')
291 let(:title) { '/etc/foo.bar' }
292 let(:params) {{ :warn => 123 }}
294 expect { should }.to raise_error(Puppet::Error, /is not a string or boolean/)
299 context 'force =>' do
300 [true, false].each do |force|
302 it_behaves_like 'concat', '/etc/foo.bar', { :force => force }
307 let(:title) { '/etc/foo.bar' }
308 let(:params) {{ :force => 123 }}
310 expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
315 context 'backup =>' do
317 it_behaves_like 'concat', '/etc/foo.bar', { :backup => 'reverse' }
321 it_behaves_like 'concat', '/etc/foo.bar', { :backup => false }
325 it_behaves_like 'concat', '/etc/foo.bar', { :backup => true }
329 let(:title) { '/etc/foo.bar' }
330 let(:params) {{ :backup => [] }}
332 expect { should }.to raise_error(Puppet::Error, /backup must be string or bool/)
337 context 'replace =>' do
338 [true, false].each do |replace|
340 it_behaves_like 'concat', '/etc/foo.bar', { :replace => replace }
345 let(:title) { '/etc/foo.bar' }
346 let(:params) {{ :replace => 123 }}
348 expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
353 context 'order =>' do
354 ['alpha', 'numeric'].each do |order|
356 it_behaves_like 'concat', '/etc/foo.bar', { :order => order }
361 let(:title) { '/etc/foo.bar' }
362 let(:params) {{ :order => 'invalid' }}
364 expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
369 context 'ensure_newline =>' do
370 [true, false].each do |ensure_newline|
372 it_behaves_like 'concat', '/etc/foo.bar', { :ensure_newline => ensure_newline}
377 let(:title) { '/etc/foo.bar' }
378 let(:params) {{ :ensure_newline => 123 }}
380 expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
383 end # ensure_newline =>
385 context 'validate_cmd =>' do
386 context '/usr/bin/test -e %' do
387 it_behaves_like 'concat', '/etc/foo.bar', { :validate_cmd => '/usr/bin/test -e %' }
390 [ 1234, true ].each do |cmd|
392 let(:title) { '/etc/foo.bar' }
393 let(:params) {{ :validate_cmd => cmd }}
395 expect { should }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/)
399 end # validate_cmd =>
401 describe 'deprecated parameter' do
404 it_behaves_like 'concat', '/etc/foo.bar', { :gnu => 'foo'}
406 it 'should create a warning' do
407 skip('rspec-puppet support for testing warning()')
415 # vim:sw=2:ts=2:expandtab:textwidth=79