Showing with 38 additions and 5 deletions.
  1. +8 −0 CHANGELOG.md
  2. +1 −1 lib/facter/virtualenv_version.rb
  3. +1 −1 metadata.json
  4. +28 −3 spec/unit/facter/virtualenv_version_spec.rb
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v4.1.1](https://github.com/voxpupuli/puppet-python/tree/v4.1.1) (2020-04-30)

[Full Changelog](https://github.com/voxpupuli/puppet-python/compare/v4.1.0...v4.1.1)

**Fixed bugs:**

- Fixes for virtualenv\_version fact when virtualenv \> 20.x [\#537](https://github.com/voxpupuli/puppet-python/pull/537) ([pjonesIDBS](https://github.com/pjonesIDBS))

## [v4.1.0](https://github.com/voxpupuli/puppet-python/tree/v4.1.0) (2020-04-26)

[Full Changelog](https://github.com/voxpupuli/puppet-python/compare/v4.0.0...v4.1.0)
Expand Down
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
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-python",
"version": "4.1.0",
"version": "4.1.1",
"author": "Vox Pupuli",
"summary": "Python Module",
"license": "Apache-2.0",
Expand Down
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