(FM-7795) Cleanup java tests (#350)
* Add idempotent_apply function * Remove unsupported OS specific code * Remove outdated comments * Improve unit test coverage * Fix typo
This commit is contained in:
@@ -2,32 +2,6 @@ require 'spec_helper_acceptance'
|
||||
|
||||
include Unix::File
|
||||
|
||||
# RedHat, CentOS, Scientific, Oracle prior to 5.0 : Sun Java JDK/JRE 1.6
|
||||
# RedHat, CentOS, Scientific, Oracle 5.0 < x < 6.3 : OpenJDK Java JDK/JRE 1.6
|
||||
# RedHat, CentOS, Scientific, Oracle after 6.3 : OpenJDK Java JDK/JRE 1.7
|
||||
# Debian Jesse & Ubuntu 14.04 : OpenJDK Java JDK/JRE 1.7 or Oracle Java JDK/JRE 1.6
|
||||
# Solaris (what versions?) : Java JDK/JRE 1.7
|
||||
# OpenSuSE : OpenJDK Java JDK/JRE 1.7
|
||||
# SLES : IBM Java JDK/JRE 1.6
|
||||
|
||||
# C14677
|
||||
# C14678
|
||||
# C14679
|
||||
# C14680
|
||||
# C14681
|
||||
# C14682
|
||||
# C14684
|
||||
# C14687
|
||||
# C14692
|
||||
# C14696
|
||||
# C14697
|
||||
# C14700 check on solaris 11
|
||||
# C14701 check on sles 11
|
||||
# C14703
|
||||
# C14723 Where is oracle linux 5?
|
||||
# C14724 Where is oracle linux 5?
|
||||
# C14771 Where is redhat 7? Centos 7?
|
||||
|
||||
java_class_jre = "class { 'java':\n"\
|
||||
" distribution => 'jre',\n"\
|
||||
'}'
|
||||
@@ -56,10 +30,6 @@ oracle_jdk = "class { 'java':\n"\
|
||||
" distribution => 'oracle-jdk',\n"\
|
||||
'}'
|
||||
|
||||
incorrect_version = "class { 'java':\n"\
|
||||
" version => '14.5',\n"\
|
||||
'}'
|
||||
|
||||
blank_version = "class { 'java':\n"\
|
||||
" version => '',\n"\
|
||||
'}'
|
||||
@@ -91,7 +61,7 @@ oracle_version_minor = '201'
|
||||
oracle_version_build = '09'
|
||||
oracle_hash = '42970487e3af4f5aa5bca3f542482c60'
|
||||
|
||||
install_oracle_jre = <<EOL
|
||||
install_oracle_jdk_jre = <<EOL
|
||||
java::oracle {
|
||||
'test_oracle_jre':
|
||||
version => '#{oracle_version_major}',
|
||||
@@ -100,9 +70,6 @@ install_oracle_jre = <<EOL
|
||||
url_hash => '#{oracle_hash}',
|
||||
java_se => 'jre',
|
||||
}
|
||||
EOL
|
||||
|
||||
install_oracle_jdk = <<EOL
|
||||
java::oracle {
|
||||
'test_oracle_jdk':
|
||||
version => '#{oracle_version_major}',
|
||||
@@ -123,6 +90,7 @@ install_oracle_jre_jce = <<EOL
|
||||
java_se => 'jre',
|
||||
jce => true,
|
||||
}
|
||||
|
||||
EOL
|
||||
|
||||
install_oracle_jdk_jce = <<EOL
|
||||
@@ -139,21 +107,16 @@ EOL
|
||||
|
||||
context 'installing java jre', unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'installs jre' do
|
||||
apply_manifest(java_class_jre, catch_failures: true)
|
||||
apply_manifest(java_class_jre, catch_changes: true)
|
||||
idempotent_apply(default, java_class_jre)
|
||||
end
|
||||
end
|
||||
|
||||
context 'installing java jdk', unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'installs jdk' do
|
||||
apply_manifest(java_class, catch_failures: true)
|
||||
apply_manifest(java_class, catch_changes: true)
|
||||
idempotent_apply(default, java_class)
|
||||
end
|
||||
end
|
||||
|
||||
# C14704
|
||||
# C14705
|
||||
# C15006
|
||||
context 'oracle', if: (
|
||||
(fact('operatingsystem') == 'Ubuntu') && fact('operatingsystemrelease').match(%r{^14\.04})
|
||||
) do
|
||||
@@ -174,37 +137,22 @@ context 'oracle', if: (
|
||||
end
|
||||
|
||||
context 'with failure cases' do
|
||||
# C14711
|
||||
# SLES 10 returns an exit code of 0 on zypper failure
|
||||
unless fact('operatingsystem') == 'SLES' && fact('operatingsystemrelease') < '11'
|
||||
it 'fails to install java with an incorrect version' do
|
||||
apply_manifest(incorrect_version, expect_failures: true)
|
||||
end
|
||||
end
|
||||
|
||||
# C14712
|
||||
it 'fails to install java with a blank version' do
|
||||
apply_manifest(blank_version, expect_failures: true)
|
||||
end
|
||||
|
||||
# C14713
|
||||
it 'fails to install java with an incorrect distribution' do
|
||||
apply_manifest(incorrect_distro, expect_failures: true)
|
||||
end
|
||||
|
||||
# C14714
|
||||
it 'fails to install java with a blank distribution' do
|
||||
apply_manifest(blank_distro, expect_failures: true)
|
||||
end
|
||||
|
||||
# C14715
|
||||
it 'fails to install java with an incorrect package' do
|
||||
apply_manifest(incorrect_package, expect_failures: true)
|
||||
end
|
||||
|
||||
# C14717
|
||||
# C14719
|
||||
# C14725
|
||||
it 'fails on debian or RHEL when passed fake java_alternative and path' do
|
||||
if fact('osfamily') == 'Debian' || fact('osfamily') == 'RedHat'
|
||||
apply_manifest(bogus_alternative, expect_failures: true)
|
||||
@@ -214,35 +162,31 @@ context 'with failure cases' do
|
||||
end
|
||||
end
|
||||
|
||||
# Test oracle java installs
|
||||
context 'java::oracle', if: oracle_enabled, unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
install_path = '/usr/lib/jvm'
|
||||
version_suffix = ''
|
||||
if fact('osfamily') == 'RedHat' || fact('osfamily') == 'Amazon'
|
||||
install_path = '/usr/java'
|
||||
version_suffix = '-amd64'
|
||||
let(:install_path) do
|
||||
(fact('osfamily') == 'RedHat') ? '/usr/java' : '/usr/lib/jvm'
|
||||
end
|
||||
it 'installs oracle jdk' do
|
||||
apply_manifest(install_oracle_jdk, catch_failures: true)
|
||||
apply_manifest(install_oracle_jdk, catch_changes: true)
|
||||
result = shell("test ! -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar")
|
||||
expect(result.exit_code).to eq(0)
|
||||
|
||||
let(:version_suffix) do
|
||||
(fact('osfamily') == 'RedHat') ? '-amd64' : ''
|
||||
end
|
||||
it 'installs oracle jre' do
|
||||
apply_manifest(install_oracle_jre, catch_failures: true)
|
||||
apply_manifest(install_oracle_jre, catch_changes: true)
|
||||
result = shell("test ! -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar")
|
||||
expect(result.exit_code).to eq(0)
|
||||
|
||||
it 'installs oracle jdk and jre' do
|
||||
idempotent_apply(default, install_oracle_jdk_jre)
|
||||
jdk_result = shell("test ! -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar")
|
||||
jre_result = shell("test ! -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar")
|
||||
expect(jdk_result.exit_code).to eq(0)
|
||||
expect(jre_result.exit_code).to eq(0)
|
||||
end
|
||||
|
||||
it 'installs oracle jdk with jce' do
|
||||
apply_manifest(install_oracle_jdk_jce, catch_failures: true)
|
||||
apply_manifest(install_oracle_jdk_jce, catch_changes: true)
|
||||
idempotent_apply(default, install_oracle_jdk_jce)
|
||||
result = shell("test -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar")
|
||||
expect(result.exit_code).to eq(0)
|
||||
end
|
||||
|
||||
it 'installs oracle jre with jce' do
|
||||
apply_manifest(install_oracle_jre_jce, catch_failures: true)
|
||||
apply_manifest(install_oracle_jre_jce, catch_changes: true)
|
||||
idempotent_apply(default, install_oracle_jre_jce)
|
||||
result = shell("test -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar")
|
||||
expect(result.exit_code).to eq(0)
|
||||
end
|
||||
|
||||
@@ -53,20 +53,20 @@ describe 'java', type: :class do
|
||||
it { is_expected.not_to contain_exec('update-java-alternatives') }
|
||||
end
|
||||
|
||||
context 'when select jdk for Ubuntu Vivid (15.04)' do
|
||||
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistcodename: 'vivid', operatingsystemrelease: '15.04', architecture: 'amd64' } }
|
||||
context 'when select jdk for Ubuntu Trusty (14.04)' do
|
||||
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistcodename: 'trusty', operatingsystemrelease: '14.04', architecture: 'amd64' } }
|
||||
let(:params) { { 'distribution' => 'jdk' } }
|
||||
|
||||
it { is_expected.to contain_package('java').with_name('openjdk-8-jdk') }
|
||||
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/') }
|
||||
it { is_expected.to contain_package('java').with_name('openjdk-7-jdk') }
|
||||
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64/') }
|
||||
end
|
||||
|
||||
context 'when select jre for Ubuntu Vivid (15.04)' do
|
||||
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistcodename: 'vivid', operatingsystemrelease: '15.04', architecture: 'amd64' } }
|
||||
context 'when select jre for Ubuntu Trusty (14.04)' do
|
||||
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistcodename: 'trusty', operatingsystemrelease: '14.04', architecture: 'amd64' } }
|
||||
let(:params) { { 'distribution' => 'jre' } }
|
||||
|
||||
it { is_expected.to contain_package('java').with_name('openjdk-8-jre-headless') }
|
||||
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/') }
|
||||
it { is_expected.to contain_package('java').with_name('openjdk-7-jre-headless') }
|
||||
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64/') }
|
||||
end
|
||||
|
||||
context 'when select jdk for Ubuntu xenial (16.04) on ARM' do
|
||||
@@ -85,20 +85,6 @@ describe 'java', type: :class do
|
||||
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-arm64/') }
|
||||
end
|
||||
|
||||
context 'when select openjdk for Amazon Linux' do
|
||||
let(:facts) { { osfamily: 'RedHat', operatingsystem: 'Amazon', operatingsystemrelease: '3.4.43-43.43.amzn1.x86_64', architecture: 'x86_64' } }
|
||||
|
||||
it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk-devel') }
|
||||
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-x86_64/') }
|
||||
end
|
||||
|
||||
context 'when select passed value for Amazon Linux' do
|
||||
let(:facts) { { osfamily: 'RedHat', operatingsystem: 'Amazon', operatingsystemrelease: '5.3.4.43-43.43.amzn1.x86_64', architecture: 'x86_64' } }
|
||||
let(:params) { { 'distribution' => 'jre' } }
|
||||
|
||||
it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') }
|
||||
end
|
||||
|
||||
context 'when select openjdk for Oracle Linux' do
|
||||
let(:facts) { { osfamily: 'RedHat', operatingsystem: 'OracleLinux', operatingsystemrelease: '6.4', architecture: 'x86_64' } }
|
||||
|
||||
@@ -169,20 +155,6 @@ describe 'java', type: :class do
|
||||
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/') }
|
||||
end
|
||||
|
||||
context 'when 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.not_to contain_file_line('java-home-environment') }
|
||||
end
|
||||
|
||||
context 'when select jre for OpenBSD' do
|
||||
let(:facts) { { osfamily: 'OpenBSD', architecture: 'x86_64' } }
|
||||
let(:params) { { 'distribution' => 'jre' } }
|
||||
|
||||
it { is_expected.to contain_package('java').with_name('jre') }
|
||||
end
|
||||
|
||||
describe 'custom java package' do
|
||||
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Debian', lsbdistcodename: 'jessie', operatingsystemrelease: '8.6', architecture: 'amd64' } }
|
||||
|
||||
@@ -218,31 +190,26 @@ describe 'java', type: :class do
|
||||
describe 'incompatible OSs' do
|
||||
[
|
||||
{
|
||||
# C14706
|
||||
osfamily: 'windows',
|
||||
operatingsystem: 'windows',
|
||||
operatingsystemrelease: '8.1',
|
||||
},
|
||||
{
|
||||
# C14707
|
||||
osfamily: 'Darwin',
|
||||
operatingsystem: 'Darwin',
|
||||
operatingsystemrelease: '13.3.0',
|
||||
},
|
||||
{
|
||||
# C14708
|
||||
osfamily: 'AIX',
|
||||
operatingsystem: 'AIX',
|
||||
operatingsystemrelease: '7100-02-00-000',
|
||||
},
|
||||
{
|
||||
# C14708
|
||||
osfamily: 'AIX',
|
||||
operatingsystem: 'AIX',
|
||||
operatingsystemrelease: '6100-07-04-1216',
|
||||
},
|
||||
{
|
||||
# C14708
|
||||
osfamily: 'AIX',
|
||||
operatingsystem: 'AIX',
|
||||
operatingsystemrelease: '5300-12-01-1016',
|
||||
|
||||
@@ -398,7 +398,6 @@ describe 'java::oracle', type: :define do
|
||||
describe 'incompatible OSes' do
|
||||
[
|
||||
{
|
||||
# C14706
|
||||
kernel: 'Windows',
|
||||
os: {
|
||||
family: 'Windows',
|
||||
@@ -409,7 +408,6 @@ describe 'java::oracle', type: :define do
|
||||
},
|
||||
},
|
||||
{
|
||||
# C14707
|
||||
kernel: 'Darwin',
|
||||
os: {
|
||||
family: 'Darwin',
|
||||
@@ -420,7 +418,6 @@ describe 'java::oracle', type: :define do
|
||||
},
|
||||
},
|
||||
{
|
||||
# C14708
|
||||
kernel: 'AIX',
|
||||
os: {
|
||||
family: 'AIX',
|
||||
@@ -431,7 +428,6 @@ describe 'java::oracle', type: :define do
|
||||
},
|
||||
},
|
||||
{
|
||||
# C14709
|
||||
kernel: 'AIX',
|
||||
os: {
|
||||
family: 'AIX',
|
||||
@@ -442,7 +438,6 @@ describe 'java::oracle', type: :define do
|
||||
},
|
||||
},
|
||||
{
|
||||
# C14710
|
||||
kernel: 'AIX',
|
||||
os: {
|
||||
family: 'AIX',
|
||||
|
||||
@@ -21,3 +21,17 @@ RSpec.configure do |c|
|
||||
# Readable test descriptions
|
||||
c.formatter = :documentation
|
||||
end
|
||||
|
||||
def idempotent_apply(hosts, manifest, opts = {}, &block)
|
||||
block_on hosts, opts do |host|
|
||||
file_path = host.tmpfile('apply_manifest.pp')
|
||||
create_remote_file(host, file_path, manifest + "\n")
|
||||
|
||||
puppet_apply_opts = { :verbose => nil, 'detailed-exitcodes' => nil }
|
||||
on_options = { acceptable_exit_codes: [0, 2] }
|
||||
on host, puppet('apply', file_path, puppet_apply_opts), on_options, &block
|
||||
puppet_apply_opts2 = { :verbose => nil, 'detailed-exitcodes' => nil }
|
||||
on_options2 = { acceptable_exit_codes: [0] }
|
||||
on host, puppet('apply', file_path, puppet_apply_opts2), on_options2, &block
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ describe 'java_default_home' do
|
||||
context 'when java not present, return nil' do
|
||||
it do
|
||||
allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
|
||||
expect(Facter::Util::Resolution).to receive(:which).with('java').at_least(1).and_return(false)
|
||||
expect(Facter::Util::Resolution).to receive(:which).with('java').at_least(1).and_return(nil)
|
||||
expect(Facter.value(:java_default_home)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'java_libjvm_path' do
|
||||
let(:java_default_home) { '/usr/lib/jvm/java-8-openjdk-amd64' }
|
||||
|
||||
before(:each) do
|
||||
Facter.clear
|
||||
allow(Facter.fact(:kernel)).to receive(:value).once.and_return('Linux')
|
||||
java_default_home = '/usr/lib/jvm/java-8-openjdk-amd64'
|
||||
allow(Facter.fact(:java_default_home)).to receive(:value).once.and_return(java_default_home)
|
||||
allow(Dir).to receive(:glob).with("#{java_default_home}/jre/lib/**/libjvm.so").and_return(['/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so'])
|
||||
end
|
||||
|
||||
context 'when on Linux, return libjvm path' do
|
||||
context 'when libjvm exists' do
|
||||
it do
|
||||
allow(Dir).to receive(:glob).with("#{java_default_home}/jre/lib/**/libjvm.so").and_return(['/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so'])
|
||||
expect(Facter.value(:java_libjvm_path)).to eql '/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when libjvm does not exist' do
|
||||
it do
|
||||
allow(Dir).to receive(:glob).with("#{java_default_home}/jre/lib/**/libjvm.so").and_return([])
|
||||
expect(Facter.value(:java_libjvm_path)).to be nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user