1 # frozen_string_literal: true
5 describe 'apt::source' do
6 GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'
33 context 'with defaults' do
34 context 'without location' do
36 is_expected.to raise_error(Puppet::Error, %r{source entry without specifying a location})
39 context 'with location' do
40 let(:params) { { location: 'hello.there' } }
43 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n})
44 is_expected.not_to contain_package('apt-transport-https')
49 describe 'no defaults' do
50 context 'with complex pin' do
53 location: 'hello.there',
54 pin: { 'release' => 'wishwash',
55 'explanation' => 'wishwash',
61 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there stretch main\n})
64 it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]') }
67 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
69 explanation: 'wishwash',
74 context 'with simple key' do
78 location: 'http://debian.mirror.iweb.ca/debian/',
83 architecture: 'x86_64',
89 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
90 .without_content(%r{deb-src})
94 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
96 origin: 'debian.mirror.iweb.ca')
100 is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
105 context 'with complex key' do
109 location: 'http://debian.mirror.iweb.ca/debian/',
113 'ensure' => 'refreshed',
115 'server' => 'pgp.mit.edu',
116 'content' => 'GPG key content',
117 'source' => 'http://apt.puppetlabs.com/pubkey.gpg',
121 architecture: 'x86_64',
122 allow_unsigned: true,
127 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
128 .without_content(%r{deb-src})
132 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
134 origin: 'debian.mirror.iweb.ca')
138 is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'refreshed',
140 server: 'pgp.mit.edu',
141 content: 'GPG key content',
142 source: 'http://apt.puppetlabs.com/pubkey.gpg',
148 context 'with allow_insecure true' do
151 location: 'hello.there',
152 allow_insecure: true,
157 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[allow-insecure=yes\] hello.there stretch main\n})
161 context 'with allow_unsigned true' do
164 location: 'hello.there',
165 allow_unsigned: true,
170 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[trusted=yes\] hello.there stretch main\n})
174 context 'with keyring set' do
177 location: 'hello.there',
178 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
183 is_expected.to contain_apt__setting('list-my_source')
184 .with(ensure: 'present')
185 .with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n})
189 context 'with keyring, architecture and allow_unsigned set' do
192 location: 'hello.there',
193 architecture: 'amd64',
194 allow_unsigned: true,
195 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
200 is_expected.to contain_apt__setting('list-my_source')
201 .with(ensure: 'present')
202 .with_content(%r{# my_source\ndeb \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n})
206 context 'with a https location, install apt-transport-https' do
209 location: 'HTTPS://foo.bar',
210 allow_unsigned: false,
215 is_expected.to contain_package('apt-transport-https')
219 context 'with a https location and custom release, install apt-transport-https' do
234 puppetversion: Puppet.version,
239 location: 'HTTPS://foo.bar',
240 allow_unsigned: false,
241 release: 'customrelease',
246 is_expected.to contain_package('apt-transport-https')
250 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
269 location: 'https://foo.bar',
270 allow_unsigned: false,
275 is_expected.not_to contain_package('apt-transport-https')
279 context 'with architecture equals x86_64' do
298 location: 'hello.there',
299 include: { 'deb' => false, 'src' => true },
300 architecture: 'x86_64',
305 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src \[arch=x86_64\] hello.there wheezy main\n})
309 context 'with architecture fact and unset architecture parameter' do
311 super().merge(architecture: 'amd64')
315 location: 'hello.there',
316 include: { 'deb' => false, 'src' => true },
321 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there stretch main\n})
325 context 'with include_src => true' do
328 location: 'hello.there',
329 include: { 'src' => true },
334 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there stretch main\ndeb-src hello.there stretch main\n})
338 context 'with include deb => false' do
341 include: { 'deb' => false },
342 location: 'hello.there',
347 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
349 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
352 context 'with include src => true and include deb => false' do
355 include: { 'deb' => false, 'src' => true },
356 location: 'hello.there',
361 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there stretch main\n})
363 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there stretch main\n}) }
366 context 'with ensure => absent' do
374 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
378 describe 'validation' do
379 context 'with no release' do
395 let(:params) { { location: 'hello.there' } }
398 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
402 context 'with release is empty string' do
403 let(:params) { { location: 'hello.there', release: '' } }
405 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
408 context 'with invalid pin' do
411 location: 'hello.there',
417 is_expected.to raise_error(Puppet::Error, %r{expects a value})
421 context 'with notify_update = undef (default)' do
424 location: 'hello.there',
428 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
431 context 'with notify_update = true' do
434 location: 'hello.there',
439 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
442 context 'with notify_update = false' do
445 location: 'hello.there',
446 notify_update: false,
450 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }