Skip to content

Commit

Permalink
Merge pull request #607 from brabiega/patch-1
Browse files Browse the repository at this point in the history
Use $real_pkgname for pip uninstall command
  • Loading branch information
bastelfreak authored Apr 28, 2021
2 parents 7dd4543 + f36ea4a commit 50886bf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@

default: {
# Anti-action, uninstall.
$command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}"
$command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${real_pkgname}"
$unless_command = "! ${pip_env} list | grep -i -e '${grep_regex}'"
}
}
Expand Down
75 changes: 75 additions & 0 deletions spec/acceptance/pip_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'spec_helper_acceptance'

describe 'python::pip defined resource' do
context 'install package with custom name' do
it 'works with no errors' do
pp = <<-PUPPET
class { 'python':
version => '3',
dev => 'present',
}
python::pyvenv { '/opt/test-venv':
ensure => 'present',
systempkgs => false,
mode => '0755',
pip_version => '<= 20.3.4',
}
python::pip { 'agent package':
virtualenv => '/opt/test-venv',
pkgname => 'agent',
ensure => '0.1.2',
}
PUPPET

apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
end

describe command('/opt/test-venv/bin/pip list') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{agent.* 0\.1\.2} }
end

context 'uninstall package with custom name' do
it 'works with no errors' do
pp = <<-PUPPET
class { 'python':
version => '3',
dev => 'present',
}
python::pyvenv { '/opt/test-venv':
ensure => 'present',
systempkgs => false,
mode => '0755',
pip_version => '<= 20.3.4',
}
python::pip { 'agent package install':
ensure => '0.1.2',
pkgname => 'agent',
virtualenv => '/opt/test-venv',
}
python::pip { 'agent package uninstall custom pkgname':
ensure => 'absent',
pkgname => 'agent',
virtualenv => '/opt/test-venv',
require => Python::Pip['agent package install'],
}
PUPPET

apply_manifest(pp, catch_failures: true)
end
end

describe command('/opt/test-venv/bin/pip list') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.not_to match %r{agent.* 0\.1\.2} }
end
end

8 changes: 8 additions & 0 deletions spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@

it { is_expected.to contain_exec('pip_uninstall_rpyc').with_command(%r{uninstall.*rpyc$}) }
end

context 'passes correct package name' do
let(:params) { { ensure: 'absent', 'pkgname': 'r-pyc' } }

it { is_expected.not_to contain_exec('pip_install_rpyc') }

it { is_expected.to contain_exec('pip_uninstall_rpyc').with_command(%r{uninstall.*r-pyc$}) }
end
end
end
end
Expand Down

0 comments on commit 50886bf

Please sign in to comment.