Fix gpg key checking warings after f588f26
[puppet-modules/puppetlabs-apt.git] / spec / classes / apt_spec.rb
1 require 'spec_helper'
2 describe 'apt', :type => :class do
3   let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
4
5   context 'defaults' do
6     it { should contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
7       'ensure' => 'present',
8       'path'   => '/etc/apt/sources.list',
9       'owner'  => 'root',
10       'group'  => 'root',
11       'mode'   => '0644',
12       'notify' => 'Exec[apt_update]',
13     })}
14
15     it { should contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
16       'ensure'  => 'directory',
17       'path'    => '/etc/apt/sources.list.d',
18       'owner'   => 'root',
19       'group'   => 'root',
20       'purge'   => false,
21       'recurse' => false,
22       'notify'  => 'Exec[apt_update]',
23     })}
24
25     it { should contain_file('preferences.d').only_with({
26       'ensure'  => 'directory',
27       'path'    => '/etc/apt/preferences.d',
28       'owner'   => 'root',
29       'group'   => 'root',
30       'purge'   => false,
31       'recurse' => false,
32     })}
33
34     it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
35       'ensure' => 'absent',
36       'path'   => '/etc/apt/apt.conf.d/01proxy',
37       'notify' => 'Exec[apt_update]',
38     })}
39
40     it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
41       should contain_file('/etc/apt/apt.conf.d/15update-stamp').with({
42         'group' => 'root',
43         'mode'  => '0644',
44         'owner' => 'root',
45       }).with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/)
46     end
47
48     it { should contain_file('old-proxy-file').that_notifies('Exec[apt_update]').only_with({
49       'ensure' => 'absent',
50       'path'   => '/etc/apt/apt.conf.d/proxy',
51       'notify' => 'Exec[apt_update]',
52     })}
53
54     it { should contain_exec('apt_update').with({
55       'refreshonly' => 'true',
56     })}
57   end
58
59   context 'lots of non-defaults' do
60     let :params do
61       {
62         :always_apt_update    => true,
63         :disable_keys         => true,
64         :proxy_host           => 'foo',
65         :proxy_port           => '9876',
66         :purge_sources_list   => true,
67         :purge_sources_list_d => true,
68         :purge_preferences    => true,
69         :purge_preferences_d  => true,
70         :update_timeout       => '1',
71         :update_tries         => '3',
72         :fancy_progress       => true,
73       }
74     end
75
76     it { should contain_file('sources.list').with({
77       'content' => "# Repos managed by puppet.\n"
78     })}
79
80     it { should contain_file('sources.list.d').with({
81       'purge'   => 'true',
82       'recurse' => 'true',
83     })}
84
85     it { should contain_file('apt-preferences').only_with({
86       'ensure' => 'absent',
87       'path'   => '/etc/apt/preferences',
88     })}
89
90     it { should contain_file('preferences.d').with({
91       'purge'   => 'true',
92       'recurse' => 'true',
93     })}
94
95     it { should contain_file('99progressbar').only_with({
96       'ensure'  => 'present',
97       'content' => /Dpkg::Progress-Fancy "1";/,
98       'path'    => '/etc/apt/apt.conf.d/99progressbar',
99     })}
100
101     it { should contain_file('99unauth').only_with({
102       'ensure'  => 'present',
103       'content' => /APT::Get::AllowUnauthenticated 1;/,
104       'path'    => '/etc/apt/apt.conf.d/99unauth',
105     })}
106
107     it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
108       'ensure'  => 'present',
109       'path'    => '/etc/apt/apt.conf.d/01proxy',
110       'content' => /Acquire::http::Proxy "http:\/\/foo:9876";/,
111       'notify'  => 'Exec[apt_update]',
112       'mode'    => '0644',
113       'owner'   => 'root',
114       'group'   => 'root'
115     })}
116
117     it { should contain_exec('apt_update').with({
118       'refreshonly' => 'false',
119       'timeout'     => '1',
120       'tries'       => '3',
121     })}
122
123   end
124
125   context 'more non-default' do
126     let :params do
127       {
128         :fancy_progress => false,
129         :disable_keys   => false,
130       }
131     end
132
133     it { should contain_file('99progressbar').only_with({
134       'ensure'  => 'absent',
135       'path'    => '/etc/apt/apt.conf.d/99progressbar',
136     })}
137
138     it { should contain_file('99unauth').only_with({
139       'ensure'  => 'absent',
140       'path'    => '/etc/apt/apt.conf.d/99unauth',
141     })}
142
143   end
144
145   context 'with sources defined on valid osfamily' do
146     let :facts do
147       { :osfamily        => 'Debian',
148         :lsbdistcodename => 'precise',
149         :lsbdistid       => 'Debian',
150       }
151     end
152     let(:params) { { :sources => {
153       'debian_unstable' => {
154         'location'          => 'http://debian.mirror.iweb.ca/debian/',
155         'release'           => 'unstable',
156         'repos'             => 'main contrib non-free',
157         'required_packages' => 'debian-keyring debian-archive-keyring',
158         'key'               => '150C8614919D8446E01E83AF9AA38DCD55BE302B',
159         'key_server'        => 'subkeys.pgp.net',
160         'pin'               => '-10',
161         'include_src'       => true
162       },
163       'puppetlabs' => {
164         'location'   => 'http://apt.puppetlabs.com',
165         'repos'      => 'main',
166         'key'        => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
167         'key_server' => 'pgp.mit.edu',
168       }
169     } } }
170
171     it {
172       should contain_file('debian_unstable.list').with({
173         'ensure'  => 'present',
174         'path'    => '/etc/apt/sources.list.d/debian_unstable.list',
175         'owner'   => 'root',
176         'group'   => 'root',
177         'mode'    => '0644',
178         'notify'  => 'Exec[apt_update]',
179       })
180     }
181
182     it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
183     it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
184
185     it {
186       should contain_file('puppetlabs.list').with({
187         'ensure'  => 'present',
188         'path'    => '/etc/apt/sources.list.d/puppetlabs.list',
189         'owner'   => 'root',
190         'group'   => 'root',
191         'mode'    => '0644',
192         'notify'  => 'Exec[apt_update]',
193       })
194     }
195
196     it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
197     it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
198   end
199
200   describe 'failing tests' do
201     context 'bad purge_sources_list' do
202       let :params do
203         {
204           'purge_sources_list' => 'foo'
205         }
206       end
207       it do
208         expect {
209           should compile
210         }.to raise_error(Puppet::Error)
211       end
212     end
213
214     context 'bad purge_sources_list_d' do
215       let :params do
216         {
217           'purge_sources_list_d' => 'foo'
218         }
219       end
220       it do
221         expect {
222           should compile
223         }.to raise_error(Puppet::Error)
224       end
225     end
226
227     context 'bad purge_preferences' do
228       let :params do
229         {
230           'purge_preferences' => 'foo'
231         }
232       end
233       it do
234         expect {
235           should compile
236         }.to raise_error(Puppet::Error)
237       end
238     end
239
240     context 'bad purge_preferences_d' do
241       let :params do
242         {
243           'purge_preferences_d' => 'foo'
244         }
245       end
246       it do
247         expect {
248           should compile
249         }.to raise_error(Puppet::Error)
250       end
251     end
252
253     context 'with unsupported osfamily' do
254       let :facts do
255         { :osfamily => 'Darwin', }
256       end
257
258       it do
259         expect {
260           should compile
261         }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
262       end
263     end
264   end
265 end