Skip to content

Commit

Permalink
Fixes version check for virtualenv_version
Browse files Browse the repository at this point in the history
This should fix issue voxpupuli#534 I've tested locally with success. I've tested against Virtualenv 20.0.4 and 16.7.9.
The output from the fact is only the version number as was previously the case.
  • Loading branch information
pjonesIDBS authored and krissik committed Jul 30, 2020
1 parent 1cc1476 commit dfdf7f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/facter/virtualenv_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Facter.add('virtualenv_version') do
setcode do
if Facter::Util::Resolution.which('virtualenv')
Facter::Util::Resolution.exec('virtualenv --version 2>&1').match(%r{^(\d+\.\d+\.?\d*).*$})[0]
Facter::Util::Resolution.exec('virtualenv --version 2>&1').match(%r{(\d+\.\d+\.?\d*).*$})[1]
end
end
end
31 changes: 28 additions & 3 deletions spec/unit/facter/virtualenv_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
Facter.clear
end

let(:virtualenv_version_output) do
let(:virtualenv_old_version_output) do
<<-EOS
12.0.7
EOS
end

describe 'virtualenv_version' do
let(:virtualenv_new_version_output) do
<<-EOS
virtualenv 20.0.17 from /opt/python/lib/python3.5/site-packages/virtualenv/__init__.py
EOS
end

describe 'virtualenv_version old' do
context 'returns virtualenv version when virtualenv present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with('virtualenv').returns(true)
Facter::Util::Resolution.expects(:exec).with('virtualenv --version 2>&1').returns(virtualenv_version_output)
Facter::Util::Resolution.expects(:exec).with('virtualenv --version 2>&1').returns(virtualenv_old_version_output)
expect(Facter.value(:virtualenv_version)).to eq('12.0.7')
end
end
Expand All @@ -29,4 +35,23 @@
end
end
end

describe 'virtualenv_version new' do
context 'returns virtualenv version when virtualenv present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with('virtualenv').returns(true)
Facter::Util::Resolution.expects(:exec).with('virtualenv --version 2>&1').returns(virtualenv_new_version_output)
expect(Facter.value(:virtualenv_version)).to eq('20.0.17')
end
end

context 'returns nil when virtualenv not present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with('virtualenv').returns(false)
expect(Facter.value(:virtualenv_version)).to eq(nil)
end
end
end
end

0 comments on commit dfdf7f9

Please sign in to comment.