Fix broken acceptance tests.
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / apt_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4
5   context 'reset' do
6     it 'fixes the sources.list' do
7       shell('cp /etc/apt/sources.list /tmp')
8     end
9   end
10
11   context 'always_apt_update => true' do
12     it 'should work with no errors' do
13       pp = <<-EOS
14       class { 'apt': always_apt_update => true }
15       EOS
16
17       apply_manifest(pp, :catch_failures => true) do |r|
18         expect(r.stdout).to match(/Exec\[apt_update\]/)
19       end
20     end
21   end
22   context 'always_apt_update => false' do
23     it 'should work with no errors' do
24       pp = <<-EOS
25       class { 'apt': always_apt_update => false }
26       EOS
27
28       apply_manifest(pp, :catch_failures => true) do |r|
29         expect(r.stdout).to_not match(/Exec\[apt_update\]/)
30       end
31     end
32   end
33
34   # disable_keys drops in a 99unauth file to ignore keys in
35   # other files.
36   context 'disable_keys => true' do
37     it 'should work with no errors' do
38       pp = <<-EOS
39       class { 'apt': disable_keys => true }
40       EOS
41
42       apply_manifest(pp, :catch_failures => true)
43     end
44
45     describe file('/etc/apt/apt.conf.d/99unauth') do
46       it { should be_file }
47       it { should contain 'APT::Get::AllowUnauthenticated 1;' }
48     end
49   end
50   context 'disable_keys => false' do
51     it 'should work with no errors' do
52       pp = <<-EOS
53       class { 'apt': disable_keys => false }
54       EOS
55
56       apply_manifest(pp, :catch_failures => true)
57     end
58
59     describe file('/etc/apt/apt.conf.d/99unauth') do
60       it { should_not be_file }
61     end
62   end
63
64   # proxy_host sets the proxy to use for transfers.
65   # proxy_port sets the proxy port to use.
66   context 'proxy settings' do
67     it 'should work with no errors' do
68       pp = <<-EOS
69       class { 'apt': 
70         proxy_host => 'localhost',
71         proxy_port => '7042',
72       }
73       EOS
74
75       apply_manifest(pp, :catch_failures => true)
76     end
77
78     describe file('/etc/apt/apt.conf.d/01proxy') do
79       it { should be_file }
80       it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
81     end
82     describe file('/etc/apt/apt.conf.d/proxy') do
83       it { should_not be_file }
84     end
85   end
86
87   context 'purge_sources' do
88     it 'creates a fake apt file' do
89       shell('touch /etc/apt/sources.list.d/fake.list')
90       shell('echo "deb fake" >> /etc/apt/sources.list')
91     end
92     it 'purge_sources_list and purge_sources_list_d => true' do
93       pp = <<-EOS
94       class { 'apt':
95         purge_sources_list   => true,
96         purge_sources_list_d => true,
97       }
98       EOS
99
100       apply_manifest(pp, :catch_failures => true)
101     end
102
103     describe file('/etc/apt/sources.list') do
104       it { should_not contain 'deb fake' }
105     end
106
107     describe file('/etc/apt/sources.list.d/fake.list') do
108       it { should_not be_file }
109     end
110   end
111   context 'proxy settings' do
112     it 'should work with no errors' do
113       pp = <<-EOS
114       class { 'apt': 
115         proxy_host => 'localhost',
116         proxy_port => '7042',
117       }
118       EOS
119
120       apply_manifest(pp, :catch_failures => true)
121     end
122
123     describe file('/etc/apt/apt.conf.d/01proxy') do
124       it { should be_file }
125       it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
126     end
127     describe file('/etc/apt/apt.conf.d/proxy') do
128       it { should_not be_file }
129     end
130   end
131
132   context 'purge_sources' do
133     context 'false' do
134       it 'creates a fake apt file' do
135         shell('touch /etc/apt/sources.list.d/fake.list')
136         shell('echo "deb fake" >> /etc/apt/sources.list')
137       end
138       it 'purge_sources_list and purge_sources_list_d => false' do
139         pp = <<-EOS
140         class { 'apt':
141           purge_sources_list   => false,
142           purge_sources_list_d => false,
143         }
144         EOS
145
146         apply_manifest(pp, :catch_failures => false)
147       end
148
149       describe file('/etc/apt/sources.list') do
150         it { should contain 'deb fake' }
151       end
152
153       describe file('/etc/apt/sources.list.d/fake.list') do
154         it { should be_file }
155       end
156     end
157
158     context 'true' do
159       it 'creates a fake apt file' do
160         shell('touch /etc/apt/sources.list.d/fake.list')
161         shell('echo "deb fake" >> /etc/apt/sources.list')
162       end
163       it 'purge_sources_list and purge_sources_list_d => true' do
164         pp = <<-EOS
165         class { 'apt':
166           purge_sources_list   => true,
167           purge_sources_list_d => true,
168         }
169         EOS
170
171         apply_manifest(pp, :catch_failures => true)
172       end
173
174       describe file('/etc/apt/sources.list') do
175         it { should_not contain 'deb fake' }
176       end
177
178       describe file('/etc/apt/sources.list.d/fake.list') do
179         it { should_not be_file }
180       end
181     end
182   end
183
184   context 'purge_preferences' do
185     context 'false' do
186       it 'creates a preferences file' do
187         shell("echo 'original' > /etc/apt/preferences")
188       end
189
190       it 'should work with no errors' do
191         pp = <<-EOS
192         class { 'apt': purge_preferences => false }
193         EOS
194
195         apply_manifest(pp, :catch_failures => true)
196       end
197
198       describe file('/etc/apt/preferences') do
199         it { should be_file }
200         it 'is not managed by Puppet' do
201           shell("grep 'original' /etc/apt/preferences", {:acceptable_exit_codes => 0})
202         end
203       end
204     end
205
206     context 'true' do
207       it 'creates a preferences file' do
208         shell('touch /etc/apt/preferences')
209       end
210
211       it 'should work with no errors' do
212         pp = <<-EOS
213         class { 'apt': purge_preferences => true }
214         EOS
215
216         apply_manifest(pp, :catch_failures => true)
217       end
218
219       describe file('/etc/apt/preferences') do
220         it { should_not be_file }
221       end
222     end
223   end
224
225   context 'purge_preferences_d' do
226     context 'false' do
227       it 'creates a preferences file' do
228         shell('touch /etc/apt/preferences.d/test')
229       end
230
231       it 'should work with no errors' do
232         pp = <<-EOS
233         class { 'apt': purge_preferences_d => false }
234         EOS
235
236         apply_manifest(pp, :catch_failures => true)
237       end
238
239       describe file('/etc/apt/preferences.d/test') do
240         it { should be_file }
241       end
242     end
243     context 'true' do
244       it 'creates a preferences file' do
245         shell('touch /etc/apt/preferences.d/test')
246       end
247
248       it 'should work with no errors' do
249         pp = <<-EOS
250         class { 'apt': purge_preferences_d => true }
251         EOS
252
253         apply_manifest(pp, :catch_failures => true)
254       end
255
256       describe file('/etc/apt/preferences.d/test') do
257         it { should_not be_file }
258       end
259     end
260   end
261
262   context 'update_timeout' do
263     context '5000' do
264       it 'should work with no errors' do
265         pp = <<-EOS
266         class { 'apt': update_timeout => '5000' }
267         EOS
268
269         apply_manifest(pp, :catch_failures => true)
270       end
271     end
272   end
273
274   context 'fancy_progress => true' do
275     it 'should work with no errors' do
276       pp = <<-EOS
277       class { 'apt': fancy_progress => true }
278       EOS
279
280       apply_manifest(pp, :catch_failures => true)
281     end
282
283     describe file('/etc/apt/apt.conf.d/99progressbar') do
284       it { should be_file }
285       it { should contain 'Dpkg::Progress-Fancy "1";' }
286     end
287   end
288   context 'fancy_progress => false' do
289     it 'should work with no errors' do
290       pp = <<-EOS
291       class { 'apt': fancy_progress => false }
292       EOS
293
294       apply_manifest(pp, :catch_failures => true)
295     end
296
297     describe file('/etc/apt/apt.conf.d/99progressbar') do
298       it { should_not be_file }
299     end
300   end
301
302   context 'reset' do
303     it 'fixes the sources.list' do
304       shell('cp /tmp/sources.list /etc/apt')
305     end
306   end
307
308 end