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