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 a https location, install apt-transport-https' do
160 location: 'HTTPS://foo.bar',
161 allow_unsigned: false,
166 is_expected.to contain_package('apt-transport-https')
170 context 'with a https location and custom release, install apt-transport-https' do
185 puppetversion: Puppet.version,
190 location: 'HTTPS://foo.bar',
191 allow_unsigned: false,
192 release: 'customrelease',
197 is_expected.to contain_package('apt-transport-https')
201 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
220 location: 'https://foo.bar',
221 allow_unsigned: false,
226 is_expected.not_to contain_package('apt-transport-https')
230 context 'with architecture equals x86_64' do
249 location: 'hello.there',
250 include: { 'deb' => false, 'src' => true },
251 architecture: 'x86_64',
256 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})
260 context 'with architecture fact and unset architecture parameter' do
262 super().merge(architecture: 'amd64')
266 location: 'hello.there',
267 include: { 'deb' => false, 'src' => true },
272 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
276 context 'with include_src => true' do
279 location: 'hello.there',
280 include: { 'src' => true },
285 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})
289 context 'with include deb => false' do
292 include: { 'deb' => false },
293 location: 'hello.there',
298 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
300 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
303 context 'with include src => true and include deb => false' do
306 include: { 'deb' => false, 'src' => true },
307 location: 'hello.there',
312 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
314 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
317 context 'with ensure => absent' do
325 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
329 describe 'validation' do
330 context 'with no release' do
346 let(:params) { { location: 'hello.there' } }
349 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
353 context 'with release is empty string' do
354 let(:params) { { location: 'hello.there', release: '' } }
356 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
359 context 'with invalid pin' do
362 location: 'hello.there',
368 is_expected.to raise_error(Puppet::Error, %r{expects a value})
372 context 'with notify_update = undef (default)' do
375 location: 'hello.there',
379 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
382 context 'with notify_update = true' do
385 location: 'hello.there',
390 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
393 context 'with notify_update = false' do
396 location: 'hello.there',
397 notify_update: false,
401 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }