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 jessie 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_unsigned true' do
151 location: 'hello.there',
152 allow_unsigned: true,
157 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[trusted=yes\] hello.there jessie main\n})
161 context 'with keyring set' do
164 location: 'hello.there',
165 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
170 is_expected.to contain_apt__setting('list-my_source')
171 .with(ensure: 'present')
172 .with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there jessie main\n})
176 context 'with keyring, architecture and allow_unsigned set' do
179 location: 'hello.there',
180 architecture: 'amd64',
181 allow_unsigned: true,
182 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
187 is_expected.to contain_apt__setting('list-my_source')
188 .with(ensure: 'present')
189 .with_content(%r{# my_source\ndeb \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there jessie main\n})
193 context 'with a https location, install apt-transport-https' do
196 location: 'HTTPS://foo.bar',
197 allow_unsigned: false,
202 is_expected.to contain_package('apt-transport-https')
206 context 'with a https location and custom release, install apt-transport-https' do
221 puppetversion: Puppet.version,
226 location: 'HTTPS://foo.bar',
227 allow_unsigned: false,
228 release: 'customrelease',
233 is_expected.to contain_package('apt-transport-https')
237 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
256 location: 'https://foo.bar',
257 allow_unsigned: false,
262 is_expected.not_to contain_package('apt-transport-https')
266 context 'with architecture equals x86_64' do
285 location: 'hello.there',
286 include: { 'deb' => false, 'src' => true },
287 architecture: 'x86_64',
292 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})
296 context 'with architecture fact and unset architecture parameter' do
298 super().merge(architecture: 'amd64')
302 location: 'hello.there',
303 include: { 'deb' => false, 'src' => true },
308 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
312 context 'with include_src => true' do
315 location: 'hello.there',
316 include: { 'src' => true },
321 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there jessie main\ndeb-src hello.there jessie main\n})
325 context 'with include deb => false' do
328 include: { 'deb' => false },
329 location: 'hello.there',
334 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
336 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
339 context 'with include src => true and include deb => false' do
342 include: { 'deb' => false, 'src' => true },
343 location: 'hello.there',
348 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
350 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
353 context 'with ensure => absent' do
361 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
365 describe 'validation' do
366 context 'with no release' do
382 let(:params) { { location: 'hello.there' } }
385 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
389 context 'with release is empty string' do
390 let(:params) { { location: 'hello.there', release: '' } }
392 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
395 context 'with invalid pin' do
398 location: 'hello.there',
404 is_expected.to raise_error(Puppet::Error, %r{expects a value})
408 context 'with notify_update = undef (default)' do
411 location: 'hello.there',
415 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
418 context 'with notify_update = true' do
421 location: 'hello.there',
426 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
429 context 'with notify_update = false' do
432 location: 'hello.there',
433 notify_update: false,
437 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }