3 describe 'concat', :type => :define do
5 shared_examples 'concat' do |title, params, id|
6 params = {} if params.nil?
21 safe_name = title.gsub('/', '_')
22 concat_name = 'fragments.concat.out'
23 default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n"
26 :backup => p[:backup],
30 let(:params) { params }
34 :osfamily => 'Debian',
35 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
41 if p[:ensure] == 'present'
43 should contain_concat(title).with(file_defaults.merge({
49 :backup => p[:backup],
50 :replace => p[:replace],
55 should contain_concat(title).with(file_defaults.merge({
57 :backup => p[:backup],
64 context 'without path param' do
65 # title/name is the default value for the path param. therefore, the
66 # title must be an absolute path unless path is specified
67 ['/foo', '/foo/bar', '/foo/bar/baz'].each do |title|
69 it_behaves_like 'concat', '/etc/foo.bar'
73 ['./foo', 'foo', 'foo/bar'].each do |title|
77 expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/)
83 context 'with path param' do
84 ['/foo', 'foo', 'foo/bar'].each do |title|
86 it_behaves_like 'concat', title, { :path => '/etc/foo.bar' }
92 context 'as non-root user' do
93 it_behaves_like 'concat', '/etc/foo.bar', {}, 'bob'
96 context 'ensure =>' do
97 ['present', 'absent'].each do |ens|
99 it_behaves_like 'concat', '/etc/foo.bar', { :ensure => ens }
104 let(:title) { '/etc/foo.bar' }
105 let(:params) {{ :ensure => 'invalid' }}
107 expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/)
114 it_behaves_like 'concat', '/etc/foo.bar', { :path => '/foo' }
117 ['./foo', 'foo', 'foo/bar', false].each do |path|
119 let(:title) { '/etc/foo.bar' }
120 let(:params) {{ :path => path }}
122 expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/)
128 context 'owner =>' do
130 it_behaves_like 'concat', '/etc/foo.bar', { :owner => 'apenny' }
134 let(:title) { '/etc/foo.bar' }
135 let(:params) {{ :owner => false }}
137 expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
142 context 'group =>' do
144 it_behaves_like 'concat', '/etc/foo.bar', { :group => 'apenny' }
148 let(:title) { '/etc/foo.bar' }
149 let(:params) {{ :group => false }}
151 expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
158 it_behaves_like 'concat', '/etc/foo.bar', { :mode => '1755' }
162 let(:title) { '/etc/foo.bar' }
163 let(:params) {{ :mode => false }}
165 expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
171 [true, false, '# foo'].each do |warn|
173 it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
177 context '(stringified boolean)' do
178 ['true', 'yes', 'on', 'false', 'no', 'off'].each do |warn|
180 it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn }
182 it 'should create a warning' do
183 skip('rspec-puppet support for testing warning()')
190 let(:title) { '/etc/foo.bar' }
191 let(:params) {{ :warn => 123 }}
193 expect { catalogue }.to raise_error(Puppet::Error, /is not a string or boolean/)
198 context 'backup =>' do
200 it_behaves_like 'concat', '/etc/foo.bar', { :backup => 'reverse' }
204 it_behaves_like 'concat', '/etc/foo.bar', { :backup => false }
208 it_behaves_like 'concat', '/etc/foo.bar', { :backup => true }
212 let(:title) { '/etc/foo.bar' }
213 let(:params) {{ :backup => [] }}
215 expect { catalogue }.to raise_error(Puppet::Error, /backup must be string or bool/)
220 context 'replace =>' do
221 [true, false].each do |replace|
223 it_behaves_like 'concat', '/etc/foo.bar', { :replace => replace }
228 let(:title) { '/etc/foo.bar' }
229 let(:params) {{ :replace => 123 }}
231 expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
236 context 'order =>' do
237 ['alpha', 'numeric'].each do |order|
239 it_behaves_like 'concat', '/etc/foo.bar', { :order => order }
244 let(:title) { '/etc/foo.bar' }
245 let(:params) {{ :order => 'invalid' }}
247 expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
252 context 'ensure_newline =>' do
253 [true, false].each do |ensure_newline|
255 it_behaves_like 'concat', '/etc/foo.bar', { :ensure_newline => ensure_newline}
260 let(:title) { '/etc/foo.bar' }
261 let(:params) {{ :ensure_newline => 123 }}
263 expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
266 end # ensure_newline =>
268 context 'validate_cmd =>' do
269 context '/usr/bin/test -e %' do
270 it_behaves_like 'concat', '/etc/foo.bar', { :validate_cmd => '/usr/bin/test -e %' }
273 [ 1234, true ].each do |cmd|
275 let(:title) { '/etc/foo.bar' }
276 let(:params) {{ :validate_cmd => cmd }}
278 expect { catalogue }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/)
282 end # validate_cmd =>