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 expect(subject).to raise_error(Puppet::Error, %r{source entry without specifying a location})
40 context 'with location' do
41 let(:params) { { location: 'hello.there' } }
44 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n})
45 expect(subject).not_to contain_package('apt-transport-https')
50 describe 'no defaults' do
51 context 'with complex pin' do
54 location: 'hello.there',
55 pin: { 'release' => 'wishwash',
56 'explanation' => 'wishwash',
62 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there stretch main\n})
65 it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]') }
68 expect(subject).to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
70 explanation: 'wishwash',
75 context 'with simple key' do
79 location: 'http://debian.mirror.iweb.ca/debian/',
84 architecture: 'x86_64',
90 expect(subject).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})
91 .without_content(%r{deb-src})
95 expect(subject).to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
97 origin: 'debian.mirror.iweb.ca')
101 expect(subject).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',
106 context 'with complex key' do
110 location: 'http://debian.mirror.iweb.ca/debian/',
114 'ensure' => 'refreshed',
116 'server' => 'pgp.mit.edu',
117 'content' => 'GPG key content',
118 'source' => 'http://apt.puppetlabs.com/pubkey.gpg',
122 architecture: 'x86_64',
123 allow_unsigned: true,
128 expect(subject).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})
129 .without_content(%r{deb-src})
133 expect(subject).to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
135 origin: 'debian.mirror.iweb.ca')
139 expect(subject).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',
141 server: 'pgp.mit.edu',
142 content: 'GPG key content',
143 source: 'http://apt.puppetlabs.com/pubkey.gpg',
149 context 'with allow_insecure true' do
152 location: 'hello.there',
153 allow_insecure: true,
158 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[allow-insecure=yes\] hello.there stretch main\n})
162 context 'with allow_unsigned true' do
165 location: 'hello.there',
166 allow_unsigned: true,
171 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[trusted=yes\] hello.there stretch main\n})
175 context 'with check_valid_until false' do
178 location: 'hello.there',
179 check_valid_until: false,
184 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[check-valid-until=false\] hello.there stretch main\n})
188 context 'with check_valid_until true' do
191 location: 'hello.there',
192 check_valid_until: true,
197 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there stretch main\n})
201 context 'with keyring set' do
204 location: 'hello.there',
205 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
210 expect(subject).to contain_apt__setting('list-my_source')
211 .with(ensure: 'present')
212 .with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n})
216 context 'with keyring, architecture and allow_unsigned set' do
219 location: 'hello.there',
220 architecture: 'amd64',
221 allow_unsigned: true,
222 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
227 expect(subject).to contain_apt__setting('list-my_source')
228 .with(ensure: 'present')
229 .with_content(%r{# my_source\ndeb \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n})
233 context 'with a https location, install apt-transport-https' do
236 location: 'HTTPS://foo.bar',
237 allow_unsigned: false,
242 expect(subject).to contain_package('apt-transport-https')
246 context 'with a https location and custom release, install apt-transport-https' do
261 puppetversion: Puppet.version,
266 location: 'HTTPS://foo.bar',
267 allow_unsigned: false,
268 release: 'customrelease',
273 expect(subject).to contain_package('apt-transport-https')
277 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
296 location: 'https://foo.bar',
297 allow_unsigned: false,
302 expect(subject).not_to contain_package('apt-transport-https')
306 context 'with architecture equals x86_64' do
325 location: 'hello.there',
326 include: { 'deb' => false, 'src' => true },
327 architecture: 'x86_64',
332 expect(subject).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})
336 context 'with architecture fact and unset architecture parameter' do
338 super().merge(architecture: 'amd64')
342 location: 'hello.there',
343 include: { 'deb' => false, 'src' => true },
348 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there stretch main\n})
352 context 'with include_src => true' do
355 location: 'hello.there',
356 include: { 'src' => true },
361 expect(subject).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})
365 context 'with include deb => false' do
368 include: { 'deb' => false },
369 location: 'hello.there',
374 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
377 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
380 context 'with include src => true and include deb => false' do
383 include: { 'deb' => false, 'src' => true },
384 location: 'hello.there',
389 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there stretch main\n})
392 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there stretch main\n}) }
395 context 'with ensure => absent' do
403 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'absent')
407 describe 'validation' do
408 context 'with no release' do
424 let(:params) { { location: 'hello.there' } }
427 expect(subject).to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
431 context 'with release is empty string' do
432 let(:params) { { location: 'hello.there', release: '' } }
434 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
437 context 'with invalid pin' do
440 location: 'hello.there',
446 expect(subject).to raise_error(Puppet::Error, %r{expects a value})
450 context 'with notify_update = undef (default)' do
453 location: 'hello.there',
457 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
460 context 'with notify_update = true' do
463 location: 'hello.there',
468 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
471 context 'with notify_update = false' do
474 location: 'hello.there',
475 notify_update: false,
479 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }