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