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