-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PUP-1691) (WIP) chocolateyversion fact
- Loading branch information
1 parent
72e67c3
commit 125491f
Showing
6 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'facter/util/resolution' | ||
|
||
Facter.add('chocolateyversion') do | ||
setcode do | ||
value = nil | ||
|
||
choco_path = "#{Facter.value(:choco_install_path)}\\bin\\choco.exe" | ||
if Puppet::Util::Platform.windows? && File.exist?(choco_path) | ||
begin | ||
old_choco_message = 'Please run chocolatey /? or chocolatey help - chocolatey v' | ||
#Facter::Core::Execution.exec is 2.0.1 forward | ||
value = Facter::Util::Resolution.exec("#{choco_path} -v").gsub(old_choco_message,'').strip | ||
rescue StandardError => e | ||
value = '0' | ||
end | ||
end | ||
|
||
value || '0' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'facter' | ||
require 'rspec/its' | ||
|
||
describe 'chocolateyversion fact' do | ||
subject(:fact) { Facter.fact(:chocolateyversion) } | ||
|
||
context 'on Windows', :if => Puppet::Util::Platform.windows? do | ||
it "should return the value from running choco -v" do | ||
expected_value = '1.2.3' | ||
Facter::Util::Resolution.expects(:exec).returns(expected_value) | ||
|
||
subject.value.must == expected_value | ||
end | ||
|
||
it "should handle cleaning up spaces" do | ||
expected_value = '1.2.3' | ||
Facter::Util::Resolution.expects(:exec).returns(' ' + expected_value + ' ') | ||
|
||
subject.value.must == expected_value | ||
end | ||
|
||
it "should handle older versions of choco" do | ||
expected_value = '1.2.3' | ||
Facter::Util::Resolution.expects(:exec).returns('Please run chocolatey /? or chocolatey help - chocolatey v' + expected_value) | ||
|
||
subject.value.must == expected_value | ||
end | ||
end | ||
|
||
context 'on Linux', :if => Puppet.features.posix? do | ||
its(:value) { should eql('0') } | ||
end | ||
|
||
after :each do | ||
Facter.clear | ||
Facter.clear_messages | ||
end | ||
end |