]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/concat/spec/unit/defines/concat_fragment_spec.rb
try if downgrading to 1.2.2 solves my problem
[dsa-puppet.git] / 3rdparty / modules / concat / spec / unit / defines / concat_fragment_spec.rb
1 require 'spec_helper'
2
3 describe 'concat::fragment', :type => :define do
4
5   shared_examples 'fragment' do |title, params|
6     params = {} if params.nil?
7
8     p = {
9       :content => nil,
10       :source  => nil,
11       :order   => 10,
12       :ensure  => 'present',
13     }.merge(params)
14
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}"
19     id               = 'root'
20     gid              = 'root'
21     if p[:ensure] == 'absent'
22       safe_ensure = p[:ensure] 
23     else
24       safe_ensure = 'file'
25     end
26
27     let(:title) { title }
28     let(:facts) do
29       {
30         :concat_basedir => concatdir,
31         :id             => id,
32         :gid            => gid,
33         :osfamily       => 'Debian',
34         :path           => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
35         :is_pe          => false,
36       }
37     end
38     let(:params) { params }
39     let(:pre_condition) do
40       "concat{ '#{p[:target]}': }"
41     end
42
43     it do
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,
48         :owner   => id,
49         :group   => gid,
50         :mode    => '0640',
51         :source  => p[:source],
52         :content => p[:content],
53         :alias   => "concat_fragment_#{title}",
54         :backup  => 'puppet',
55       })
56     end
57   end
58
59   context 'title' do
60     ['0', '1', 'a', 'z'].each do |title|
61       it_behaves_like 'fragment', title, {
62         :target  => '/etc/motd',
63       }
64     end
65   end # title
66
67   context 'target =>' do
68     ['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
69       context target do
70         it_behaves_like 'fragment', target, {
71           :target  => '/etc/motd',
72         }
73       end
74     end
75
76     context 'false' do
77       let(:title) { 'motd_header' }
78       let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
79       let(:params) {{ :target => false }}
80
81       it 'should fail' do
82         expect { should }.to raise_error(Puppet::Error, /is not a string/)
83       end
84     end
85   end # target =>
86
87   context 'ensure =>' do
88     ['present', 'absent'].each do |ens|
89       context ens do
90         it_behaves_like 'fragment', 'motd_header', {
91           :ensure => ens,
92           :target => '/etc/motd',
93         }
94       end
95     end
96
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' }}
101
102       it 'should create a warning' do
103         skip('rspec-puppet support for testing warning()')
104       end
105     end
106   end # ensure =>
107
108   context 'content =>' do
109     ['', 'ashp is our hero'].each do |content|
110       context content do
111         it_behaves_like 'fragment', 'motd_header', {
112           :content => content,
113           :target  => '/etc/motd',
114         }
115       end
116     end
117
118     context 'false' do
119       let(:title) { 'motd_header' }
120       let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
121       let(:params) {{ :content => false, :target => '/etc/motd' }}
122
123       it 'should fail' do
124         expect { should }.to raise_error(Puppet::Error, /is not a string/)
125       end
126     end
127   end # content =>
128
129   context 'source =>' do
130     ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source|
131       context source do
132         it_behaves_like 'fragment', 'motd_header', {
133           :source => source,
134           :target => '/etc/motd',
135         }
136       end
137     end
138
139     context 'false' do
140       let(:title) { 'motd_header' }
141       let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
142       let(:params) {{ :source => false, :target => '/etc/motd' }}
143
144       it 'should fail' do
145         expect { should }.to raise_error(Puppet::Error, /is not a string or an Array/)
146       end
147     end
148   end # source =>
149
150   context 'order =>' do
151     ['', '42', 'a', 'z'].each do |order|
152       context '\'\'' do
153         it_behaves_like 'fragment', 'motd_header', {
154           :order  => order,
155           :target => '/etc/motd',
156         }
157       end
158     end
159
160     context 'false' do
161       let(:title) { 'motd_header' }
162       let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
163       let(:params) {{ :order => false, :target => '/etc/motd' }}
164
165       it 'should fail' do
166         expect { should }.to raise_error(Puppet::Error, /is not a string or integer/)
167       end
168     end
169
170     context '123:456' do
171       let(:title) { 'motd_header' }
172       let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
173       let(:params) {{ :order => '123:456', :target => '/etc/motd' }}
174
175       it 'should fail' do
176         expect { should }.to raise_error(Puppet::Error, /cannot contain/)
177       end
178     end
179     context '123/456' do
180       let(:title) { 'motd_header' }
181       let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
182       let(:params) {{ :order => '123/456', :target => '/etc/motd' }}
183
184       it 'should fail' do
185         expect { should }.to raise_error(Puppet::Error, /cannot contain/)
186       end
187     end
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' }}
192
193       it 'should fail' do
194         expect { should }.to raise_error(Puppet::Error, /cannot contain/)
195       end
196     end
197   end # order =>
198
199   context 'more than one content source' do
200     error_msg = 'You cannot specify more than one of $content, $source, $ensure => /target'
201
202     context 'ensure => target and source' do
203       let(:title) { 'motd_header' }
204       let(:facts) do
205         {
206           :concat_basedir => '/tmp',
207           :osfamily       => 'Debian',
208           :id             => 'root',
209           :is_pe          => false,
210           :gid            => 'root',
211         }
212       end
213       let(:params) do
214         {
215           :target  => '/etc/motd',
216           :ensure  => '/foo',
217           :source  => '/bar',
218         }
219       end
220
221       it 'should fail' do
222         expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
223       end
224     end
225
226     context 'ensure => target and content' do
227       let(:title) { 'motd_header' }
228       let(:facts) do
229         {
230           :concat_basedir => '/tmp',
231           :osfamily       => 'Debian',
232           :id             => 'root',
233           :is_pe          => false,
234           :gid            => 'root',
235         }
236       end
237       let(:params) do
238         {
239           :target  => '/etc/motd',
240           :ensure  => '/foo',
241           :content => 'bar',
242         }
243       end
244
245       it 'should fail' do
246         expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
247       end
248     end
249
250     context 'source and content' do
251       let(:title) { 'motd_header' }
252       let(:facts) do
253         {
254           :concat_basedir => '/tmp',
255           :osfamily       => 'Debian',
256           :id             => 'root',
257           :is_pe          => false,
258           :gid            => 'root',
259         }
260       end
261       let(:params) do
262         {
263           :target => '/etc/motd',
264           :source => '/foo',
265           :content => 'bar',
266         }
267       end
268
269       it 'should fail' do
270         expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
271       end
272     end
273
274   end # more than one content source
275
276   describe 'deprecated parameter' do
277     context 'mode =>' do
278       context '1755' do
279         it_behaves_like 'fragment', 'motd_header', {
280           :mode   => '1755',
281           :target => '/etc/motd',
282         }
283
284         it 'should create a warning' do
285           skip('rspec-puppet support for testing warning()')
286         end
287       end
288     end # mode =>
289
290     context 'owner =>' do
291       context 'apenny' do
292         it_behaves_like 'fragment', 'motd_header', {
293           :owner  => 'apenny',
294           :target => '/etc/motd',
295         }
296
297         it 'should create a warning' do
298           skip('rspec-puppet support for testing warning()')
299         end
300       end
301     end # owner =>
302
303     context 'group =>' do
304       context 'apenny' do
305         it_behaves_like 'fragment', 'motd_header', {
306           :group  => 'apenny',
307           :target => '/etc/motd',
308         }
309
310         it 'should create a warning' do
311           skip('rspec-puppet support for testing warning()')
312         end
313       end
314     end # group =>
315
316     context 'backup =>' do
317       context 'foo' do
318         it_behaves_like 'fragment', 'motd_header', {
319           :backup => 'foo',
320           :target => '/etc/motd',
321         }
322
323         it 'should create a warning' do
324           skip('rspec-puppet support for testing warning()')
325         end
326       end
327     end # backup =>
328   end # deprecated params
329
330 end