1 # frozen_string_literal: true
5 def ppa_exec_params(user, repo, distro = 'trusty', environment = [])
7 environment: environment,
8 command: "/opt/puppetlabs/puppet/cache/add-apt-repository-#{user}-ubuntu-#{repo}-#{distro}.sh",
9 logoutput: 'on_failure',
13 describe 'apt::ppa' do
18 describe 'defaults' do
33 puppet_vardir: '/opt/puppetlabs/puppet/cache'
37 let(:title) { 'ppa:needs/substitution' }
39 it { is_expected.not_to contain_package('python-software-properties') }
41 is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
42 .that_notifies('Class[Apt::Update]')
43 .with(*ppa_exec_params('needs', 'substitution'))
53 describe 'valid resource names' do
73 it { is_expected.not_to raise_error }
74 it { is_expected.to contain_exec("add-apt-repository-#{value}") }
84 '|| touch /tmp/foo.txt ||',
86 describe 'invalid resource names' do
104 let(:title) { value }
106 it { is_expected.to raise_error(Puppet::PreformattedError, %r{Invalid PPA name: #{value}}) }
110 describe 'Ubuntu 15.10 sources.list filename' do
125 puppet_vardir: '/opt/puppetlabs/puppet/cache',
129 let(:title) { 'ppa:user/foo' }
132 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
133 .that_notifies('Class[Apt::Update]')
134 .with(*ppa_exec_params('user', 'foo', 'wily'))
138 describe 'package_name => software-properties-common' do
139 let :pre_condition do
145 package_name: 'software-properties-common',
146 package_manage: true,
164 puppet_vardir: '/opt/puppetlabs/puppet/cache',
168 let(:title) { 'ppa:needs/substitution' }
170 it { is_expected.to contain_package('software-properties-common') }
172 is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
173 .that_notifies('Class[Apt::Update]')
174 .with(*ppa_exec_params('needs', 'substitution'))
178 describe 'package_manage => false' do
179 let :pre_condition do
197 puppet_vardir: '/opt/puppetlabs/puppet/cache',
203 package_manage: false,
207 let(:title) { 'ppa:needs/substitution' }
209 it { is_expected.not_to contain_package('python-software-properties') }
211 is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
212 .that_notifies('Class[Apt::Update]')
213 .with(*ppa_exec_params('needs', 'substitution'))
217 describe 'apt included, no proxy' do
218 let :pre_condition do
220 apt::ppa { "ppa:user/foo2": }
238 puppet_vardir: '/opt/puppetlabs/puppet/cache',
244 package_manage: true,
245 require: 'Apt::Ppa[ppa:user/foo2]',
249 let(:title) { 'ppa:user/foo' }
251 it { is_expected.to compile.with_all_deps }
252 it { is_expected.to contain_package('software-properties-common') }
254 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
255 .that_notifies('Class[Apt::Update]')
256 .with(*ppa_exec_params('user', 'foo'))
260 describe 'apt included, proxy host' do
261 let :pre_condition do
263 proxy => { "host" => "localhost" },
281 puppet_vardir: '/opt/puppetlabs/puppet/cache',
287 'package_manage' => true,
291 let(:title) { 'ppa:user/foo' }
293 it { is_expected.to contain_package('software-properties-common') }
295 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
296 .that_notifies('Class[Apt::Update]')
297 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8080']))
301 describe 'apt included, proxy host and port' do
302 let :pre_condition do
304 proxy => { "host" => "localhost", "port" => 8180 },
322 puppet_vardir: '/opt/puppetlabs/puppet/cache',
328 package_manage: true,
332 let(:title) { 'ppa:user/foo' }
334 it { is_expected.to contain_package('software-properties-common') }
336 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
337 .that_notifies('Class[Apt::Update]')
338 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180']))
342 describe 'apt included, proxy host and port and https' do
343 let :pre_condition do
345 proxy => { "host" => "localhost", "port" => 8180, "https" => true },
363 puppet_vardir: '/opt/puppetlabs/puppet/cache',
369 package_manage: true,
373 let(:title) { 'ppa:user/foo' }
375 it { is_expected.to contain_package('software-properties-common') }
377 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
378 .that_notifies('Class[Apt::Update]')
379 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180']))
383 describe 'ensure absent' do
384 let :pre_condition do
402 puppet_vardir: '/opt/puppetlabs/puppet/cache',
406 let(:title) { 'ppa:user/foo' }
415 is_expected.to contain_tidy("remove-apt-repository-script-#{title}")
416 .with('path' => '/opt/puppetlabs/puppet/cache/add-apt-repository-user-ubuntu-foo-trusty.sh')
418 is_expected.to contain_tidy("remove-apt-repository-#{title}")
419 .with('path' => '/etc/apt/sources.list.d/user-ubuntu-foo-trusty.list')
420 .that_notifies('Class[Apt::Update]')
424 context 'with validation' do
425 describe 'no release' do
443 let(:title) { 'ppa:user/foo' }
446 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
450 describe 'not ubuntu' do
468 let(:title) { 'ppa:user/foo' }
471 is_expected.to raise_error(Puppet::Error, %r{not currently supported on Debian})