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 a https location, install apt-transport-https' do
164 location: 'HTTPS://foo.bar',
165 allow_unsigned: false,
170 is_expected.to contain_package('apt-transport-https')
174 context 'with a https location and custom release, install apt-transport-https' do
189 puppetversion: Puppet.version,
194 location: 'HTTPS://foo.bar',
195 allow_unsigned: false,
196 release: 'customrelease',
201 is_expected.to contain_package('apt-transport-https')
205 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
224 location: 'https://foo.bar',
225 allow_unsigned: false,
230 is_expected.not_to contain_package('apt-transport-https')
234 context 'with architecture equals x86_64' do
253 location: 'hello.there',
254 include: { 'deb' => false, 'src' => true },
255 architecture: 'x86_64',
260 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})
264 context 'with architecture fact and unset architecture parameter' do
266 super().merge(architecture: 'amd64')
270 location: 'hello.there',
271 include: { 'deb' => false, 'src' => true },
276 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
280 context 'with include_src => true' do
283 location: 'hello.there',
284 include: { 'src' => true },
289 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})
293 context 'with include deb => false' do
296 include: { 'deb' => false },
297 location: 'hello.there',
302 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
304 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
307 context 'with include src => true and include deb => false' do
310 include: { 'deb' => false, 'src' => true },
311 location: 'hello.there',
316 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
318 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
321 context 'with ensure => absent' do
329 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
333 describe 'validation' do
334 context 'with no release' do
350 let(:params) { { location: 'hello.there' } }
353 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
357 context 'with release is empty string' do
358 let(:params) { { location: 'hello.there', release: '' } }
360 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
363 context 'with invalid pin' do
366 location: 'hello.there',
372 is_expected.to raise_error(Puppet::Error, %r{expects a value})
376 context 'with notify_update = undef (default)' do
379 location: 'hello.there',
383 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
386 context 'with notify_update = true' do
389 location: 'hello.there',
394 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
397 context 'with notify_update = false' do
400 location: 'hello.there',
401 notify_update: false,
405 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }