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(/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(/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/proxy') do
80 it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
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')
89 it 'purge_sources_list and purge_sources_list_d => true' do
92 purge_sources_list => true,
93 purge_sources_list_d => true,
97 apply_manifest(pp, :catch_failures => true)
100 describe file('/etc/apt/sources.list') do
101 it { should_not contain 'deb fake' }
104 describe file('/etc/apt/sources.list.d/fake.list') do
105 it { should_not be_file }
108 context 'proxy settings' do
109 it 'should work with no errors' do
112 proxy_host => 'localhost',
113 proxy_port => '7042',
117 apply_manifest(pp, :catch_failures => true)
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\";' }
126 context 'purge_sources' 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')
132 it 'purge_sources_list and purge_sources_list_d => false' do
135 purge_sources_list => false,
136 purge_sources_list_d => false,
140 apply_manifest(pp, :catch_failures => false)
143 describe file('/etc/apt/sources.list') do
144 it { should contain 'deb fake' }
147 describe file('/etc/apt/sources.list.d/fake.list') do
148 it { should be_file }
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')
157 it 'purge_sources_list and purge_sources_list_d => true' do
160 purge_sources_list => true,
161 purge_sources_list_d => true,
165 apply_manifest(pp, :catch_failures => true)
168 describe file('/etc/apt/sources.list') do
169 it { should_not contain 'deb fake' }
172 describe file('/etc/apt/sources.list.d/fake.list') do
173 it { should_not be_file }
178 context 'purge_preferences' do
180 it 'creates a preferences file' do
181 shell("echo 'original' > /etc/apt/preferences")
184 it 'should work with no errors' do
186 class { 'apt': purge_preferences => false }
189 apply_manifest(pp, :catch_failures => true)
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})
201 it 'creates a preferences file' do
202 shell('touch /etc/apt/preferences')
205 it 'should work with no errors' do
207 class { 'apt': purge_preferences => true }
210 apply_manifest(pp, :catch_failures => true)
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})
222 context 'purge_preferences_d' do
224 it 'creates a preferences file' do
225 shell('touch /etc/apt/preferences.d/test')
228 it 'should work with no errors' do
230 class { 'apt': purge_preferences_d => false }
233 apply_manifest(pp, :catch_failures => true)
236 describe file('/etc/apt/preferences.d/test') do
237 it { should be_file }
241 it 'creates a preferences file' do
242 shell('touch /etc/apt/preferences.d/test')
245 it 'should work with no errors' do
247 class { 'apt': purge_preferences_d => true }
250 apply_manifest(pp, :catch_failures => true)
253 describe file('/etc/apt/preferences.d/test') do
254 it { should_not be_file }
259 context 'update_timeout' do
261 it 'should work with no errors' do
263 class { 'apt': update_timeout => '5000' }
266 apply_manifest(pp, :catch_failures => true)
272 it 'fixes the sources.list' do
273 shell('cp /tmp/sources.list /etc/apt')