3 sources_list = { ensure: 'file',
4 path: '/etc/apt/sources.list',
8 notify: 'Class[Apt::Update]' }
10 sources_list_d = { ensure: 'directory',
11 path: '/etc/apt/sources.list.d',
17 notify: 'Class[Apt::Update]' }
19 preferences = { ensure: 'file',
20 path: '/etc/apt/preferences',
24 notify: 'Class[Apt::Update]' }
26 preferences_d = { ensure: 'directory',
27 path: '/etc/apt/preferences.d',
33 notify: 'Class[Apt::Update]' }
38 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
41 lsbdistcodename: 'wheezy',
42 puppetversion: Puppet.version,
46 context 'with defaults' do
48 is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list)
52 is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d)
56 is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences)
60 is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
63 it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }
65 it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
66 is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root',
68 owner: 'root').with_content(
69 %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};},
74 is_expected.to contain_exec('apt_update').with(refreshonly: 'true')
77 it { is_expected.not_to contain_apt__setting('conf-proxy') }
81 context 'when host=localhost' do
82 let(:params) { { proxy: { 'host' => 'localhost' } } }
85 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
86 %r{Acquire::http::proxy "http://localhost:8080/";},
88 %r{Acquire::https::proxy},
93 context 'when host=localhost and port=8180' do
94 let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } }
97 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
98 %r{Acquire::http::proxy "http://localhost:8180/";},
100 %r{Acquire::https::proxy},
105 context 'when host=localhost and https=true' do
106 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } }
109 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
110 %r{Acquire::http::proxy "http://localhost:8080/";},
112 %r{Acquire::https::proxy "https://localhost:8080/";},
117 context 'when host=localhost and direct=true' do
118 let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } }
121 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
122 %r{Acquire::http::proxy "http://localhost:8080/";},
124 %r{Acquire::https::proxy "DIRECT";},
129 context 'when host=localhost and https=true and direct=true' do
130 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } }
133 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
134 %r{Acquire::http::proxy "http://localhost:8080/";},
136 %r{Acquire::https::proxy "https://localhost:8080/";},
140 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
141 %r{Acquire::http::proxy "http://localhost:8080/";},
143 %r{Acquire::https::proxy "DIRECT";},
148 context 'when ensure=absent' do
149 let(:params) { { proxy: { 'ensure' => 'absent' } } }
152 is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent',
157 context 'with lots of non-defaults' do
160 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
161 purge: { 'sources.list' => false, 'sources.list.d' => false,
162 'preferences' => false, 'preferences.d' => false },
167 is_expected.to contain_file('sources.list').with(content: nil)
171 is_expected.to contain_file('sources.list.d').with(purge: false,
176 is_expected.to contain_file('preferences').with(ensure: 'file')
180 is_expected.to contain_file('preferences.d').with(purge: false,
185 is_expected.to contain_exec('apt_update').with(refreshonly: false,
191 context 'with entries for /etc/apt/auth.conf' do
195 { machine: 'deb.example.net',
197 password: 'secret' },
198 { machine: 'apt.example.com',
200 password: 'supersecret' },
205 auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
206 machine deb.example.net login foologin password secret
207 machine apt.example.com login aptlogin password supersecret
211 is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
215 notify: 'Class[Apt::Update]',
216 content: auth_conf_content)
220 context 'with improperly specified entries for /etc/apt/auth.conf' do
224 { machinn: 'deb.example.net',
225 username: 'foologin',
226 password: 'secret' },
227 { machine: 'apt.example.com',
229 password: 'supersecret' },
234 it { is_expected.to raise_error(Puppet::Error) }
237 context 'with sources defined on valid osfamily' do
239 { os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
241 lsbdistcodename: 'xenial',
243 lsbdistrelease: '16.04',
244 puppetversion: Puppet.version }
248 'debian_unstable' => {
249 'location' => 'http://debian.mirror.iweb.ca/debian/',
250 'release' => 'unstable',
251 'repos' => 'main contrib non-free',
252 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
254 'include' => { 'src' => true },
257 'location' => 'http://apt.puppetlabs.com',
259 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' },
265 is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present')
268 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(%r{^deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free$}) }
269 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(%r{^deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free$}) }
272 is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present')
275 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com xenial main$}) }
278 context 'with confs defined on valid osfamily' do
281 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
283 lsbdistcodename: 'xenial',
285 puppetversion: Puppet.version,
300 is_expected.to contain_apt__conf('foo').with(content: 'foo')
304 is_expected.to contain_apt__conf('bar').with(content: 'bar')
308 context 'with keys defined on valid osfamily' do
311 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
313 lsbdistcodename: 'xenial',
315 puppetversion: Puppet.version,
321 'server' => 'subkeys.pgp.net',
324 'server' => 'pgp.mit.edu',
330 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
334 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
338 context 'with ppas defined on valid osfamily' do
341 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
343 lsbdistcodename: 'xenial',
345 lsbdistrelease: '16.04',
346 puppetversion: Puppet.version,
351 'ppa:drizzle-developers/ppa' => {},
352 'ppa:nginx/stable' => {},
356 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
357 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
360 context 'with settings defined on valid osfamily' do
363 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
365 lsbdistcodename: 'xenial',
367 puppetversion: Puppet.version,
372 'conf-banana' => { 'content' => 'banana' },
373 'pref-banana' => { 'content' => 'banana' },
377 it { is_expected.to contain_apt__setting('conf-banana') }
378 it { is_expected.to contain_apt__setting('pref-banana') }
381 context 'with pins defined on valid osfamily' do
384 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
386 lsbdistcodename: 'xenial',
388 puppetversion: Puppet.version,
393 'stable' => { 'priority' => 600, 'order' => 50 },
394 'testing' => { 'priority' => 700, 'order' => 100 },
398 it { is_expected.to contain_apt__pin('stable') }
399 it { is_expected.to contain_apt__pin('testing') }
402 describe 'failing tests' do
403 context "with purge['sources.list']=>'banana'" do
404 let(:params) { { purge: { 'sources.list' => 'banana' } } }
407 is_expected.to raise_error(Puppet::Error)
411 context "with purge['sources.list.d']=>'banana'" do
412 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
415 is_expected.to raise_error(Puppet::Error)
419 context "with purge['preferences']=>'banana'" do
420 let(:params) { { purge: { 'preferences' => 'banana' } } }
423 is_expected.to raise_error(Puppet::Error)
427 context "with purge['preferences.d']=>'banana'" do
428 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
431 is_expected.to raise_error(Puppet::Error)