3 describe 'apt::source' do
4 GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
16 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
18 lsbdistcodename: 'jessie',
19 operatingsystem: 'Debian',
24 context 'with defaults' do
25 context 'without location' do
27 is_expected.to raise_error(Puppet::Error, %r{source entry without specifying a location})
30 context 'with location' do
31 let(:params) { { location: 'hello.there' } }
34 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n})
35 is_expected.not_to contain_package('apt-transport-https')
40 describe 'no defaults' do
41 context 'with complex pin' do
44 location: 'hello.there',
45 pin: { 'release' => 'wishwash',
46 'explanation' => 'wishwash',
52 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there jessie main\n})
55 it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]') }
58 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
60 explanation: 'wishwash',
65 context 'with simple key' do
69 location: 'http://debian.mirror.iweb.ca/debian/',
74 architecture: 'x86_64',
80 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})
81 .without_content(%r{deb-src})
85 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
87 origin: 'debian.mirror.iweb.ca')
91 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',
96 context 'with complex key' do
100 location: 'http://debian.mirror.iweb.ca/debian/',
103 key: { 'ensure' => 'refreshed',
105 'server' => 'pgp.mit.edu',
106 'content' => 'GPG key content',
107 'source' => 'http://apt.puppetlabs.com/pubkey.gpg' },
109 architecture: 'x86_64',
110 allow_unsigned: true,
115 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})
116 .without_content(%r{deb-src})
120 is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present',
122 origin: 'debian.mirror.iweb.ca')
126 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',
128 server: 'pgp.mit.edu',
129 content: 'GPG key content',
130 source: 'http://apt.puppetlabs.com/pubkey.gpg')
135 context 'with allow_unsigned true' do
138 location: 'hello.there',
139 allow_unsigned: true,
144 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})
148 context 'with a https location, install apt-transport-https' do
151 location: 'HTTPS://foo.bar',
152 allow_unsigned: false,
157 is_expected.to contain_package('apt-transport-https')
161 context 'with a https location and custom release, install apt-transport-https' do
164 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
166 lsbdistcodename: 'jessie',
168 puppetversion: Puppet.version,
173 location: 'HTTPS://foo.bar',
174 allow_unsigned: false,
175 release: 'customrelease',
180 is_expected.to contain_package('apt-transport-https')
184 context 'with a https location, do not install apt-transport-https on oses not in list eg buster' do
187 os: { family: 'Debian', name: 'Debian', release: { major: '10', full: '10.0' } },
189 lsbdistcodename: 'buster',
195 location: 'https://foo.bar',
196 allow_unsigned: false,
201 is_expected.not_to contain_package('apt-transport-https')
205 context 'with architecture equals x86_64' do
208 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
210 lsbdistcodename: 'wheezy',
216 location: 'hello.there',
217 include: { 'deb' => false, 'src' => true },
218 architecture: 'x86_64',
223 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})
227 context 'with architecture fact and unset architecture parameter' do
229 super().merge(architecture: 'amd64')
233 location: 'hello.there',
234 include: { 'deb' => false, 'src' => true },
239 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there jessie main\n})
243 context 'with include_src => true' do
246 location: 'hello.there',
247 include: { 'src' => true },
252 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})
256 context 'with include deb => false' do
259 include: { 'deb' => false },
260 location: 'hello.there',
265 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
267 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
270 context 'with include src => true and include deb => false' do
273 include: { 'deb' => false, 'src' => true },
274 location: 'hello.there',
279 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there jessie main\n})
281 it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there jessie main\n}) }
284 context 'with ensure => absent' do
292 is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent')
296 describe 'validation' do
297 context 'with no release' do
300 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
304 let(:params) { { location: 'hello.there' } }
307 is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
311 context 'with release is empty string' do
312 let(:params) { { location: 'hello.there', release: '' } }
314 it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
317 context 'with invalid pin' do
320 location: 'hello.there',
326 is_expected.to raise_error(Puppet::Error, %r{expects a value})
330 context 'with notify_update = undef (default)' do
333 location: 'hello.there',
337 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
340 context 'with notify_update = true' do
343 location: 'hello.there',
348 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
351 context 'with notify_update = false' do
354 location: 'hello.there',
355 notify_update: false,
359 it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }