1 # frozen_string_literal: true
5 describe 'apt::source' do
6 let(:id) { '6F6B15509CF8E59E6E469F327F438280EF8D349F' }
7 let(:title) { 'my_source' }
8 let(:pre_condition) { 'class { "apt": }' }
26 context 'with defaults' do
27 context 'without location' do
29 expect(subject).to raise_error(Puppet::Error, %r{source entry without specifying a location})
33 context 'with location' do
34 let(:params) { { location: 'hello.there' } }
37 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n})
38 expect(subject).not_to contain_package('apt-transport-https')
43 describe 'no defaults' do
44 context 'with complex pin' do
47 location: 'hello.there',
48 pin: { 'release' => 'wishwash',
49 'explanation' => 'wishwash',
55 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there stretch main\n})
58 it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]') }
61 expect(subject).to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
63 explanation: 'wishwash',
68 context 'with simple key' do
72 location: 'http://debian.mirror.iweb.ca/debian/',
77 architecture: 'x86_64',
83 expect(subject).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})
84 .without_content(%r{deb-src})
88 expect(subject).to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
90 origin: 'debian.mirror.iweb.ca')
94 expect(subject).to contain_apt__key("Add key: #{id} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
99 context 'with complex key' do
103 location: 'http://debian.mirror.iweb.ca/debian/',
107 'ensure' => 'refreshed',
109 'server' => 'pgp.mit.edu',
110 'content' => 'GPG key content',
111 'source' => 'http://apt.puppetlabs.com/pubkey.gpg',
115 architecture: 'x86_64',
121 expect(subject).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})
122 .without_content(%r{deb-src})
126 expect(subject).to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
128 origin: 'debian.mirror.iweb.ca')
132 expect(subject).to contain_apt__key("Add key: #{id} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'refreshed',
134 server: 'pgp.mit.edu',
135 content: 'GPG key content',
136 source: 'http://apt.puppetlabs.com/pubkey.gpg',
142 context 'with allow_insecure true' do
145 location: 'hello.there',
151 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[allow-insecure=yes\] hello.there stretch main\n})
155 context 'with allow_unsigned true' do
158 location: 'hello.there',
164 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[trusted=yes\] hello.there stretch main\n})
168 context 'with check_valid_until false' do
171 location: 'hello.there',
172 check_valid_until: false
177 expect(subject).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})
181 context 'with check_valid_until true' do
184 location: 'hello.there',
185 check_valid_until: true
190 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there stretch main\n})
194 context 'with keyring set' do
197 location: 'hello.there',
198 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg'
203 expect(subject).to contain_apt__setting('list-my_source')
204 .with(ensure: 'present')
205 .with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n})
209 context 'with keyring, architecture and allow_unsigned set' do
212 location: 'hello.there',
213 architecture: 'amd64',
214 allow_unsigned: true,
215 keyring: '/usr/share/keyrings/foo-archive-keyring.gpg'
220 expect(subject).to contain_apt__setting('list-my_source')
221 .with(ensure: 'present')
222 .with_content(%r{# my_source\ndeb \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n})
226 context 'with a https location, install apt-transport-https' do
229 location: 'HTTPS://foo.bar',
230 allow_unsigned: false
235 expect(subject).to contain_package('apt-transport-https')
239 context 'with a https location and custom release, install apt-transport-https' do
254 puppetversion: Puppet.version
259 location: 'HTTPS://foo.bar',
260 allow_unsigned: false,
261 release: 'customrelease'
266 expect(subject).to contain_package('apt-transport-https')
270 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
289 location: 'https://foo.bar',
290 allow_unsigned: false
295 expect(subject).not_to contain_package('apt-transport-https')
299 context 'with architecture equals x86_64' do
318 location: 'hello.there',
319 include: { 'deb' => false, 'src' => true },
320 architecture: 'x86_64'
325 expect(subject).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})
329 context 'with architecture fact and unset architecture parameter' do
331 super().merge(architecture: 'amd64')
335 location: 'hello.there',
336 include: { 'deb' => false, 'src' => true }
341 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there stretch main\n})
345 context 'with include_src => true' do
348 location: 'hello.there',
349 include: { 'src' => true }
354 expect(subject).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})
358 context 'with include deb => false' do
361 include: { 'deb' => false },
362 location: 'hello.there'
367 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
370 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
373 context 'with include src => true and include deb => false' do
376 include: { 'deb' => false, 'src' => true },
377 location: 'hello.there'
382 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there stretch main\n})
385 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there stretch main\n}) }
388 context 'with ensure => absent' do
396 expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'absent')
400 describe 'validation' do
401 context 'with no release' do
417 let(:params) { { location: 'hello.there' } }
420 expect(subject).to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
424 context 'with release is empty string' do
425 let(:params) { { location: 'hello.there', release: '' } }
427 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
430 context 'with invalid pin' do
433 location: 'hello.there',
439 expect(subject).to raise_error(Puppet::Error, %r{expects a value})
443 context 'with notify_update = undef (default)' do
446 location: 'hello.there'
450 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
453 context 'with notify_update = true' do
456 location: 'hello.there',
461 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
464 context 'with notify_update = false' do
467 location: 'hello.there',
472 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }