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'))
47 describe 'Ubuntu 15.10 sources.list filename' do
62 puppet_vardir: '/opt/puppetlabs/puppet/cache',
66 let(:title) { 'ppa:user/foo' }
69 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
70 .that_notifies('Class[Apt::Update]')
71 .with(*ppa_exec_params('user', 'foo', 'wily'))
75 describe 'package_name => software-properties-common' do
82 package_name: 'software-properties-common',
101 puppet_vardir: '/opt/puppetlabs/puppet/cache',
105 let(:title) { 'ppa:needs/substitution' }
107 it { is_expected.to contain_package('software-properties-common') }
109 is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
110 .that_notifies('Class[Apt::Update]')
111 .with(*ppa_exec_params('needs', 'substitution'))
115 describe 'package_manage => false' do
116 let :pre_condition do
134 puppet_vardir: '/opt/puppetlabs/puppet/cache',
140 package_manage: false,
144 let(:title) { 'ppa:needs/substitution' }
146 it { is_expected.not_to contain_package('python-software-properties') }
148 is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
149 .that_notifies('Class[Apt::Update]')
150 .with(*ppa_exec_params('needs', 'substitution'))
154 describe 'apt included, no proxy' do
155 let :pre_condition do
157 apt::ppa { "ppa:user/foo2": }
175 puppet_vardir: '/opt/puppetlabs/puppet/cache',
181 package_manage: true,
182 require: 'Apt::Ppa[ppa:user/foo2]',
186 let(:title) { 'ppa:user/foo' }
188 it { is_expected.to compile.with_all_deps }
189 it { is_expected.to contain_package('software-properties-common') }
191 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
192 .that_notifies('Class[Apt::Update]')
193 .with(*ppa_exec_params('user', 'foo'))
197 describe 'apt included, proxy host' do
198 let :pre_condition do
200 proxy => { "host" => "localhost" },
218 puppet_vardir: '/opt/puppetlabs/puppet/cache',
224 'package_manage' => true,
228 let(:title) { 'ppa:user/foo' }
230 it { is_expected.to contain_package('software-properties-common') }
232 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
233 .that_notifies('Class[Apt::Update]')
234 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8080']))
238 describe 'apt included, proxy host and port' do
239 let :pre_condition do
241 proxy => { "host" => "localhost", "port" => 8180 },
259 puppet_vardir: '/opt/puppetlabs/puppet/cache',
265 package_manage: true,
269 let(:title) { 'ppa:user/foo' }
271 it { is_expected.to contain_package('software-properties-common') }
273 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
274 .that_notifies('Class[Apt::Update]')
275 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180']))
279 describe 'apt included, proxy host and port and https' do
280 let :pre_condition do
282 proxy => { "host" => "localhost", "port" => 8180, "https" => true },
300 puppet_vardir: '/opt/puppetlabs/puppet/cache',
306 package_manage: true,
310 let(:title) { 'ppa:user/foo' }
312 it { is_expected.to contain_package('software-properties-common') }
314 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
315 .that_notifies('Class[Apt::Update]')
316 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180']))
320 describe 'ensure absent' do
321 let :pre_condition do
339 puppet_vardir: '/opt/puppetlabs/puppet/cache',
343 let(:title) { 'ppa:user/foo' }
352 is_expected.to contain_tidy("remove-apt-repository-script-#{title}")
353 .with('path' => '/opt/puppetlabs/puppet/cache/add-apt-repository-user-ubuntu-foo-trusty.sh')
355 is_expected.to contain_tidy("remove-apt-repository-#{title}")
356 .with('path' => '/etc/apt/sources.list.d/user-ubuntu-foo-trusty.list')
357 .that_notifies('Class[Apt::Update]')
361 context 'with validation' do
362 describe 'no release' do
380 let(:title) { 'ppa:user/foo' }
383 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
387 describe 'not ubuntu' do
405 let(:title) { 'ppa:user/foo' }
408 is_expected.to raise_error(Puppet::Error, %r{not currently supported on Debian})