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 check_valid_until false' do
177 location: 'hello.there',
178 check_valid_until: false,
183 is_expected.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})
187 context 'with check_valid_until true' do
190 location: 'hello.there',
191 check_valid_until: true,
196 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there stretch main\n})
200 context 'with keyring set' do
203 location: 'hello.there',
204 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
209 is_expected.to contain_apt__setting('list-my_source')
210 .with(ensure: 'present')
211 .with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n})
215 context 'with keyring, architecture and allow_unsigned set' do
218 location: 'hello.there',
219 architecture: 'amd64',
220 allow_unsigned: true,
221 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
226 is_expected.to contain_apt__setting('list-my_source')
227 .with(ensure: 'present')
228 .with_content(%r{# my_source\ndeb \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n})
232 context 'with a https location, install apt-transport-https' do
235 location: 'HTTPS://foo.bar',
236 allow_unsigned: false,
241 is_expected.to contain_package('apt-transport-https')
245 context 'with a https location and custom release, install apt-transport-https' do
260 puppetversion: Puppet.version,
265 location: 'HTTPS://foo.bar',
266 allow_unsigned: false,
267 release: 'customrelease',
272 is_expected.to contain_package('apt-transport-https')
276 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
295 location: 'https://foo.bar',
296 allow_unsigned: false,
301 is_expected.not_to contain_package('apt-transport-https')
305 context 'with architecture equals x86_64' do
324 location: 'hello.there',
325 include: { 'deb' => false, 'src' => true },
326 architecture: 'x86_64',
331 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})
335 context 'with architecture fact and unset architecture parameter' do
337 super().merge(architecture: 'amd64')
341 location: 'hello.there',
342 include: { 'deb' => false, 'src' => true },
347 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there stretch main\n})
351 context 'with include_src => true' do
354 location: 'hello.there',
355 include: { 'src' => true },
360 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})
364 context 'with include deb => false' do
367 include: { 'deb' => false },
368 location: 'hello.there',
373 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
375 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
378 context 'with include src => true and include deb => false' do
381 include: { 'deb' => false, 'src' => true },
382 location: 'hello.there',
387 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there stretch main\n})
389 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there stretch main\n}) }
392 context 'with ensure => absent' do
400 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
404 describe 'validation' do
405 context 'with no release' do
421 let(:params) { { location: 'hello.there' } }
424 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
428 context 'with release is empty string' do
429 let(:params) { { location: 'hello.there', release: '' } }
431 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
434 context 'with invalid pin' do
437 location: 'hello.there',
443 is_expected.to raise_error(Puppet::Error, %r{expects a value})
447 context 'with notify_update = undef (default)' do
450 location: 'hello.there',
454 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
457 context 'with notify_update = true' do
460 location: 'hello.there',
465 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
468 context 'with notify_update = false' do
471 location: 'hello.there',
472 notify_update: false,
476 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }