(MODULES-1570) TDD Style - Add specs first
Facter unit tests to check resolution of Java version
This commit is contained in:
31
spec/unit/facter/java_patch_level_spec.rb
Normal file
31
spec/unit/facter/java_patch_level_spec.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe Facter::Util::Fact do
|
||||||
|
before {
|
||||||
|
Facter.clear
|
||||||
|
}
|
||||||
|
|
||||||
|
describe "java_patch_level" do
|
||||||
|
context "if java is installed" do
|
||||||
|
context 'returns java patch version extracted from java_version fact' do
|
||||||
|
before :each do
|
||||||
|
Facter.fact(:java_version).stubs(:value).returns('1.7.0_71')
|
||||||
|
end
|
||||||
|
it do
|
||||||
|
Facter.fact(:java_patch_level).value.should == "71"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "if java is installed" do
|
||||||
|
context 'returns java patch version extracted from java_version fact' do
|
||||||
|
before :each do
|
||||||
|
Facter.fact(:java_version).stubs(:value).returns(nil)
|
||||||
|
end
|
||||||
|
it do
|
||||||
|
Facter.fact(:java_patch_level).value.should == "JAVA_NOT_INSTALLED"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
29
spec/unit/facter/java_version_spec.rb
Normal file
29
spec/unit/facter/java_version_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe Facter::Util::Fact do
|
||||||
|
before {
|
||||||
|
Facter.clear
|
||||||
|
}
|
||||||
|
|
||||||
|
describe "java_version" do
|
||||||
|
context 'returns java version when java present' do
|
||||||
|
it do
|
||||||
|
java_version_output = <<-EOS
|
||||||
|
java version "1.7.0_71"
|
||||||
|
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
|
||||||
|
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
|
||||||
|
EOS
|
||||||
|
Facter::Util::Resolution.expects(:exec).with("java -version 2>&1").returns(java_version_output)
|
||||||
|
Facter.fact(:java_version).value.should == "1.7.0_71"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'returns nil when java not present' do
|
||||||
|
it do
|
||||||
|
java_version_output = "bash: java: command not found"
|
||||||
|
Facter::Util::Resolution.expects(:exec).with("java -version 2>&1").returns(java_version_output)
|
||||||
|
Facter.fact(:java_version).value.should be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user