1 # frozen_string_literal: true
5 describe 'apt::source' do
6 GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'
18 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
20 lsbdistcodename: 'jessie',
21 operatingsystem: 'Debian',
26 context 'with defaults' do
27 context 'without location' do
29 is_expected.to raise_error(Puppet::Error, %r{source entry without specifying a location})
32 context 'with location' do
33 let(:params) { { location: 'hello.there' } }
36 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n})
37 is_expected.not_to contain_package('apt-transport-https')
42 describe 'no defaults' do
43 context 'with complex pin' do
46 location: 'hello.there',
47 pin: { 'release' => 'wishwash',
48 'explanation' => 'wishwash',
54 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there jessie main\n})
57 it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]') }
60 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
62 explanation: 'wishwash',
67 context 'with simple key' do
71 location: 'http://debian.mirror.iweb.ca/debian/',
76 architecture: 'x86_64',
82 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})
83 .without_content(%r{deb-src})
87 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
89 origin: 'debian.mirror.iweb.ca')
93 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',
98 context 'with complex key' do
102 location: 'http://debian.mirror.iweb.ca/debian/',
105 key: { 'ensure' => 'refreshed',
107 'server' => 'pgp.mit.edu',
108 'content' => 'GPG key content',
109 'source' => 'http://apt.puppetlabs.com/pubkey.gpg' },
111 architecture: 'x86_64',
112 allow_unsigned: true,
117 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})
118 .without_content(%r{deb-src})
122 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
124 origin: 'debian.mirror.iweb.ca')
128 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',
130 server: 'pgp.mit.edu',
131 content: 'GPG key content',
132 source: 'http://apt.puppetlabs.com/pubkey.gpg')
137 context 'with allow_unsigned true' do
140 location: 'hello.there',
141 allow_unsigned: true,
146 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})
150 context 'with a https location, install apt-transport-https' do
153 location: 'HTTPS://foo.bar',
154 allow_unsigned: false,
159 is_expected.to contain_package('apt-transport-https')
163 context 'with a https location and custom release, install apt-transport-https' do
166 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
168 lsbdistcodename: 'jessie',
170 puppetversion: Puppet.version,
175 location: 'HTTPS://foo.bar',
176 allow_unsigned: false,
177 release: 'customrelease',
182 is_expected.to contain_package('apt-transport-https')
186 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
189 os: { family: 'Debian', name: 'Debian', release: { major: '10', full: '10.0' } },
191 lsbdistcodename: 'buster',
197 location: 'https://foo.bar',
198 allow_unsigned: false,
203 is_expected.not_to contain_package('apt-transport-https')
207 context 'with architecture equals x86_64' do
210 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
212 lsbdistcodename: 'wheezy',
218 location: 'hello.there',
219 include: { 'deb' => false, 'src' => true },
220 architecture: 'x86_64',
225 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})
229 context 'with architecture fact and unset architecture parameter' do
231 super().merge(architecture: 'amd64')
235 location: 'hello.there',
236 include: { 'deb' => false, 'src' => true },
241 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
245 context 'with include_src => true' do
248 location: 'hello.there',
249 include: { 'src' => true },
254 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})
258 context 'with include deb => false' do
261 include: { 'deb' => false },
262 location: 'hello.there',
267 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
269 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
272 context 'with include src => true and include deb => false' do
275 include: { 'deb' => false, 'src' => true },
276 location: 'hello.there',
281 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
283 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
286 context 'with ensure => absent' do
294 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
298 describe 'validation' do
299 context 'with no release' do
302 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
306 let(:params) { { location: 'hello.there' } }
309 is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
313 context 'with release is empty string' do
314 let(:params) { { location: 'hello.there', release: '' } }
316 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
319 context 'with invalid pin' do
322 location: 'hello.there',
328 is_expected.to raise_error(Puppet::Error, %r{expects a value})
332 context 'with notify_update = undef (default)' do
335 location: 'hello.there',
339 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
342 context 'with notify_update = true' do
345 location: 'hello.there',
350 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
353 context 'with notify_update = false' do
356 location: 'hello.there',
357 notify_update: false,
361 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }