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: '8', full: '8.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 context 'with manage_auth_conf => true' do
207 super().merge(manage_auth_conf: true)
210 auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
211 machine deb.example.net login foologin password secret
212 machine apt.example.com login aptlogin password supersecret
216 is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
220 notify: 'Class[Apt::Update]',
221 content: auth_conf_content)
225 context 'with manage_auth_conf => false' do
227 super().merge(manage_auth_conf: false)
231 is_expected.not_to contain_file('/etc/apt/auth.conf')
236 context 'with improperly specified entries for /etc/apt/auth.conf' do
240 { machinn: 'deb.example.net',
241 username: 'foologin',
242 password: 'secret' },
243 { machine: 'apt.example.com',
245 password: 'supersecret' },
250 it { is_expected.to raise_error(Puppet::Error) }
253 context 'with sources defined on valid osfamily' do
255 { os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
257 lsbdistcodename: 'xenial',
259 lsbdistrelease: '16.04',
260 puppetversion: Puppet.version }
264 'debian_unstable' => {
265 'location' => 'http://debian.mirror.iweb.ca/debian/',
266 'release' => 'unstable',
267 'repos' => 'main contrib non-free',
268 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
270 'include' => { 'src' => true },
273 'location' => 'http://apt.puppetlabs.com',
275 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' },
281 is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present')
284 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$}) }
285 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$}) }
288 is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present')
291 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com xenial main$}) }
294 context 'with confs defined on valid osfamily' do
297 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
299 lsbdistcodename: 'xenial',
301 puppetversion: Puppet.version,
316 is_expected.to contain_apt__conf('foo').with(content: 'foo')
320 is_expected.to contain_apt__conf('bar').with(content: 'bar')
324 context 'with keys defined on valid osfamily' do
327 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
329 lsbdistcodename: 'xenial',
331 puppetversion: Puppet.version,
337 'server' => 'subkeys.pgp.net',
340 'server' => 'pgp.mit.edu',
346 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
350 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
354 context 'with ppas defined on valid osfamily' do
357 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
359 lsbdistcodename: 'xenial',
361 lsbdistrelease: '16.04',
362 puppetversion: Puppet.version,
367 'ppa:drizzle-developers/ppa' => {},
368 'ppa:nginx/stable' => {},
372 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
373 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
376 context 'with settings defined on valid osfamily' do
379 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
381 lsbdistcodename: 'xenial',
383 puppetversion: Puppet.version,
388 'conf-banana' => { 'content' => 'banana' },
389 'pref-banana' => { 'content' => 'banana' },
393 it { is_expected.to contain_apt__setting('conf-banana') }
394 it { is_expected.to contain_apt__setting('pref-banana') }
397 context 'with pins defined on valid osfamily' do
400 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
402 lsbdistcodename: 'xenial',
404 puppetversion: Puppet.version,
409 'stable' => { 'priority' => 600, 'order' => 50 },
410 'testing' => { 'priority' => 700, 'order' => 100 },
414 it { is_expected.to contain_apt__pin('stable') }
415 it { is_expected.to contain_apt__pin('testing') }
418 describe 'failing tests' do
419 context "with purge['sources.list']=>'banana'" do
420 let(:params) { { purge: { 'sources.list' => 'banana' } } }
423 is_expected.to raise_error(Puppet::Error)
427 context "with purge['sources.list.d']=>'banana'" do
428 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
431 is_expected.to raise_error(Puppet::Error)
435 context "with purge['preferences']=>'banana'" do
436 let(:params) { { purge: { 'preferences' => 'banana' } } }
439 is_expected.to raise_error(Puppet::Error)
443 context "with purge['preferences.d']=>'banana'" do
444 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
447 is_expected.to raise_error(Puppet::Error)