1 require 'spec_helper_acceptance'
3 describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
6 it 'fixes the sources.list' do
7 shell('cp /etc/apt/sources.list /tmp')
11 context 'always_apt_update => true' do
12 it 'should work with no errors' do
14 class { 'apt': always_apt_update => true }
17 apply_manifest(pp, :catch_failures => true) do |r|
18 expect(r.stdout).to match(/Exec\[apt_update\]/)
22 context 'always_apt_update => false' do
23 it 'should work with no errors' do
25 class { 'apt': always_apt_update => false }
28 apply_manifest(pp, :catch_failures => true) do |r|
29 expect(r.stdout).to_not match(/Exec\[apt_update\]/)
34 # disable_keys drops in a 99unauth file to ignore keys in
36 context 'disable_keys => true' do
37 it 'should work with no errors' do
39 class { 'apt': disable_keys => true }
42 apply_manifest(pp, :catch_failures => true)
45 describe file('/etc/apt/apt.conf.d/99unauth') do
47 it { should contain 'APT::Get::AllowUnauthenticated 1;' }
50 context 'disable_keys => false' do
51 it 'should work with no errors' do
53 class { 'apt': disable_keys => false }
56 apply_manifest(pp, :catch_failures => true)
59 describe file('/etc/apt/apt.conf.d/99unauth') do
60 it { should_not be_file }
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
70 proxy_host => 'localhost',
75 apply_manifest(pp, :catch_failures => true)
78 describe file('/etc/apt/apt.conf.d/01proxy') do
80 it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
82 describe file('/etc/apt/apt.conf.d/proxy') do
83 it { should_not be_file }
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')
92 it 'purge_sources_list and purge_sources_list_d => true' do
95 purge_sources_list => true,
96 purge_sources_list_d => true,
100 apply_manifest(pp, :catch_failures => true)
103 describe file('/etc/apt/sources.list') do
104 it { should_not contain 'deb fake' }
107 describe file('/etc/apt/sources.list.d/fake.list') do
108 it { should_not be_file }
111 context 'proxy settings' do
112 it 'should work with no errors' do
115 proxy_host => 'localhost',
116 proxy_port => '7042',
120 apply_manifest(pp, :catch_failures => true)
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\";' }
127 describe file('/etc/apt/apt.conf.d/proxy') do
128 it { should_not be_file }
132 context 'purge_sources' 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')
138 it 'purge_sources_list and purge_sources_list_d => false' do
141 purge_sources_list => false,
142 purge_sources_list_d => false,
146 apply_manifest(pp, :catch_failures => false)
149 describe file('/etc/apt/sources.list') do
150 it { should contain 'deb fake' }
153 describe file('/etc/apt/sources.list.d/fake.list') do
154 it { should be_file }
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')
163 it 'purge_sources_list and purge_sources_list_d => true' do
166 purge_sources_list => true,
167 purge_sources_list_d => true,
171 apply_manifest(pp, :catch_failures => true)
174 describe file('/etc/apt/sources.list') do
175 it { should_not contain 'deb fake' }
178 describe file('/etc/apt/sources.list.d/fake.list') do
179 it { should_not be_file }
184 context 'purge_preferences' do
186 it 'creates a preferences file' do
187 shell("echo 'original' > /etc/apt/preferences")
190 it 'should work with no errors' do
192 class { 'apt': purge_preferences => false }
195 apply_manifest(pp, :catch_failures => true)
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})
207 it 'creates a preferences file' do
208 shell('touch /etc/apt/preferences')
211 it 'should work with no errors' do
213 class { 'apt': purge_preferences => true }
216 apply_manifest(pp, :catch_failures => true)
219 describe file('/etc/apt/preferences') do
220 it { should_not be_file }
225 context 'purge_preferences_d' do
227 it 'creates a preferences file' do
228 shell('touch /etc/apt/preferences.d/test')
231 it 'should work with no errors' do
233 class { 'apt': purge_preferences_d => false }
236 apply_manifest(pp, :catch_failures => true)
239 describe file('/etc/apt/preferences.d/test') do
240 it { should be_file }
244 it 'creates a preferences file' do
245 shell('touch /etc/apt/preferences.d/test')
248 it 'should work with no errors' do
250 class { 'apt': purge_preferences_d => true }
253 apply_manifest(pp, :catch_failures => true)
256 describe file('/etc/apt/preferences.d/test') do
257 it { should_not be_file }
262 context 'update_timeout' do
264 it 'should work with no errors' do
266 class { 'apt': update_timeout => '5000' }
269 apply_manifest(pp, :catch_failures => true)
274 context 'fancy_progress => true' do
275 it 'should work with no errors' do
277 class { 'apt': fancy_progress => true }
280 apply_manifest(pp, :catch_failures => true)
283 describe file('/etc/apt/apt.conf.d/99progressbar') do
284 it { should be_file }
285 it { should contain 'Dpkg::Progress-Fancy "1";' }
288 context 'fancy_progress => false' do
289 it 'should work with no errors' do
291 class { 'apt': fancy_progress => false }
294 apply_manifest(pp, :catch_failures => true)
297 describe file('/etc/apt/apt.conf.d/99progressbar') do
298 it { should_not be_file }
303 it 'fixes the sources.list' do
304 shell('cp /tmp/sources.list /etc/apt')