X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fdefines%2Fppa_spec.rb;h=74265cde99bbc5376ec31962f70d42cf862e3bb5;hb=58265f32854aaaa03d1abb83c1511563a2879e0b;hp=b5aadff31a5e211994c6a3eea770989b6d870357;hpb=1192618d075d30a8131f8cfff6af79f42c85d6a3;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index b5aadff..74265cd 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -1,6 +1,15 @@ # frozen_string_literal: true require 'spec_helper' + +def ppa_exec_params(user, repo, distro = 'trusty', environment = []) + [ + environment: environment, + command: "/opt/puppetlabs/puppet/cache/add-apt-repository-#{user}-ubuntu-#{repo}-#{distro}.sh", + logoutput: 'on_failure', + ] +end + describe 'apt::ppa' do let :pre_condition do 'class { "apt": }' @@ -21,18 +30,17 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end - let(:title) { 'ppa:needs/such.substitution/wow+type' } + let(:title) { 'ppa:needs/substitution' } it { is_expected.not_to contain_package('python-software-properties') } it { - is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with(environment: [], - command: '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type || (rm /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow_type-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow_type-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs_ubuntu_such_substitution-wow_type.gpg', # rubocop:disable Layout/LineLength - user: 'root', - logoutput: 'on_failure') + is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('needs', 'substitution')) } end @@ -51,17 +59,16 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache', } end let(:title) { 'ppa:user/foo' } it { - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [], - command: '/usr/bin/add-apt-repository -y ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength - user: 'root', - logoutput: 'on_failure') + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('user', 'foo', 'wily')) } end @@ -69,12 +76,14 @@ describe 'apt::ppa' do let :pre_condition do 'class { "apt": }' end + let :params do { package_name: 'software-properties-common', package_manage: true, } end + let :facts do { os: { @@ -89,22 +98,17 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache', } end - let(:title) { 'ppa:needs/such.substitution/wow' } + let(:title) { 'ppa:needs/substitution' } it { is_expected.to contain_package('software-properties-common') } it { - is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [], - 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow || (rm /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list && false)', # rubocop:disable Layout/LineLength - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs_ubuntu_such_substitution-wow.gpg', # rubocop:disable Layout/LineLength - 'user' => 'root', - 'logoutput' => 'on_failure') - } - - it { - is_expected.to contain_file('/etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file') # rubocop:disable Layout/LineLength + is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('needs', 'substitution')) } end @@ -112,6 +116,7 @@ describe 'apt::ppa' do let :pre_condition do 'class { "apt": }' end + let :facts do { os: { @@ -126,27 +131,23 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache', } end + let :params do { package_manage: false, } end - let(:title) { 'ppa:needs/such.substitution/wow' } + let(:title) { 'ppa:needs/substitution' } it { is_expected.not_to contain_package('python-software-properties') } it { - is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [], - 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow || (rm /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list && false)', # rubocop:disable Layout/LineLength - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs_ubuntu_such_substitution-wow.gpg', # rubocop:disable Layout/LineLength - 'user' => 'root', - 'logoutput' => 'on_failure') - } - - it { - is_expected.to contain_file('/etc/apt/sources.list.d/needs-ubuntu-such_substitution-wow-trusty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file') # rubocop:disable Layout/LineLength + is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('needs', 'substitution')) } end @@ -156,6 +157,7 @@ describe 'apt::ppa' do apt::ppa { "ppa:user/foo2": } ' end + let :facts do { os: { @@ -170,25 +172,25 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache', } end + let :params do { - options: '', package_manage: true, require: 'Apt::Ppa[ppa:user/foo2]', } end + let(:title) { 'ppa:user/foo' } it { is_expected.to compile.with_all_deps } it { is_expected.to contain_package('software-properties-common') } it { - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [], - command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength - user: 'root', - logoutput: 'on_failure') + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('user', 'foo')) } end @@ -198,6 +200,7 @@ describe 'apt::ppa' do proxy => { "host" => "localhost" }, }' end + let :facts do { os: { @@ -212,23 +215,23 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache', } end + let :params do { - 'options' => '', 'package_manage' => true, } end + let(:title) { 'ppa:user/foo' } it { is_expected.to contain_package('software-properties-common') } it { - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8080'], - command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength - user: 'root', - logoutput: 'on_failure') + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8080'])) } end @@ -238,6 +241,7 @@ describe 'apt::ppa' do proxy => { "host" => "localhost", "port" => 8180 }, }' end + let :facts do { os: { @@ -252,23 +256,23 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache', } end + let :params do { - options: '', package_manage: true, } end + let(:title) { 'ppa:user/foo' } it { is_expected.to contain_package('software-properties-common') } it { - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180'], - command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength - user: 'root', - logoutput: 'on_failure') + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180'])) } end @@ -278,6 +282,7 @@ describe 'apt::ppa' do proxy => { "host" => "localhost", "port" => 8180, "https" => true }, }' end + let :facts do { os: { @@ -292,23 +297,23 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache', } end + let :params do { - options: '', package_manage: true, } end + let(:title) { 'ppa:user/foo' } it { is_expected.to contain_package('software-properties-common') } it { - is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'], - command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Layout/LineLength - user: 'root', - logoutput: 'on_failure') + is_expected.to contain_exec('add-apt-repository-ppa:user/foo') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'])) } end @@ -316,6 +321,7 @@ describe 'apt::ppa' do let :pre_condition do 'class { "apt": }' end + let :facts do { os: { @@ -330,9 +336,12 @@ describe 'apt::ppa' do id: 'Ubuntu', }, }, + puppet_vardir: '/opt/puppetlabs/puppet/cache', } end + let(:title) { 'ppa:user/foo' } + let :params do { ensure: 'absent', @@ -340,7 +349,12 @@ describe 'apt::ppa' do end it { - is_expected.to contain_file('/etc/apt/sources.list.d/user-ubuntu-foo-trusty.list').that_notifies('Class[Apt::Update]').with(ensure: 'absent') + is_expected.to contain_tidy("remove-apt-repository-script-#{title}") + .with('path' => '/opt/puppetlabs/puppet/cache/add-apt-repository-user-ubuntu-foo-trusty.sh') + + is_expected.to contain_tidy("remove-apt-repository-#{title}") + .with('path' => '/etc/apt/sources.list.d/user-ubuntu-foo-trusty.list') + .that_notifies('Class[Apt::Update]') } end @@ -362,6 +376,7 @@ describe 'apt::ppa' do }, } end + let(:title) { 'ppa:user/foo' } it do @@ -386,6 +401,7 @@ describe 'apt::ppa' do }, } end + let(:title) { 'ppa:user/foo' } it do