X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fdefines%2Fppa_spec.rb;h=74265cde99bbc5376ec31962f70d42cf862e3bb5;hb=65e03244552e8113b69f6ca5f4e6dc142251df0b;hp=43ee7541d712d6663f9c68ed33ee50172bf34603;hpb=7e31732abd277c852564c10011099bdf6967dc4f;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 43ee754..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": }' @@ -13,26 +22,25 @@ describe 'apt::ppa' do family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: 'trusty', 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-such_substitution-wow_type-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-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,42 +76,39 @@ 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: { family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: 'trusty', 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-such_substitution-wow-trusty.list && false)', # rubocop:disable Layout/LineLength - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-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-such_substitution-wow-trusty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file') + is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('needs', 'substitution')) } end @@ -112,41 +116,38 @@ describe 'apt::ppa' do let :pre_condition do 'class { "apt": }' end + let :facts do { os: { family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: 'trusty', 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-such_substitution-wow-trusty.list && false)', # rubocop:disable Layout/LineLength - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-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-such_substitution-wow-trusty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file') + is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') + .that_notifies('Class[Apt::Update]') + .with(*ppa_exec_params('needs', 'substitution')) } end @@ -156,39 +157,40 @@ describe 'apt::ppa' do apt::ppa { "ppa:user/foo2": } ' end + let :facts do { os: { family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: 'trusty', 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-foo-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-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,37 +200,38 @@ describe 'apt::ppa' do proxy => { "host" => "localhost" }, }' end + let :facts do { os: { family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: 'trusty', 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-foo-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-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,37 +241,38 @@ describe 'apt::ppa' do proxy => { "host" => "localhost", "port" => 8180 }, }' end + let :facts do { os: { family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: 'trusty', 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-foo-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-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,37 +282,38 @@ describe 'apt::ppa' do proxy => { "host" => "localhost", "port" => 8180, "https" => true }, }' end + let :facts do { os: { family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: 'trusty', 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-foo-trusty.list && false)', # rubocop:disable Layout/LineLength - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-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,23 +321,27 @@ describe 'apt::ppa' do let :pre_condition do 'class { "apt": }' end + let :facts do { os: { family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: 'trusty', 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-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 @@ -352,8 +366,8 @@ describe 'apt::ppa' do family: 'Debian', name: 'Ubuntu', release: { - major: '14', - full: '14.04', + major: '18', + full: '18.04', }, distro: { codename: nil, @@ -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