Add additional acceptance testing.
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / unattended_upgrade_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apt::unattended_upgrades class' do
4   context 'defaults' do
5     it 'should work with no errors' do
6       pp = <<-EOS
7       include apt
8       include apt::unattended_upgrades
9       EOS
10
11       apply_manifest(pp, :catch_failures => true)
12     end
13
14     describe file('/etc/apt/apt.conf.d/10periodic') do
15       it { should be_file }
16     end
17     describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
18       it { should be_file }
19     end
20   end
21
22   context 'origins' do
23     it 'should work with no errors' do
24       pp = <<-EOS
25       include apt
26       class { 'apt::unattended_upgrades':
27         origins => ['${distro_id}:${distro_codename}-test'],
28       }
29       EOS
30
31       apply_manifest(pp, :catch_failures => true)
32     end
33
34     describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
35       it { should be_file }
36       it { should contain '${distro_id}:${distro_codename}-test' }
37     end
38   end
39
40   context 'blacklist' do
41     it 'should work with no errors' do
42       pp = <<-EOS
43       include apt
44       class { 'apt::unattended_upgrades':
45         blacklist => ['puppet']
46       }
47       EOS
48
49       apply_manifest(pp, :catch_failures => true)
50     end
51
52     describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
53       it { should be_file }
54       it { should contain 'puppet' }
55     end
56   end
57
58   context 'update' do
59     it 'should work with no errors' do
60       pp = <<-EOS
61       include apt
62       class { 'apt::unattended_upgrades':
63         update => '99'
64       }
65       EOS
66
67       apply_manifest(pp, :catch_failures => true)
68     end
69
70     describe file('/etc/apt/apt.conf.d/10periodic') do
71       it { should be_file }
72       it { should contain 'APT::Periodic::Update-Package-Lists "99";' }
73     end
74   end
75
76   context 'download' do
77     it 'should work with no errors' do
78       pp = <<-EOS
79       include apt
80       class { 'apt::unattended_upgrades':
81         download => '99'
82       }
83       EOS
84
85       apply_manifest(pp, :catch_failures => true)
86     end
87
88     describe file('/etc/apt/apt.conf.d/10periodic') do
89       it { should be_file }
90       it { should contain 'APT::Periodic::Download-Upgradeable-Packages "99";' }
91     end
92   end
93
94   context 'upgrade' do
95     it 'should work with no errors' do
96       pp = <<-EOS
97       include apt
98       class { 'apt::unattended_upgrades':
99         upgrade => '99'
100       }
101       EOS
102
103       apply_manifest(pp, :catch_failures => true)
104     end
105
106     describe file('/etc/apt/apt.conf.d/10periodic') do
107       it { should be_file }
108       it { should contain 'APT::Periodic::Unattended-Upgrade "99";' }
109     end
110   end
111
112   context 'autoclean' do
113     it 'should work with no errors' do
114       pp = <<-EOS
115       include apt
116       class { 'apt::unattended_upgrades':
117         autoclean => '99'
118       }
119       EOS
120
121       apply_manifest(pp, :catch_failures => true)
122     end
123
124     describe file('/etc/apt/apt.conf.d/10periodic') do
125       it { should be_file }
126       it { should contain 'APT::Periodic::AutocleanInterval "99";' }
127     end
128   end
129
130   context 'auto_fix' do
131     context 'true' do
132       it 'should work with no errors' do
133         pp = <<-EOS
134         include apt
135         class { 'apt::unattended_upgrades':
136           auto_fix => true
137         }
138         EOS
139
140         apply_manifest(pp, :catch_failures => true)
141       end
142
143       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
144         it { should be_file }
145         it { should contain 'Unattended-Upgrade::AutoFixInterruptedDpkg "true";' }
146       end
147     end
148
149     context 'false' do
150       it 'should work with no errors' do
151         pp = <<-EOS
152         include apt
153         class { 'apt::unattended_upgrades':
154           auto_fix => false
155         }
156         EOS
157
158         apply_manifest(pp, :catch_failures => true)
159       end
160
161       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
162         it { should be_file }
163         it { should contain 'Unattended-Upgrade::AutoFixInterruptedDpkg "false";' }
164       end
165     end
166   end
167
168   context 'minimal_steps' do
169     context 'true' do
170       it 'should work with no errors' do
171         pp = <<-EOS
172         include apt
173         class { 'apt::unattended_upgrades':
174           minimal_steps => true
175         }
176         EOS
177
178         apply_manifest(pp, :catch_failures => true)
179       end
180
181       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
182         it { should be_file }
183         it { should contain 'Unattended-Upgrade::MinimalSteps "true";' }
184       end
185     end
186
187     context 'false' do
188       it 'should work with no errors' do
189         pp = <<-EOS
190         include apt
191         class { 'apt::unattended_upgrades':
192           minimal_steps => false
193         }
194         EOS
195
196         apply_manifest(pp, :catch_failures => true)
197       end
198
199       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
200         it { should be_file }
201         it { should contain 'Unattended-Upgrade::MinimalSteps "false";' }
202       end
203     end
204   end
205
206   context 'install_on_shutdown' do
207     context 'true' do
208       it 'should work with no errors' do
209         pp = <<-EOS
210         include apt
211         class { 'apt::unattended_upgrades':
212           install_on_shutdown => true
213         }
214         EOS
215
216         apply_manifest(pp, :catch_failures => true)
217       end
218
219       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
220         it { should be_file }
221         it { should contain 'Unattended-Upgrade::InstallOnShutdown "true";' }
222       end
223     end
224
225     context 'false' do
226       it 'should work with no errors' do
227         pp = <<-EOS
228         include apt
229         class { 'apt::unattended_upgrades':
230           install_on_shutdown => false
231         }
232         EOS
233
234         apply_manifest(pp, :catch_failures => true)
235       end
236
237       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
238         it { should be_file }
239         it { should contain 'Unattended-Upgrade::InstallOnShutdown "false";' }
240       end
241     end
242   end
243
244   context 'mail_to' do
245     it 'should work with no errors' do
246       pp = <<-EOS
247       include apt
248       class { 'apt::unattended_upgrades':
249         mail_to => 'test@example.com'
250       }
251       EOS
252
253       apply_manifest(pp, :catch_failures => true)
254     end
255
256     describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
257       it { should be_file }
258       it { should contain 'Unattended-Upgrade::Mail "test@example.com";' }
259     end
260   end
261
262   context 'mail_only_on_error' do
263     context 'true' do
264       it 'should work with no errors' do
265         pp = <<-EOS
266         include apt
267         class { 'apt::unattended_upgrades':
268           mail_to            => 'test@example.com',
269           mail_only_on_error => true
270         }
271         EOS
272
273         apply_manifest(pp, :catch_failures => true)
274       end
275
276       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
277         it { should be_file }
278         it { should contain 'Unattended-Upgrade::MailOnlyOnError "true";' }
279       end
280     end
281
282     context 'false' do
283       it 'should work with no errors' do
284         pp = <<-EOS
285         include apt
286         class { 'apt::unattended_upgrades':
287           mail_to            => 'test@example.com',
288           mail_only_on_error => false,
289         }
290         EOS
291
292         apply_manifest(pp, :catch_failures => true)
293       end
294
295       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
296         it { should be_file }
297         it { should contain 'Unattended-Upgrade::MailOnlyOnError "false";' }
298       end
299     end
300
301     context 'mail_to missing' do
302       it 'should work with no errors' do
303         pp = <<-EOS
304         include apt
305         class { 'apt::unattended_upgrades':
306           mail_only_on_error => true,
307         }
308         EOS
309
310         apply_manifest(pp, :catch_failures => true)
311       end
312
313       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
314         it { should be_file }
315         it { should_not contain 'Unattended-Upgrade::MailOnlyOnError "true";' }
316       end
317     end
318   end
319
320   context 'remove_unused' do
321     context 'true' do
322       it 'should work with no errors' do
323         pp = <<-EOS
324         include apt
325         class { 'apt::unattended_upgrades':
326           remove_unused => true
327         }
328         EOS
329
330         apply_manifest(pp, :catch_failures => true)
331       end
332
333       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
334         it { should be_file }
335         it { should contain 'Unattended-Upgrade::Remove-Unused-Dependencies "true";' }
336       end
337     end
338
339     context 'false' do
340       it 'should work with no errors' do
341         pp = <<-EOS
342         include apt
343         class { 'apt::unattended_upgrades':
344           remove_unused => false,
345         }
346         EOS
347
348         apply_manifest(pp, :catch_failures => true)
349       end
350
351       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
352         it { should be_file }
353         it { should contain 'Unattended-Upgrade::Remove-Unused-Dependencies "false";' }
354       end
355     end
356   end
357
358   context 'auto_reboot' do
359     context 'true' do
360       it 'should work with no errors' do
361         pp = <<-EOS
362         include apt
363         class { 'apt::unattended_upgrades':
364           auto_reboot => true
365         }
366         EOS
367
368         apply_manifest(pp, :catch_failures => true)
369       end
370
371       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
372         it { should be_file }
373         it { should contain 'Unattended-Upgrade::Automatic-Reboot "true";' }
374       end
375     end
376
377     context 'false' do
378       it 'should work with no errors' do
379         pp = <<-EOS
380         include apt
381         class { 'apt::unattended_upgrades':
382           auto_reboot => false,
383         }
384         EOS
385
386         apply_manifest(pp, :catch_failures => true)
387       end
388
389       describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
390         it { should be_file }
391         it { should contain 'Unattended-Upgrade::Automatic-Reboot "false";' }
392       end
393     end
394   end
395
396   context 'dl_limit' do
397     it 'should work with no errors' do
398       pp = <<-EOS
399       include apt
400       class { 'apt::unattended_upgrades':
401         dl_limit => '99'
402       }
403       EOS
404
405       apply_manifest(pp, :catch_failures => true)
406     end
407
408     describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
409       it { should be_file }
410       it { should contain 'Acquire::http::Dl-Limit "99"' }
411     end
412   end
413
414   context 'enable' do
415     it 'should work with no errors' do
416       pp = <<-EOS
417       include apt
418       class { 'apt::unattended_upgrades':
419         enable => '2'
420       }
421       EOS
422
423       apply_manifest(pp, :catch_failures => true)
424     end
425
426     describe file('/etc/apt/apt.conf.d/10periodic') do
427       it { should be_file }
428       it { should contain 'APT::Periodic::Enable "2"' }
429     end
430   end
431
432   context 'backup_interval' do
433     it 'should work with no errors' do
434       pp = <<-EOS
435       include apt
436       class { 'apt::unattended_upgrades':
437         backup_interval => '2'
438       }
439       EOS
440
441       apply_manifest(pp, :catch_failures => true)
442     end
443
444     describe file('/etc/apt/apt.conf.d/10periodic') do
445       it { should be_file }
446       it { should contain 'APT::Periodic::BackUpArchiveInterval "2";' }
447     end
448   end
449
450   context 'backup_level' do
451     it 'should work with no errors' do
452       pp = <<-EOS
453       include apt
454       class { 'apt::unattended_upgrades':
455         backup_level => '2'
456       }
457       EOS
458
459       apply_manifest(pp, :catch_failures => true)
460     end
461
462     describe file('/etc/apt/apt.conf.d/10periodic') do
463       it { should be_file }
464       it { should contain 'APT::Periodic::BackUpLevel "2";' }
465     end
466   end
467
468   context 'max_age' do
469     it 'should work with no errors' do
470       pp = <<-EOS
471       include apt
472       class { 'apt::unattended_upgrades':
473         max_age => '2'
474       }
475       EOS
476
477       apply_manifest(pp, :catch_failures => true)
478     end
479
480     describe file('/etc/apt/apt.conf.d/10periodic') do
481       it { should be_file }
482       it { should contain 'APT::Periodic::MaxAge "2";' }
483     end
484   end
485
486   context 'min_age' do
487     it 'should work with no errors' do
488       pp = <<-EOS
489       include apt
490       class { 'apt::unattended_upgrades':
491         min_age => '2'
492       }
493       EOS
494
495       apply_manifest(pp, :catch_failures => true)
496     end
497
498     describe file('/etc/apt/apt.conf.d/10periodic') do
499       it { should be_file }
500       it { should contain 'APT::Periodic::MinAge "2";' }
501     end
502   end
503
504   context 'max_size' do
505     it 'should work with no errors' do
506       pp = <<-EOS
507       include apt
508       class { 'apt::unattended_upgrades':
509         max_size => '2'
510       }
511       EOS
512
513       apply_manifest(pp, :catch_failures => true)
514     end
515
516     describe file('/etc/apt/apt.conf.d/10periodic') do
517       it { should be_file }
518       it { should contain 'APT::Periodic::MaxSize "2";' }
519     end
520   end
521
522   context 'download_delta' do
523     it 'should work with no errors' do
524       pp = <<-EOS
525       include apt
526       class { 'apt::unattended_upgrades':
527         download_delta => '2'
528       }
529       EOS
530
531       apply_manifest(pp, :catch_failures => true)
532     end
533
534     describe file('/etc/apt/apt.conf.d/10periodic') do
535       it { should be_file }
536       it { should contain 'APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";' }
537     end
538   end
539
540   context 'verbose' do
541     it 'should work with no errors' do
542       pp = <<-EOS
543       include apt
544       class { 'apt::unattended_upgrades':
545         verbose => '2'
546       }
547       EOS
548
549       apply_manifest(pp, :catch_failures => true)
550     end
551
552     describe file('/etc/apt/apt.conf.d/10periodic') do
553       it { should be_file }
554       it { should contain 'APT::Periodic::Verbose "2";' }
555     end
556   end
557
558 end