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: 'jessie',
45 context 'with defaults' do
47 is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list)
51 is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d)
55 is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences)
59 is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
62 it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }
64 it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
65 is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root',
67 owner: 'root').with_content(
68 %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};},
73 is_expected.to contain_exec('apt_update').with(refreshonly: 'true')
76 it { is_expected.not_to contain_apt__setting('conf-proxy') }
80 context 'when host=localhost' do
81 let(:params) { { proxy: { 'host' => 'localhost' } } }
84 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
85 %r{Acquire::http::proxy "http://localhost:8080/";},
87 %r{Acquire::https::proxy},
92 context 'when host=localhost and port=8180' do
93 let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } }
96 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
97 %r{Acquire::http::proxy "http://localhost:8180/";},
99 %r{Acquire::https::proxy},
104 context 'when host=localhost and https=true' do
105 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } }
108 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
109 %r{Acquire::http::proxy "http://localhost:8080/";},
111 %r{Acquire::https::proxy "https://localhost:8080/";},
116 context 'when host=localhost and direct=true' do
117 let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } }
120 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
121 %r{Acquire::http::proxy "http://localhost:8080/";},
123 %r{Acquire::https::proxy "DIRECT";},
128 context 'when host=localhost and https=true and direct=true' do
129 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } }
132 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
133 %r{Acquire::http::proxy "http://localhost:8080/";},
135 %r{Acquire::https::proxy "https://localhost:8080/";},
139 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
140 %r{Acquire::http::proxy "http://localhost:8080/";},
142 %r{Acquire::https::proxy "DIRECT";},
147 context 'when ensure=absent' do
148 let(:params) { { proxy: { 'ensure' => 'absent' } } }
151 is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent',
156 context 'with lots of non-defaults' do
159 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
160 purge: { 'sources.list' => false, 'sources.list.d' => false,
161 'preferences' => false, 'preferences.d' => false },
166 is_expected.to contain_file('sources.list').with(content: nil)
170 is_expected.to contain_file('sources.list.d').with(purge: false,
175 is_expected.to contain_file('preferences').with(ensure: 'file')
179 is_expected.to contain_file('preferences.d').with(purge: false,
184 is_expected.to contain_exec('apt_update').with(refreshonly: false,
190 context 'with entries for /etc/apt/auth.conf' do
194 { machine: 'deb.example.net',
196 password: 'secret' },
197 { machine: 'apt.example.com',
199 password: 'supersecret' },
204 context 'with manage_auth_conf => true' do
206 super().merge(manage_auth_conf: true)
209 auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
210 machine deb.example.net login foologin password secret
211 machine apt.example.com login aptlogin password supersecret
215 is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
219 notify: 'Class[Apt::Update]',
220 content: auth_conf_content)
224 context 'with manage_auth_conf => false' do
226 super().merge(manage_auth_conf: false)
230 is_expected.not_to contain_file('/etc/apt/auth.conf')
235 context 'with improperly specified entries for /etc/apt/auth.conf' do
239 { machinn: 'deb.example.net',
240 username: 'foologin',
241 password: 'secret' },
242 { machine: 'apt.example.com',
244 password: 'supersecret' },
249 it { is_expected.to raise_error(Puppet::Error) }
252 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',
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',
315 is_expected.to contain_apt__conf('foo').with(content: 'foo')
319 is_expected.to contain_apt__conf('bar').with(content: 'bar')
323 context 'with keys defined on valid osfamily' do
326 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
328 lsbdistcodename: 'xenial',
335 'server' => 'subkeys.pgp.net',
338 'server' => 'pgp.mit.edu',
344 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
348 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
352 context 'with ppas defined on valid osfamily' do
355 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
357 lsbdistcodename: 'xenial',
359 lsbdistrelease: '16.04',
364 'ppa:drizzle-developers/ppa' => {},
365 'ppa:nginx/stable' => {},
369 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
370 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
373 context 'with settings defined on valid osfamily' do
376 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
378 lsbdistcodename: 'xenial',
384 'conf-banana' => { 'content' => 'banana' },
385 'pref-banana' => { 'content' => 'banana' },
389 it { is_expected.to contain_apt__setting('conf-banana') }
390 it { is_expected.to contain_apt__setting('pref-banana') }
393 context 'with pins defined on valid osfamily' do
396 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
398 lsbdistcodename: 'xenial',
404 'stable' => { 'priority' => 600, 'order' => 50 },
405 'testing' => { 'priority' => 700, 'order' => 100 },
409 it { is_expected.to contain_apt__pin('stable') }
410 it { is_expected.to contain_apt__pin('testing') }
413 describe 'failing tests' do
414 context "with purge['sources.list']=>'banana'" do
415 let(:params) { { purge: { 'sources.list' => 'banana' } } }
418 is_expected.to raise_error(Puppet::Error)
422 context "with purge['sources.list.d']=>'banana'" do
423 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
426 is_expected.to raise_error(Puppet::Error)
430 context "with purge['preferences']=>'banana'" do
431 let(:params) { { purge: { 'preferences' => 'banana' } } }
434 is_expected.to raise_error(Puppet::Error)
438 context "with purge['preferences.d']=>'banana'" do
439 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
442 is_expected.to raise_error(Puppet::Error)