do not use unportable readlink utility to find the java_default_home,
use Ruby in a more portable fashion. adapt tests as well
This commit is contained in:
committed by
Will Meek
parent
bdfc567c18
commit
e50eb64614
@@ -1,47 +1,43 @@
|
||||
require "spec_helper"
|
||||
|
||||
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"
|
||||
File.delete('./java') if File.exist?('./java')
|
||||
File.symlink('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java', './java')
|
||||
Facter::Util::Resolution.expects(:which).with("java").returns("./java")
|
||||
expect(File.readlink('./java')).to eq('/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'
|
||||
File.delete('./java') if File.exist?('./java')
|
||||
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"
|
||||
File.delete('./java') if File.exist?('./java')
|
||||
File.symlink('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java', './java')
|
||||
Facter::Util::Resolution.expects(:which).with("java").returns("./java")
|
||||
expect(File.readlink('./java')).to eq('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java')
|
||||
expect(Facter.value(:java_default_home)).to eql '/usr/lib/jvm/oracle-java8-jre-amd64'
|
||||
File.delete('./java') if File.exist?('./java')
|
||||
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