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: { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu',
124 'content' => 'GPG key content',
125 'source' => 'http://apt.puppetlabs.com/pubkey.gpg' },
127 architecture: 'x86_64',
128 allow_unsigned: true,
133 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})
134 .without_content(%r{deb-src})
138 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
140 origin: 'debian.mirror.iweb.ca')
144 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',
146 server: 'pgp.mit.edu',
147 content: 'GPG key content',
148 source: 'http://apt.puppetlabs.com/pubkey.gpg')
153 context 'with allow_unsigned true' do
156 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
158 lsbdistcodename: 'jessie',
160 puppetversion: Puppet.version,
165 location: 'hello.there',
166 allow_unsigned: true,
171 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})
175 context 'with a https location, install apt-transport-https' do
178 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
180 lsbdistcodename: 'jessie',
182 puppetversion: Puppet.version,
187 location: 'HTTPS://foo.bar',
188 allow_unsigned: false,
193 is_expected.to contain_package('apt-transport-https')
197 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
200 os: { family: 'Debian', name: 'Debian', release: { major: '10', full: '10.0' } },
202 lsbdistcodename: 'buster',
204 puppetversion: Puppet.version,
209 location: 'https://foo.bar',
210 allow_unsigned: false,
215 is_expected.not_to contain_package('apt-transport-https')
219 context 'with architecture equals x86_64' do
222 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
224 lsbdistcodename: 'wheezy',
226 puppetversion: Puppet.version,
231 location: 'hello.there',
232 include: { 'deb' => false, 'src' => true },
233 architecture: 'x86_64',
238 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})
242 context 'with architecture fact and unset architecture parameter' do
245 architecture: 'amd64',
246 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
248 lsbdistcodename: 'jessie',
250 puppetversion: Puppet.version,
255 location: 'hello.there',
256 include: { 'deb' => false, 'src' => true },
261 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
265 context 'with include_src => true' do
268 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
270 lsbdistcodename: 'jessie',
272 puppetversion: Puppet.version,
277 location: 'hello.there',
278 include: { 'src' => true },
283 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})
287 context 'with include deb => false' do
290 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
292 lsbdistcodename: 'jessie',
294 puppetversion: Puppet.version,
299 include: { 'deb' => false },
300 location: 'hello.there',
305 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
307 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
310 context 'with include src => true and include deb => false' do
313 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
315 lsbdistcodename: 'jessie',
317 puppetversion: Puppet.version,
322 include: { 'deb' => false, 'src' => true },
323 location: 'hello.there',
328 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
330 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
333 context 'with ensure => absent' do
336 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
338 lsbdistcodename: 'jessie',
340 puppetversion: Puppet.version,
350 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
354 describe 'validation' do
355 context 'with no release' do
358 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
361 puppetversion: Puppet.version,
364 let(:params) { { location: 'hello.there' } }
367 is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
371 context 'with release is empty string' do
374 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
377 puppetversion: Puppet.version,
380 let(:params) { { location: 'hello.there', release: '' } }
382 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
385 context 'with invalid pin' do
388 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
390 lsbdistcodename: 'jessie',
392 puppetversion: Puppet.version,
397 location: 'hello.there',
403 is_expected.to raise_error(Puppet::Error, %r{expects a value})
407 context 'with notify_update = undef (default)' do
410 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
412 lsbdistcodename: 'jessie',
414 puppetversion: Puppet.version,
419 location: 'hello.there',
423 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
426 context 'with notify_update = true' do
429 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
431 lsbdistcodename: 'jessie',
433 puppetversion: Puppet.version,
438 location: 'hello.there',
443 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
446 context 'with notify_update = false' do
449 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
451 lsbdistcodename: 'jessie',
453 puppetversion: Puppet.version,
458 location: 'hello.there',
459 notify_update: false,
463 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }