3 describe 'concat::fragment', :type => :define do
5 shared_examples 'fragment' do |title, params|
6 params = {} if params.nil?
15 safe_name = title.gsub(/[\/\n]/, '_')
16 safe_target_name = p[:target].gsub(/[\/\n]/, '_')
17 concatdir = '/var/lib/puppet/concat'
18 fragdir = "#{concatdir}/#{safe_target_name}"
21 if p[:ensure] == 'absent'
22 safe_ensure = p[:ensure]
30 :concat_basedir => concatdir,
33 :osfamily => 'Debian',
34 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
38 let(:params) { params }
39 let(:pre_condition) do
40 "concat{ '#{p[:target]}': }"
44 should contain_class('concat::setup')
45 should contain_concat(p[:target])
46 should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({
47 :ensure => safe_ensure,
51 :source => p[:source],
52 :content => p[:content],
53 :alias => "concat_fragment_#{title}",
60 ['0', '1', 'a', 'z'].each do |title|
61 it_behaves_like 'fragment', title, {
62 :target => '/etc/motd',
67 context 'target =>' do
68 ['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
70 it_behaves_like 'fragment', target, {
71 :target => '/etc/motd',
77 let(:title) { 'motd_header' }
78 let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
79 let(:params) {{ :target => false }}
82 expect { should }.to raise_error(Puppet::Error, /is not a string/)
87 context 'ensure =>' do
88 ['present', 'absent'].each do |ens|
90 it_behaves_like 'fragment', 'motd_header', {
92 :target => '/etc/motd',
97 context 'any value other than \'present\' or \'absent\'' do
98 let(:title) { 'motd_header' }
99 let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
100 let(:params) {{ :ensure => 'invalid', :target => '/etc/motd' }}
102 it 'should create a warning' do
103 skip('rspec-puppet support for testing warning()')
108 context 'content =>' do
109 ['', 'ashp is our hero'].each do |content|
111 it_behaves_like 'fragment', 'motd_header', {
113 :target => '/etc/motd',
119 let(:title) { 'motd_header' }
120 let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
121 let(:params) {{ :content => false, :target => '/etc/motd' }}
124 expect { should }.to raise_error(Puppet::Error, /is not a string/)
129 context 'source =>' do
130 ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source|
132 it_behaves_like 'fragment', 'motd_header', {
134 :target => '/etc/motd',
140 let(:title) { 'motd_header' }
141 let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
142 let(:params) {{ :source => false, :target => '/etc/motd' }}
145 expect { should }.to raise_error(Puppet::Error, /is not a string or an Array/)
150 context 'order =>' do
151 ['', '42', 'a', 'z'].each do |order|
153 it_behaves_like 'fragment', 'motd_header', {
155 :target => '/etc/motd',
161 let(:title) { 'motd_header' }
162 let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
163 let(:params) {{ :order => false, :target => '/etc/motd' }}
166 expect { should }.to raise_error(Puppet::Error, /is not a string or integer/)
171 let(:title) { 'motd_header' }
172 let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
173 let(:params) {{ :order => '123:456', :target => '/etc/motd' }}
176 expect { should }.to raise_error(Puppet::Error, /cannot contain/)
180 let(:title) { 'motd_header' }
181 let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
182 let(:params) {{ :order => '123/456', :target => '/etc/motd' }}
185 expect { should }.to raise_error(Puppet::Error, /cannot contain/)
188 context '123\n456' do
189 let(:title) { 'motd_header' }
190 let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
191 let(:params) {{ :order => "123\n456", :target => '/etc/motd' }}
194 expect { should }.to raise_error(Puppet::Error, /cannot contain/)
199 context 'more than one content source' do
200 error_msg = 'You cannot specify more than one of $content, $source, $ensure => /target'
202 context 'ensure => target and source' do
203 let(:title) { 'motd_header' }
206 :concat_basedir => '/tmp',
207 :osfamily => 'Debian',
215 :target => '/etc/motd',
222 expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
226 context 'ensure => target and content' do
227 let(:title) { 'motd_header' }
230 :concat_basedir => '/tmp',
231 :osfamily => 'Debian',
239 :target => '/etc/motd',
246 expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
250 context 'source and content' do
251 let(:title) { 'motd_header' }
254 :concat_basedir => '/tmp',
255 :osfamily => 'Debian',
263 :target => '/etc/motd',
270 expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
274 end # more than one content source
276 describe 'deprecated parameter' do
279 it_behaves_like 'fragment', 'motd_header', {
281 :target => '/etc/motd',
284 it 'should create a warning' do
285 skip('rspec-puppet support for testing warning()')
290 context 'owner =>' do
292 it_behaves_like 'fragment', 'motd_header', {
294 :target => '/etc/motd',
297 it 'should create a warning' do
298 skip('rspec-puppet support for testing warning()')
303 context 'group =>' do
305 it_behaves_like 'fragment', 'motd_header', {
307 :target => '/etc/motd',
310 it 'should create a warning' do
311 skip('rspec-puppet support for testing warning()')
316 context 'backup =>' do
318 it_behaves_like 'fragment', 'motd_header', {
320 :target => '/etc/motd',
323 it 'should create a warning' do
324 skip('rspec-puppet support for testing warning()')
328 end # deprecated params