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')
152 context 'with simple key' do
156 location: 'http://debian.mirror.iweb.ca/debian/',
161 architecture: 'x86_64',
162 allow_unsigned: true,
167 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})
168 .without_content(%r{deb-src})
172 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
174 origin: 'debian.mirror.iweb.ca')
178 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',
184 context 'with allow_unsigned true' do
187 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
189 lsbdistcodename: 'jessie',
191 puppetversion: Puppet.version,
196 location: 'hello.there',
197 allow_unsigned: true,
202 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})
206 context 'with a https location, install apt-transport-https' do
209 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
211 lsbdistcodename: 'jessie',
213 puppetversion: Puppet.version,
218 location: 'HTTPS://foo.bar',
219 allow_unsigned: false,
224 is_expected.to contain_package('apt-transport-https')
228 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
231 os: { family: 'Debian', name: 'Debian', release: { major: '10', full: '10.0' } },
233 lsbdistcodename: 'buster',
235 puppetversion: Puppet.version,
240 location: 'https://foo.bar',
241 allow_unsigned: false,
246 is_expected.not_to contain_package('apt-transport-https')
250 context 'with architecture equals x86_64' do
253 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
255 lsbdistcodename: 'wheezy',
257 puppetversion: Puppet.version,
262 location: 'hello.there',
263 include: { 'deb' => false, 'src' => true },
264 architecture: 'x86_64',
269 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})
273 context 'with architecture fact and unset architecture parameter' do
276 architecture: 'amd64',
277 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
279 lsbdistcodename: 'jessie',
281 puppetversion: Puppet.version,
286 location: 'hello.there',
287 include: { 'deb' => false, 'src' => true },
292 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
296 context 'with include_src => true' do
299 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
301 lsbdistcodename: 'jessie',
303 puppetversion: Puppet.version,
308 location: 'hello.there',
309 include: { 'src' => true },
314 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})
318 context 'with include deb => false' do
321 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
323 lsbdistcodename: 'jessie',
325 puppetversion: Puppet.version,
330 include: { 'deb' => false },
331 location: 'hello.there',
336 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
338 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
341 context 'with include src => true and include deb => false' do
344 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
346 lsbdistcodename: 'jessie',
348 puppetversion: Puppet.version,
353 include: { 'deb' => false, 'src' => true },
354 location: 'hello.there',
359 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
361 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
364 context 'with ensure => absent' do
367 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
369 lsbdistcodename: 'jessie',
371 puppetversion: Puppet.version,
381 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
385 describe 'validation' do
386 context 'with no release' do
389 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
392 puppetversion: Puppet.version,
395 let(:params) { { location: 'hello.there' } }
398 is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
402 context 'with release is empty string' do
405 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
408 puppetversion: Puppet.version,
411 let(:params) { { location: 'hello.there', release: '' } }
413 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
416 context 'with invalid pin' do
419 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
421 lsbdistcodename: 'jessie',
423 puppetversion: Puppet.version,
428 location: 'hello.there',
434 is_expected.to raise_error(Puppet::Error, %r{expects a value})
438 context 'with notify_update = undef (default)' do
441 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
443 lsbdistcodename: 'jessie',
445 puppetversion: Puppet.version,
450 location: 'hello.there',
454 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
457 context 'with notify_update = true' do
460 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
462 lsbdistcodename: 'jessie',
464 puppetversion: Puppet.version,
469 location: 'hello.there',
474 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
477 context 'with notify_update = false' do
480 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
482 lsbdistcodename: 'jessie',
484 puppetversion: Puppet.version,
489 location: 'hello.there',
490 notify_update: false,
494 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }