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
36 let(:title) { 'ppa:needs/substitution' }
38 it { is_expected.not_to contain_package('python-software-properties') }
40 is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
41 .that_notifies('Class[Apt::Update]')
42 .with(*ppa_exec_params('needs', 'substitution'))
52 describe 'valid resource names' do
72 it { is_expected.not_to raise_error }
73 it { is_expected.to contain_exec("add-apt-repository-#{value}") }
83 '|| touch /tmp/foo.txt ||',
85 describe 'invalid resource names' do
103 let(:title) { value }
105 it { is_expected.to raise_error(Puppet::PreformattedError, %r{Invalid PPA name: #{value}}) }
109 describe 'Ubuntu 15.10 sources.list filename' do
127 let(:title) { 'ppa:user/foo' }
130 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
131 .that_notifies('Class[Apt::Update]')
132 .with(*ppa_exec_params('user', 'foo', 'wily'))
136 describe 'package_name => software-properties-common' do
137 let :pre_condition do
143 package_name: 'software-properties-common',
144 package_manage: true,
165 let(:title) { 'ppa:needs/substitution' }
167 it { is_expected.to contain_package('software-properties-common') }
169 is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
170 .that_notifies('Class[Apt::Update]')
171 .with(*ppa_exec_params('needs', 'substitution'))
175 describe 'package_manage => false' do
176 let :pre_condition do
199 package_manage: false,
203 let(:title) { 'ppa:needs/substitution' }
205 it { is_expected.not_to contain_package('python-software-properties') }
207 is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution')
208 .that_notifies('Class[Apt::Update]')
209 .with(*ppa_exec_params('needs', 'substitution'))
213 describe 'apt included, no proxy' do
214 let :pre_condition do
216 apt::ppa { "ppa:user/foo2": }
239 package_manage: true,
240 require: 'Apt::Ppa[ppa:user/foo2]',
244 let(:title) { 'ppa:user/foo' }
246 it { is_expected.to compile.with_all_deps }
247 it { is_expected.to contain_package('software-properties-common') }
249 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
250 .that_notifies('Class[Apt::Update]')
251 .with(*ppa_exec_params('user', 'foo'))
255 describe 'apt included, proxy host' do
256 let :pre_condition do
258 proxy => { "host" => "localhost" },
281 'package_manage' => true,
285 let(:title) { 'ppa:user/foo' }
287 it { is_expected.to contain_package('software-properties-common') }
289 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
290 .that_notifies('Class[Apt::Update]')
291 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8080']))
295 describe 'apt included, proxy host and port' do
296 let :pre_condition do
298 proxy => { "host" => "localhost", "port" => 8180 },
321 package_manage: true,
325 let(:title) { 'ppa:user/foo' }
327 it { is_expected.to contain_package('software-properties-common') }
329 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
330 .that_notifies('Class[Apt::Update]')
331 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180']))
335 describe 'apt included, proxy host and port and https' do
336 let :pre_condition do
338 proxy => { "host" => "localhost", "port" => 8180, "https" => true },
361 package_manage: true,
365 let(:title) { 'ppa:user/foo' }
367 it { is_expected.to contain_package('software-properties-common') }
369 is_expected.to contain_exec('add-apt-repository-ppa:user/foo')
370 .that_notifies('Class[Apt::Update]')
371 .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180']))
375 describe 'ensure absent' do
376 let :pre_condition do
397 let(:title) { 'ppa:user/foo' }
406 is_expected.to contain_tidy("remove-apt-repository-script-#{title}")
407 .with('path' => '/opt/puppetlabs/puppet/cache/add-apt-repository-user-ubuntu-foo-trusty.sh')
409 is_expected.to contain_tidy("remove-apt-repository-#{title}")
410 .with('path' => '/etc/apt/sources.list.d/user-ubuntu-foo-trusty.list')
411 .that_notifies('Class[Apt::Update]')
415 context 'with validation' do
416 describe 'no release' do
434 let(:title) { 'ppa:user/foo' }
437 is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
441 describe 'not ubuntu' do
459 let(:title) { 'ppa:user/foo' }
462 is_expected.to raise_error(Puppet::Error, %r{not currently supported on Debian})