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