e33f7a0470254ccb30570698ef58e68f362d85e3
[puppet-modules/puppetlabs-apt.git] / spec / classes / unattended_upgrades_spec.rb
1 require 'spec_helper'
2 describe 'apt::unattended_upgrades', :type => :class do
3   let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
4   let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
5
6   it { should contain_package("unattended-upgrades") }
7
8   it { 
9     should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({
10       "owner"   => "root",
11       "group"   => "root",
12       "mode"    => "0644",
13     })
14   }
15   
16   it { 
17     should create_file("/etc/apt/apt.conf.d/10periodic").with({
18       "owner"   => "root",
19       "group"   => "root",
20       "mode"    => "0644",
21     })
22   }
23
24   describe "origins" do
25     describe "with param defaults" do
26       let(:params) {{ }}
27       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"\${distro_id}:\${distro_codename}-security";\n\};$/) }
28     end
29
30     describe "with origins => ['ubuntu:precise-security']" do
31       let :params do
32         { :origins => ['ubuntu:precise-security'] }
33       end
34       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"ubuntu:precise-security";\n\};$/) }
35     end
36   end
37   
38   describe "blacklist" do
39     describe "with param defaults" do
40       let(:params) {{ }}
41       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
42     end
43
44     describe "with blacklist => []" do
45       let :params do
46         { :blacklist => ['libc6', 'libc6-dev'] }
47       end
48       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
49     end
50   end
51   
52   describe "with update => 2" do
53     let :params do
54       { :update => "2" }
55     end
56     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
57   end
58   
59   describe "with download => 2" do
60     let :params do
61       { :download => "2" }
62     end
63     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
64   end
65   
66   describe "with upgrade => 2" do
67     let :params do
68       { :upgrade => "2" }
69     end
70     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
71   end
72   
73   describe "with autoclean => 2" do
74     let :params do
75       { :autoclean => "2" }
76     end
77     it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
78   end
79   
80   describe "with auto_fix => false" do
81     let :params do
82       { :auto_fix => false }
83     end
84     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
85   end
86   
87   describe "with minimal_steps => true" do
88     let :params do
89       { :minimal_steps => true }
90     end
91     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
92   end
93   
94   describe "with install_on_shutdown => true" do
95     let :params do
96       { :install_on_shutdown => true }
97     end
98     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
99   end
100   
101   describe "mail_to" do
102     describe "param defaults" do
103       let(:params) {{ }}
104       it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
105       it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
106     end
107
108     describe "with mail_to => user@website, mail_only_on_error => true" do
109       let :params do
110         { :mail_to => "user@website",
111           :mail_only_on_error => true }
112       end
113       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
114       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
115     end
116   end
117   
118   describe "with remove_unused => false" do
119     let :params do
120       { :remove_unused => false }
121     end
122     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
123   end
124   
125   describe "with auto_reboot => true" do
126     let :params do
127       { :auto_reboot => true }
128     end
129     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
130   end
131   
132   describe "dl_limit" do
133     describe "param defaults" do
134       let(:params) {{ }}
135       it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
136     end
137
138     describe "with dl_limit => 70" do
139       let :params do
140         { :dl_limit => "70" }
141       end
142       it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
143     end
144   end
145   
146   describe "with enable => 0" do
147     let :params do
148       { :enable => "0" }
149     end
150     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
151   end
152   
153   describe "with backup_interval => 1" do
154     let :params do
155       { :backup_interval => "1" }
156     end
157     it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
158   end
159   
160   describe "with backup_level => 0" do
161     let :params do
162       { :backup_level => "0" }
163     end
164     it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
165   end
166   
167   describe "with max_age => 1" do
168     let :params do
169       { :max_age => "1" }
170     end
171     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
172   end
173   
174   describe "with min_age => 1" do
175     let :params do
176       { :min_age => "1" }
177     end
178     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
179   end
180   
181   describe "with max_size => 1" do
182     let :params do
183       { :max_size => "1" }
184     end
185     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
186   end
187   
188   describe "with download_delta => 2" do
189     let :params do
190       { :download_delta => "2" }
191     end
192     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
193   end
194   
195   describe "with verbose => 2" do
196     let :params do
197       { :verbose => "2" }
198     end
199     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
200   end
201   
202 end