Skip to content

Commit

Permalink
Add check to ensure regex does not throw for none type.
Browse files Browse the repository at this point in the history
Add a quick check to ensure puppetversion value is not nil and supporting test.
  • Loading branch information
mentat committed Oct 15, 2015
1 parent 57a8485 commit 6aa7f2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/facter/pe_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
#
Facter.add("pe_version") do
setcode do
pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d+\.\d+\.\d+)/)
pe_ver[1] if pe_ver
puppet_ver = Facter.value("puppetversion")
if puppet_ver != nil
pe_ver = puppet_ver.match(/Puppet Enterprise (\d+\.\d+\.\d+)/)
pe_ver[1] if pe_ver
else
nil
end
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/unit/facter/pe_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
Facter.collection.loader.load(:pe_version)
end
end

context "When puppetversion is nil" do
before :each do
Facter.fact(:puppetversion).stubs(:value).returns(nil)
end

it "pe_version is nil" do
expect(Facter.fact(:puppetversion).value).to be_nil
expect(Facter.fact(:pe_version).value).to be_nil
end
end

context "If PE is installed" do
%w{ 2.6.1 2.10.300 }.each do |version|
Expand Down Expand Up @@ -73,4 +84,5 @@
expect(Facter.fact(:pe_patch_version).value).to be_nil
end
end

end

0 comments on commit 6aa7f2d

Please sign in to comment.