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/',
112 key: { 'ensure' => 'refreshed',
114 'server' => 'pgp.mit.edu',
115 'content' => 'GPG key content',
116 'source' => 'http://apt.puppetlabs.com/pubkey.gpg' },
118 architecture: 'x86_64',
119 allow_unsigned: true,
124 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})
125 .without_content(%r{deb-src})
129 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
131 origin: 'debian.mirror.iweb.ca')
135 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',
137 server: 'pgp.mit.edu',
138 content: 'GPG key content',
139 source: 'http://apt.puppetlabs.com/pubkey.gpg')
144 context 'with allow_unsigned true' do
147 location: 'hello.there',
148 allow_unsigned: true,
153 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})
157 context 'with keyring set' do
160 location: 'hello.there',
161 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
166 is_expected.to contain_apt__setting('list-my_source')
167 .with(ensure: 'present')
168 .with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there jessie main\n})
172 context 'with keyring, architecture and allow_unsigned set' do
175 location: 'hello.there',
176 architecture: 'amd64',
177 allow_unsigned: true,
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 \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there jessie main\n})
189 context 'with a https location, install apt-transport-https' do
192 location: 'HTTPS://foo.bar',
193 allow_unsigned: false,
198 is_expected.to contain_package('apt-transport-https')
202 context 'with a https location and custom release, install apt-transport-https' do
217 puppetversion: Puppet.version,
222 location: 'HTTPS://foo.bar',
223 allow_unsigned: false,
224 release: 'customrelease',
229 is_expected.to contain_package('apt-transport-https')
233 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
252 location: 'https://foo.bar',
253 allow_unsigned: false,
258 is_expected.not_to contain_package('apt-transport-https')
262 context 'with architecture equals x86_64' do
281 location: 'hello.there',
282 include: { 'deb' => false, 'src' => true },
283 architecture: 'x86_64',
288 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})
292 context 'with architecture fact and unset architecture parameter' do
294 super().merge(architecture: 'amd64')
298 location: 'hello.there',
299 include: { 'deb' => false, 'src' => true },
304 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
308 context 'with include_src => true' do
311 location: 'hello.there',
312 include: { 'src' => true },
317 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})
321 context 'with include deb => false' do
324 include: { 'deb' => false },
325 location: 'hello.there',
330 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
332 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
335 context 'with include src => true and include deb => false' do
338 include: { 'deb' => false, 'src' => true },
339 location: 'hello.there',
344 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
346 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
349 context 'with ensure => absent' do
357 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
361 describe 'validation' do
362 context 'with no release' do
378 let(:params) { { location: 'hello.there' } }
381 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
385 context 'with release is empty string' do
386 let(:params) { { location: 'hello.there', release: '' } }
388 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
391 context 'with invalid pin' do
394 location: 'hello.there',
400 is_expected.to raise_error(Puppet::Error, %r{expects a value})
404 context 'with notify_update = undef (default)' do
407 location: 'hello.there',
411 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
414 context 'with notify_update = true' do
417 location: 'hello.there',
422 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
425 context 'with notify_update = false' do
428 location: 'hello.there',
429 notify_update: false,
433 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }