3 describe 'apt::source' do
4 GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
14 context 'with defaults' do
15 context 'without location' do
18 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
20 lsbdistcodename: 'jessie',
21 puppetversion: Puppet.version,
26 is_expected.to raise_error(Puppet::Error, %r{source entry without specifying a location})
29 context 'with location' do
32 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
34 lsbdistcodename: 'jessie',
36 puppetversion: Puppet.version,
39 let(:params) { { location: 'hello.there' } }
42 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n})
43 is_expected.not_to contain_package('apt-transport-https')
48 describe 'no defaults' do
51 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
53 lsbdistcodename: 'jessie',
55 operatingsystem: 'Debian',
56 lsbdistrelease: '8.0',
57 puppetversion: Puppet.version,
61 context 'with complex pin' do
64 location: 'hello.there',
65 pin: { 'release' => 'wishwash',
66 'explanation' => 'wishwash',
72 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there jessie main\n})
75 it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]') }
78 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
80 explanation: 'wishwash',
85 context 'with simple key' do
89 location: 'http://debian.mirror.iweb.ca/debian/',
94 architecture: 'x86_64',
100 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})
101 .without_content(%r{deb-src})
105 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
107 origin: 'debian.mirror.iweb.ca')
111 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',
116 context 'with complex key' do
120 location: 'http://debian.mirror.iweb.ca/debian/',
123 key: { 'ensure' => 'refreshed',
125 'server' => 'pgp.mit.edu',
126 'content' => 'GPG key content',
127 'source' => 'http://apt.puppetlabs.com/pubkey.gpg' },
129 architecture: 'x86_64',
130 allow_unsigned: true,
135 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})
136 .without_content(%r{deb-src})
140 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
142 origin: 'debian.mirror.iweb.ca')
146 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',
148 server: 'pgp.mit.edu',
149 content: 'GPG key content',
150 source: 'http://apt.puppetlabs.com/pubkey.gpg')
155 context 'with allow_unsigned true' do
158 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
160 lsbdistcodename: 'jessie',
162 puppetversion: Puppet.version,
167 location: 'hello.there',
168 allow_unsigned: true,
173 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})
177 context 'with a https location, install apt-transport-https' do
180 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
182 lsbdistcodename: 'jessie',
184 puppetversion: Puppet.version,
189 location: 'HTTPS://foo.bar',
190 allow_unsigned: false,
195 is_expected.to contain_package('apt-transport-https')
199 context 'with a https location and custom release, install apt-transport-https' do
202 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
204 lsbdistcodename: 'jessie',
206 puppetversion: Puppet.version,
211 location: 'HTTPS://foo.bar',
212 allow_unsigned: false,
213 release: 'customrelease',
218 is_expected.to contain_package('apt-transport-https')
222 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
225 os: { family: 'Debian', name: 'Debian', release: { major: '10', full: '10.0' } },
227 lsbdistcodename: 'buster',
229 puppetversion: Puppet.version,
234 location: 'https://foo.bar',
235 allow_unsigned: false,
240 is_expected.not_to contain_package('apt-transport-https')
244 context 'with architecture equals x86_64' do
247 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
249 lsbdistcodename: 'wheezy',
251 puppetversion: Puppet.version,
256 location: 'hello.there',
257 include: { 'deb' => false, 'src' => true },
258 architecture: 'x86_64',
263 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})
267 context 'with architecture fact and unset architecture parameter' do
270 architecture: 'amd64',
271 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
273 lsbdistcodename: 'jessie',
275 puppetversion: Puppet.version,
280 location: 'hello.there',
281 include: { 'deb' => false, 'src' => true },
286 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
290 context 'with include_src => true' do
293 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
295 lsbdistcodename: 'jessie',
297 puppetversion: Puppet.version,
302 location: 'hello.there',
303 include: { 'src' => true },
308 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})
312 context 'with include deb => false' do
315 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
317 lsbdistcodename: 'jessie',
319 puppetversion: Puppet.version,
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 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
340 lsbdistcodename: 'jessie',
342 puppetversion: Puppet.version,
347 include: { 'deb' => false, 'src' => true },
348 location: 'hello.there',
353 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
355 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
358 context 'with ensure => absent' do
361 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
363 lsbdistcodename: 'jessie',
365 puppetversion: Puppet.version,
375 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
379 describe 'validation' do
380 context 'with no release' do
383 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
386 puppetversion: Puppet.version,
389 let(:params) { { location: 'hello.there' } }
392 is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
396 context 'with release is empty string' do
399 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
402 puppetversion: Puppet.version,
405 let(:params) { { location: 'hello.there', release: '' } }
407 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
410 context 'with invalid pin' do
413 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
415 lsbdistcodename: 'jessie',
417 puppetversion: Puppet.version,
422 location: 'hello.there',
428 is_expected.to raise_error(Puppet::Error, %r{expects a value})
432 context 'with notify_update = undef (default)' do
435 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
437 lsbdistcodename: 'jessie',
439 puppetversion: Puppet.version,
444 location: 'hello.there',
448 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
451 context 'with notify_update = true' do
454 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
456 lsbdistcodename: 'jessie',
458 puppetversion: Puppet.version,
463 location: 'hello.there',
468 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
471 context 'with notify_update = false' do
474 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
476 lsbdistcodename: 'jessie',
478 puppetversion: Puppet.version,
483 location: 'hello.there',
484 notify_update: false,
488 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }