3 sources_list = { ensure: 'file',
4 path: '/etc/apt/sources.list',
8 notify: 'Class[Apt::Update]' }
10 sources_list_d = { ensure: 'directory',
11 path: '/etc/apt/sources.list.d',
17 notify: 'Class[Apt::Update]' }
19 preferences = { ensure: 'file',
20 path: '/etc/apt/preferences',
24 notify: 'Class[Apt::Update]' }
26 preferences_d = { ensure: 'directory',
27 path: '/etc/apt/preferences.d',
33 notify: 'Class[Apt::Update]' }
38 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
41 lsbdistcodename: 'wheezy',
42 puppetversion: Puppet.version,
48 is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list)
52 is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d)
56 is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences)
60 is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
63 it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
64 is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root',
66 owner: 'root').with_content(
67 %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};},
72 is_expected.to contain_exec('apt_update').with(refreshonly: 'true')
75 it { is_expected.not_to contain_apt__setting('conf-proxy') }
79 context 'host=localhost' do
80 let(:params) { { proxy: { 'host' => 'localhost' } } }
83 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
84 %r{Acquire::http::proxy "http://localhost:8080/";},
86 %r{Acquire::https::proxy},
91 context 'host=localhost and port=8180' do
92 let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } }
95 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
96 %r{Acquire::http::proxy "http://localhost:8180/";},
98 %r{Acquire::https::proxy},
103 context 'host=localhost and https=true' do
104 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } }
107 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
108 %r{Acquire::http::proxy "http://localhost:8080/";},
110 %r{Acquire::https::proxy "https://localhost:8080/";},
115 context 'host=localhost and direct=true' do
116 let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } }
119 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
120 %r{Acquire::http::proxy "http://localhost:8080/";},
122 %r{Acquire::https::proxy "DIRECT";},
127 context 'host=localhost and https=true and direct=true' do
128 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } }
131 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
132 %r{Acquire::http::proxy "http://localhost:8080/";},
134 %r{Acquire::https::proxy "https://localhost:8080/";},
138 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
139 %r{Acquire::http::proxy "http://localhost:8080/";},
141 %r{Acquire::https::proxy "DIRECT";},
146 context 'ensure=absent' do
147 let(:params) { { proxy: { 'ensure' => 'absent' } } }
150 is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent',
155 context 'lots of non-defaults' do
158 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
159 purge: { 'sources.list' => false, 'sources.list.d' => false,
160 'preferences' => false, 'preferences.d' => false },
165 is_expected.to contain_file('sources.list').with(content: nil)
169 is_expected.to contain_file('sources.list.d').with(purge: false,
174 is_expected.to contain_file('preferences').with(ensure: 'file')
178 is_expected.to contain_file('preferences.d').with(purge: false,
183 is_expected.to contain_exec('apt_update').with(refreshonly: false,
189 context 'with sources defined on valid osfamily' do
191 { os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04' } },
193 lsbdistcodename: 'precise',
195 lsbdistrelease: '12.04',
196 puppetversion: Puppet.version }
200 'debian_unstable' => {
201 'location' => 'http://debian.mirror.iweb.ca/debian/',
202 'release' => 'unstable',
203 'repos' => 'main contrib non-free',
204 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
206 'include' => { 'src' => true },
209 'location' => 'http://apt.puppetlabs.com',
211 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' },
217 is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present')
220 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(%r{^deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free$}) }
221 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(%r{^deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free$}) }
224 is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present')
227 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com precise main$}) }
230 context 'with confs defined on valid osfamily' do
233 os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } },
235 lsbdistcodename: 'precise',
237 puppetversion: Puppet.version,
252 is_expected.to contain_apt__conf('foo').with(content: 'foo')
256 is_expected.to contain_apt__conf('bar').with(content: 'bar')
260 context 'with keys defined on valid osfamily' do
263 os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } },
265 lsbdistcodename: 'precise',
267 puppetversion: Puppet.version,
273 'server' => 'subkeys.pgp.net',
276 'server' => 'pgp.mit.edu',
282 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
286 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
290 context 'with ppas defined on valid osfamily' do
293 os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } },
295 lsbdistcodename: 'precise',
297 lsbdistrelease: '12.04',
298 puppetversion: Puppet.version,
303 'ppa:drizzle-developers/ppa' => {},
304 'ppa:nginx/stable' => {},
308 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
309 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
312 context 'with settings defined on valid osfamily' do
315 os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } },
317 lsbdistcodename: 'precise',
319 puppetversion: Puppet.version,
324 'conf-banana' => { 'content' => 'banana' },
325 'pref-banana' => { 'content' => 'banana' },
329 it { is_expected.to contain_apt__setting('conf-banana') }
330 it { is_expected.to contain_apt__setting('pref-banana') }
333 context 'with pins defined on valid osfamily' do
336 os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } },
338 lsbdistcodename: 'precise',
340 puppetversion: Puppet.version,
345 'stable' => { 'priority' => 600, 'order' => 50 },
346 'testing' => { 'priority' => 700, 'order' => 100 },
350 it { is_expected.to contain_apt__pin('stable') }
351 it { is_expected.to contain_apt__pin('testing') }
354 describe 'failing tests' do
355 context "purge['sources.list']=>'banana'" do
356 let(:params) { { purge: { 'sources.list' => 'banana' } } }
359 is_expected.to raise_error(Puppet::Error)
363 context "purge['sources.list.d']=>'banana'" do
364 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
367 is_expected.to raise_error(Puppet::Error)
371 context "purge['preferences']=>'banana'" do
372 let(:params) { { purge: { 'preferences' => 'banana' } } }
375 is_expected.to raise_error(Puppet::Error)
379 context "purge['preferences.d']=>'banana'" do
380 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
383 is_expected.to raise_error(Puppet::Error)