]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/blob - spec/classes/unattended_upgrades_spec.rb
[#153] Variablise file paths in unattended spec
[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 "with origins => ['ubuntu:precise-security']" do
25     let :params do
26       { :origins => ['ubuntu:precise-security'] }
27     end
28     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"ubuntu:precise-security";\n\};$/) }
29   end
30   
31   describe "with blacklist => []" do
32     let :params do
33       { :blacklist => [] }
34     end
35     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
36   end
37   
38   describe "with update => 2" do
39     let :params do
40       { :update => "2" }
41     end
42     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
43   end
44   
45   describe "with download => 2" do
46     let :params do
47       { :download => "2" }
48     end
49     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
50   end
51   
52   describe "with upgrade => 2" do
53     let :params do
54       { :upgrade => "2" }
55     end
56     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
57   end
58   
59   describe "with autoclean => 2" do
60     let :params do
61       { :autoclean => "2" }
62     end
63     it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
64   end
65   
66   describe "with auto_fix => false" do
67     let :params do
68       { :auto_fix => false }
69     end
70     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
71   end
72   
73   describe "with minimal_steps => true" do
74     let :params do
75       { :minimal_steps => true }
76     end
77     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
78   end
79   
80   describe "with install_on_shutdown => true" do
81     let :params do
82       { :install_on_shutdown => true }
83     end
84     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
85   end
86   
87   describe "with mail_to => NONE" do
88     let :params do
89       { :mail_to => "NONE" }
90     end
91     it { should contain_file(file_unattended).with_content(/^\/\/ 'mailx' must be installed.\n$/) }
92     it { should contain_file(file_unattended).with_content(/^\/\/ is to always send a mail if Unattended-Upgrade::Mail is set\n$/) }
93   end
94   
95   describe "with mail_to => user@website, mail_only_on_error => true" do
96     let :params do
97       { :mail_to => "user@website",
98         :mail_only_on_error => true }
99     end
100     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
101     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
102   end
103   
104   describe "with remove_unused => false" do
105     let :params do
106       { :remove_unused => false }
107     end
108     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
109   end
110   
111   describe "with auto_reboot => true" do
112     let :params do
113       { :auto_reboot => true }
114     end
115     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
116   end
117   
118   describe "with dl_limit => 70" do
119     let :params do
120       { :dl_limit => "70" }
121     end
122     it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
123   end
124   
125   describe "with enable => 0" do
126     let :params do
127       { :enable => "0" }
128     end
129     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
130   end
131   
132   describe "with backup_interval => 1" do
133     let :params do
134       { :backup_interval => "1" }
135     end
136     it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
137   end
138   
139   describe "with backup_level => 0" do
140     let :params do
141       { :backup_level => "0" }
142     end
143     it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
144   end
145   
146   describe "with max_age => 1" do
147     let :params do
148       { :max_age => "1" }
149     end
150     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
151   end
152   
153   describe "with min_age => 1" do
154     let :params do
155       { :min_age => "1" }
156     end
157     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
158   end
159   
160   describe "with max_size => 1" do
161     let :params do
162       { :max_size => "1" }
163     end
164     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
165   end
166   
167   describe "with download_delta => 2" do
168     let :params do
169       { :download_delta => "2" }
170     end
171     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
172   end
173   
174   describe "with verbose => 2" do
175     let :params do
176       { :verbose => "2" }
177     end
178     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
179   end
180   
181 end