Merge pull request #265 from willmeek/realpath_test_fix
Realpath test fix
This commit is contained in:
@@ -3,24 +3,25 @@
|
||||
# Purpose: get absolute path of java system home
|
||||
#
|
||||
# Resolution:
|
||||
# Uses `readlink` to resolve the path of `/usr/bin/java` then returns subsubdir
|
||||
# Find the real java binary, and return the subsubdir
|
||||
#
|
||||
# Caveats:
|
||||
# Requires readlink
|
||||
# java binary has to be found in $PATH
|
||||
#
|
||||
# Notes:
|
||||
# None
|
||||
Facter.add(:java_default_home) do
|
||||
confine :kernel => 'Linux'
|
||||
confine :kernel => [ 'Linux', 'OpenBSD' ]
|
||||
setcode do
|
||||
if Facter::Util::Resolution.which('readlink')
|
||||
java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').strip
|
||||
if java_bin.empty?
|
||||
nil
|
||||
elsif java_bin =~ %r(/jre/)
|
||||
java_default_home = File.dirname(File.dirname(File.dirname(java_bin)))
|
||||
java_bin = Facter::Util::Resolution.which('java').to_s.strip
|
||||
if java_bin.empty?
|
||||
nil
|
||||
else
|
||||
java_path = File.realpath(java_bin)
|
||||
if java_path =~ %r(/jre/)
|
||||
java_default_home = File.dirname(File.dirname(File.dirname(java_path)))
|
||||
else
|
||||
java_default_home = File.dirname(File.dirname(java_bin))
|
||||
java_default_home = File.dirname(File.dirname(java_path))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# Notes:
|
||||
# None
|
||||
Facter.add(:java_libjvm_path) do
|
||||
confine :kernel => "Linux"
|
||||
confine :kernel => [ "Linux", "OpenBSD" ]
|
||||
setcode do
|
||||
java_default_home = Facter.value(:java_default_home)
|
||||
java_libjvm_file = Dir.glob("#{java_default_home}/jre/lib/**/libjvm.so")
|
||||
|
||||
@@ -21,21 +21,7 @@ Facter.add(:java_version) do
|
||||
# Additionally, facter versions prior to 2.0.1 only support
|
||||
# positive matches, so this needs to be done manually in setcode.
|
||||
setcode do
|
||||
unless [ 'openbsd', 'darwin' ].include? Facter.value(:operatingsystem).downcase
|
||||
version = nil
|
||||
if Facter::Util::Resolution.which('java')
|
||||
Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = $~[1] if /^.+ version \"(.+)\"$/ =~ line }
|
||||
end
|
||||
version
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add(:java_version) do
|
||||
confine :operatingsystem => 'OpenBSD'
|
||||
has_weight 100
|
||||
setcode do
|
||||
Facter::Util::Resolution.with_env("PATH" => '/usr/local/jdk-1.7.0/jre/bin:/usr/local/jre-1.7.0/bin') do
|
||||
unless [ 'darwin' ].include? Facter.value(:operatingsystem).downcase
|
||||
version = nil
|
||||
if Facter::Util::Resolution.which('java')
|
||||
Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = $~[1] if /^.+ version \"(.+)\"$/ =~ line }
|
||||
|
||||
@@ -44,7 +44,7 @@ class java::config ( ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
'OpenBSD', 'FreeBSD', 'Suse': {
|
||||
'FreeBSD', 'Suse': {
|
||||
if $java::use_java_home != undef {
|
||||
file_line { 'java-home-environment':
|
||||
path => '/etc/environment',
|
||||
|
||||
@@ -236,7 +236,7 @@ describe 'java', :type => :class do
|
||||
context 'select jdk for OpenBSD' do
|
||||
let(:facts) { {:osfamily => 'OpenBSD', :architecture => 'x86_64'} }
|
||||
it { is_expected.to contain_package('java').with_name('jdk') }
|
||||
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/local/jdk/') }
|
||||
it { is_expected.to_not contain_file_line('java-home-environment') }
|
||||
end
|
||||
|
||||
context 'select jre for OpenBSD' do
|
||||
|
||||
@@ -1,47 +1,50 @@
|
||||
require "spec_helper"
|
||||
|
||||
def unlink_and_delete(filename)
|
||||
if File.symlink?(filename)
|
||||
File.unlink(filename)
|
||||
end
|
||||
if File.exist?(filename)
|
||||
File.delete(filename)
|
||||
end
|
||||
end
|
||||
|
||||
describe Facter::Util::Fact do
|
||||
before {
|
||||
Facter.clear
|
||||
Facter.fact(:kernel).stubs(:value).returns('Linux')
|
||||
}
|
||||
|
||||
describe "java_default_home" do
|
||||
context 'returns java home path when readlink present' do
|
||||
context 'when java is in HOME/jre/bin/java' do
|
||||
before(:each) {
|
||||
Facter.clear
|
||||
Facter.fact(:kernel).stubs(:value).returns('Linux')
|
||||
}
|
||||
|
||||
context 'returns java home path when java found in PATH' do
|
||||
context "when java is in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java" do
|
||||
it do
|
||||
java_path_output = <<-EOS
|
||||
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
|
||||
EOS
|
||||
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 eql "/usr/lib/jvm/java-7-openjdk-amd64"
|
||||
unlink_and_delete('./java_test')
|
||||
File.symlink('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java', './java_test')
|
||||
Facter::Util::Resolution.expects(:which).with("java").returns("./java_test")
|
||||
File.expects(:realpath).with('./java_test').returns('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java')
|
||||
expect(Facter.value(:java_default_home)).to eql '/usr/lib/jvm/java-7-openjdk-amd64'
|
||||
unlink_and_delete('./java_test')
|
||||
end
|
||||
end
|
||||
context 'when java is in HOME/bin/java' do
|
||||
|
||||
context "when java is in /usr/lib/jvm/oracle-java8-jre-amd64/bin/java" do
|
||||
it do
|
||||
java_path_output = <<-EOS
|
||||
/usr/lib/jvm/oracle-java8-jre-amd64/bin/java
|
||||
EOS
|
||||
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 eql "/usr/lib/jvm/oracle-java8-jre-amd64"
|
||||
unlink_and_delete('./java_test')
|
||||
File.symlink('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java', './java_test')
|
||||
Facter::Util::Resolution.expects(:which).with("java").returns("./java_test")
|
||||
File.expects(:realpath).with('./java_test').returns('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java')
|
||||
expect(Facter.value(:java_default_home)).to eql '/usr/lib/jvm/oracle-java8-jre-amd64'
|
||||
unlink_and_delete('./java_test')
|
||||
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
|
||||
context 'returns nil when java not present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("readlink").at_least(1).returns(false)
|
||||
Facter::Util::Resolution.expects(:which).with("java").at_least(1).returns(false)
|
||||
expect(Facter.value(:java_default_home)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ describe Facter::Util::Fact do
|
||||
|
||||
describe "java_version" do
|
||||
context 'returns java version when java present' do
|
||||
context 'on OpenBSD', :with_env => true do
|
||||
context 'on OpenBSD' do
|
||||
before do
|
||||
Facter.fact(:operatingsystem).stubs(:value).returns("OpenBSD")
|
||||
end
|
||||
@@ -61,7 +61,7 @@ Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
|
||||
end
|
||||
|
||||
context 'returns nil when java not present' do
|
||||
context 'on OpenBSD', :with_env => true do
|
||||
context 'on OpenBSD' do
|
||||
before do
|
||||
Facter.fact(:operatingsystem).stubs(:value).returns("OpenBSD")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user