84b7f88281c1f6b7deda07779220f194ef4f200d
[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(/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(/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/proxy') do
79       it { should be_file }
80       it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
81     end
82   end
83
84   context 'purge_sources' do
85     it 'creates a fake apt file' do
86       shell('touch /etc/apt/sources.list.d/fake.list')
87       shell('echo "deb fake" >> /etc/apt/sources.list')
88     end
89     it 'purge_sources_list and purge_sources_list_d => true' do
90       pp = <<-EOS
91       class { 'apt':
92         purge_sources_list   => true,
93         purge_sources_list_d => true,
94       }
95       EOS
96
97       apply_manifest(pp, :catch_failures => true)
98     end
99
100     describe file('/etc/apt/sources.list') do
101       it { should_not contain 'deb fake' }
102     end
103
104     describe file('/etc/apt/sources.list.d/fake.list') do
105       it { should_not be_file }
106     end
107   end
108   context 'proxy settings' do
109     it 'should work with no errors' do
110       pp = <<-EOS
111       class { 'apt': 
112         proxy_host => 'localhost',
113         proxy_port => '7042',
114       }
115       EOS
116
117       apply_manifest(pp, :catch_failures => true)
118     end
119
120     describe file('/etc/apt/apt.conf.d/proxy') do
121       it { should be_file }
122       it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
123     end
124   end
125
126   context 'purge_sources' do
127     context 'false' do
128       it 'creates a fake apt file' do
129         shell('touch /etc/apt/sources.list.d/fake.list')
130         shell('echo "deb fake" >> /etc/apt/sources.list')
131       end
132       it 'purge_sources_list and purge_sources_list_d => false' do
133         pp = <<-EOS
134         class { 'apt':
135           purge_sources_list   => false,
136           purge_sources_list_d => false,
137         }
138         EOS
139
140         apply_manifest(pp, :catch_failures => false)
141       end
142
143       describe file('/etc/apt/sources.list') do
144         it { should contain 'deb fake' }
145       end
146
147       describe file('/etc/apt/sources.list.d/fake.list') do
148         it { should be_file }
149       end
150     end
151
152     context 'true' do
153       it 'creates a fake apt file' do
154         shell('touch /etc/apt/sources.list.d/fake.list')
155         shell('echo "deb fake" >> /etc/apt/sources.list')
156       end
157       it 'purge_sources_list and purge_sources_list_d => true' do
158         pp = <<-EOS
159         class { 'apt':
160           purge_sources_list   => true,
161           purge_sources_list_d => true,
162         }
163         EOS
164
165         apply_manifest(pp, :catch_failures => true)
166       end
167
168       describe file('/etc/apt/sources.list') do
169         it { should_not contain 'deb fake' }
170       end
171
172       describe file('/etc/apt/sources.list.d/fake.list') do
173         it { should_not be_file }
174       end
175     end
176   end
177
178   context 'purge_preferences' do
179     context 'false' do
180       it 'creates a preferences file' do
181         shell("echo 'original' > /etc/apt/preferences")
182       end
183
184       it 'should work with no errors' do
185         pp = <<-EOS
186         class { 'apt': purge_preferences => false }
187         EOS
188
189         apply_manifest(pp, :catch_failures => true)
190       end
191
192       describe file('/etc/apt/preferences') do
193         it { should be_file }
194         it 'is not managed by Puppet' do
195           shell("grep 'original' /etc/apt/preferences", {:acceptable_exit_codes => 0})
196         end
197       end
198     end
199
200     context 'true' do
201       it 'creates a preferences file' do
202         shell('touch /etc/apt/preferences')
203       end
204
205       it 'should work with no errors' do
206         pp = <<-EOS
207         class { 'apt': purge_preferences => true }
208         EOS
209
210         apply_manifest(pp, :catch_failures => true)
211       end
212
213       describe file('/etc/apt/preferences') do
214         it { should be_file }
215         it 'is managed by Puppet' do
216           shell("grep 'Explanation' /etc/apt/preferences", {:acceptable_exit_codes => 0})
217         end
218       end
219     end
220   end
221
222   context 'purge_preferences_d' do
223     context 'false' do
224       it 'creates a preferences file' do
225         shell('touch /etc/apt/preferences.d/test')
226       end
227
228       it 'should work with no errors' do
229         pp = <<-EOS
230         class { 'apt': purge_preferences_d => false }
231         EOS
232
233         apply_manifest(pp, :catch_failures => true)
234       end
235
236       describe file('/etc/apt/preferences.d/test') do
237         it { should be_file }
238       end
239     end
240     context 'true' do
241       it 'creates a preferences file' do
242         shell('touch /etc/apt/preferences.d/test')
243       end
244
245       it 'should work with no errors' do
246         pp = <<-EOS
247         class { 'apt': purge_preferences_d => true }
248         EOS
249
250         apply_manifest(pp, :catch_failures => true)
251       end
252
253       describe file('/etc/apt/preferences.d/test') do
254         it { should_not be_file }
255       end
256     end
257   end
258
259   context 'update_timeout' do
260     context '5000' do
261       it 'should work with no errors' do
262         pp = <<-EOS
263         class { 'apt': update_timeout => '5000' }
264         EOS
265
266         apply_manifest(pp, :catch_failures => true)
267       end
268     end
269   end
270
271   context 'reset' do
272     it 'fixes the sources.list' do
273       shell('cp /tmp/sources.list /etc/apt')
274     end
275   end
276
277 end