Merge pull request #461 from rjd1/main

(MODULES-10935) - Switch legacy operatingsystem fact to modern kernel one
This commit is contained in:
Paula Muir
2021-02-17 09:21:19 +00:00
committed by GitHub
2 changed files with 6 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ Facter.add(:java_version) do
# Additionally, facter versions prior to 2.0.1 only support # Additionally, facter versions prior to 2.0.1 only support
# positive matches, so this needs to be done manually in setcode. # positive matches, so this needs to be done manually in setcode.
setcode do setcode do
unless ['darwin'].include? Facter.value(:operatingsystem).downcase unless ['darwin'].include? Facter.value(:kernel).downcase
version = nil version = nil
if Facter::Util::Resolution.which('java') if Facter::Util::Resolution.which('java')
Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line } Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line }
@@ -34,7 +34,7 @@ Facter.add(:java_version) do
end end
Facter.add(:java_version) do Facter.add(:java_version) do
confine operatingsystem: 'Darwin' confine kernel: 'Darwin'
has_weight 100 has_weight 100
setcode do setcode do
unless Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1').include?('Unable to find any JVMs matching version') unless Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1').include?('Unable to find any JVMs matching version')

View File

@@ -32,9 +32,9 @@ describe 'java_version' do
end end
context 'when on Darwin' do context 'when on Darwin' do
before(:each) do before(:each) do
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin') allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin')
end end
let(:facts) { { operatingsystem: 'Darwin' } } let(:facts) { { kernel: 'Darwin' } }
it do it do
expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').and_return('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home') expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').and_return('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home')
@@ -71,9 +71,9 @@ describe 'java_version' do
end end
context 'when on Darwin' do context 'when on Darwin' do
before(:each) do before(:each) do
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin') allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin')
end end
let(:facts) { { operatingsystem: 'Darwin' } } let(:facts) { { kernel: 'Darwin' } }
it do it do
expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').at_least(1).and_return('Unable to find any JVMs matching version "(null)".') expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').at_least(1).and_return('Unable to find any JVMs matching version "(null)".')