Merge pull request #215 from vrtdev/bugfix/MODULES-4368-java_default_home-invalid-fact

See: https://tickets.puppetlabs.com/browse/MODULES-4368
This commit is contained in:
Hunter Haugen
2017-06-07 16:15:47 -07:00
2 changed files with 11 additions and 1 deletions

View File

@@ -15,7 +15,9 @@ Facter.add(:java_default_home) do
setcode do
if Facter::Util::Resolution.which('readlink')
java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').strip
if java_bin =~ %r(/jre/)
if java_bin.empty?
nil
elsif java_bin =~ %r(/jre/)
java_default_home = File.dirname(File.dirname(File.dirname(java_bin)))
else
java_default_home = File.dirname(File.dirname(java_bin))

View File

@@ -29,6 +29,14 @@ describe Facter::Util::Fact do
end
end
end
context 'returns nil when readlink is present but java is not' do
it do
java_path_output = ""
Facter::Util::Resolution.expects(:which).with("readlink").returns(true)
Facter::Util::Resolution.expects(:exec).with("readlink -e /usr/bin/java").returns(java_path_output)
expect(Facter.value(:java_default_home)).to be_nil
end
end
context 'returns nil when readlink not present' do
it do