diff --git a/lib/facter/java_default_home.rb b/lib/facter/java_default_home.rb index 0f4d58e..c198c2c 100644 --- a/lib/facter/java_default_home.rb +++ b/lib/facter/java_default_home.rb @@ -1,30 +1,32 @@ +# frozen_string_literal: true + # Fact: java_default_home # # Purpose: get absolute path of java system home # # Resolution: # Find the real java binary, and return the subsubdir # # Caveats: # java binary has to be found in $PATH # # Notes: # None Facter.add(:java_default_home) do confine kernel: ['Linux', 'OpenBSD'] java_default_home = nil setcode do java_bin = Facter::Util::Resolution.which('java').to_s.strip if java_bin.empty? nil else java_path = File.realpath(java_bin) java_default_home = if java_path =~ %r{/jre/} File.dirname(File.dirname(File.dirname(java_path))) else File.dirname(File.dirname(java_path)) end end end java_default_home end diff --git a/lib/facter/java_libjvm_path.rb b/lib/facter/java_libjvm_path.rb index 7ae549f..cc3085b 100644 --- a/lib/facter/java_libjvm_path.rb +++ b/lib/facter/java_libjvm_path.rb @@ -1,32 +1,34 @@ +# frozen_string_literal: true + # Fact: java_libjvm_path # # Purpose: get path to libjvm.so # # Resolution: # Lists file in java default home and searches for the file # # Caveats: # Needs to list files recursively. Returns the first match # Needs working java_major_version fact # # Notes: # None Facter.add(:java_libjvm_path) do confine kernel: ['Linux', 'OpenBSD'] setcode do java_default_home = Facter.value(:java_default_home) java_major_version = Facter.value(:java_major_version) unless java_major_version.nil? java_libjvm_file = if java_major_version.to_i >= 11 Dir.glob("#{java_default_home}/lib/**/libjvm.so") else Dir.glob("#{java_default_home}/jre/lib/**/libjvm.so") end if java_libjvm_file.nil? || java_libjvm_file.empty? nil else File.dirname(java_libjvm_file[0]) end end end end diff --git a/lib/facter/java_major_version.rb b/lib/facter/java_major_version.rb index 3afd994..6ba4ec1 100644 --- a/lib/facter/java_major_version.rb +++ b/lib/facter/java_major_version.rb @@ -1,28 +1,30 @@ +# frozen_string_literal: true + # Fact: java_major_version # # Purpose: get Java's major version # # Resolution: # Tests for presence of java, returns nil if not present # returns output of "java -version" and splits on \n + '"' # eg. # # Caveats: # none # # Notes: # None Facter.add(:java_major_version) do java_major_version = nil setcode do java_version = Facter.value(:java_version) unless java_version.nil? java_major_version = if java_version.strip[0..1] == '1.' java_version.strip.split('_')[0].split('.')[1] else java_version.strip.split('.')[0] end end end java_major_version end diff --git a/lib/facter/java_patch_level.rb b/lib/facter/java_patch_level.rb index 2722d0b..d645155 100644 --- a/lib/facter/java_patch_level.rb +++ b/lib/facter/java_patch_level.rb @@ -1,26 +1,28 @@ +# frozen_string_literal: true + # Fact: java_patch_level # # Purpose: get Java's patch level # # Resolution: # Uses java_version fact splits on the patch number (after _ for 1.x and patch number for semver'ed javas) # # Caveats: # none # # Notes: # None Facter.add(:java_patch_level) do java_patch_level = nil setcode do java_version = Facter.value(:java_version) unless java_version.nil? if java_version.strip[0..1] == '1.' java_patch_level = java_version.strip.split('_')[1] unless java_version.nil? else java_patch_level = java_version.strip.split('.')[2] unless java_version.nil? end end end java_patch_level end diff --git a/lib/facter/java_version.rb b/lib/facter/java_version.rb index 6de4bb4..07468da 100644 --- a/lib/facter/java_version.rb +++ b/lib/facter/java_version.rb @@ -1,44 +1,46 @@ +# frozen_string_literal: true + # Fact: java_version # # Purpose: get full java version string # # Resolution: # Tests for presence of java, returns nil if not present # returns output of "java -version" and splits on '"' # # Caveats: # none # # Notes: # None Facter.add(:java_version) do # the OS-specific overrides need to be able to return nil, # to indicate "no java available". Usually returning nil # would mean that facter falls back to a lower priority # resolution, which would then trigger MODULES-2637. To # avoid that, we confine the "default" here to not run # on those OS. # Additionally, facter versions prior to 2.0.1 only support # positive matches, so this needs to be done manually in setcode. setcode 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 = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line } end version end end end Facter.add(:java_version) do confine operatingsystem: 'Darwin' has_weight 100 setcode do unless %r{Unable to find any JVMs matching version} =~ Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1') version = nil Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line } version end end end diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index 7d31564..e79b4ce 100644 --- a/spec/acceptance/install_spec.rb +++ b/spec/acceptance/install_spec.rb @@ -1,280 +1,282 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'pry' java_class_jre = "class { 'java':\n"\ " distribution => 'jre',\n"\ '}' java_class = "class { 'java': }" _sources = "file_line { 'non-free source':\n"\ " path => '/etc/apt/sources.list',\n"\ " match => \"deb http://osmirror.delivery.puppetlabs.net/debian/ ${::lsbdistcodename} main\",\n"\ " line => \"deb http://osmirror.delivery.puppetlabs.net/debian/ ${::lsbdistcodename} main non-free\",\n"\ '}' _sun_jre = "class { 'java':\n"\ " distribution => 'sun-jre',\n"\ '}' _sun_jdk = "class { 'java':\n"\ " distribution => 'sun-jdk',\n"\ '}' blank_version = "class { 'java':\n"\ " version => '',\n"\ '}' incorrect_distro = "class { 'java':\n"\ " distribution => 'xyz',\n"\ '}' blank_distro = "class { 'java':\n"\ " distribution => '',\n"\ '}' incorrect_package = "class { 'java':\n"\ " package => 'xyz',\n"\ '}' bogus_alternative = "class { 'java':\n"\ " java_alternative => 'whatever',\n"\ " java_alternative_path => '/whatever',\n"\ '}' # Oracle installs are disabled by default, because the links to valid oracle installations # change often. Look the parameters up from the Oracle download URLs at https://java.oracle.com and # enable the tests: oracle_enabled = false oracle_version_major = '8' oracle_version_minor = '201' oracle_version_build = '09' oracle_hash = '42970487e3af4f5aa5bca3f542482c60' install_oracle_jdk_jre = < '#{oracle_version_major}', version_major => '#{oracle_version_major}u#{oracle_version_minor}', version_minor => 'b#{oracle_version_build}', url_hash => '#{oracle_hash}', java_se => 'jre', } java::oracle { 'test_oracle_jdk': version => '#{oracle_version_major}', version_major => '#{oracle_version_major}u#{oracle_version_minor}', version_minor => 'b#{oracle_version_build}', url_hash => '#{oracle_hash}', java_se => 'jdk', } EOL install_oracle_jre_jce = < '#{oracle_version_major}', version_major => '#{oracle_version_major}u#{oracle_version_minor}', version_minor => 'b#{oracle_version_build}', url_hash => '#{oracle_hash}', java_se => 'jre', jce => true, } EOL install_oracle_jdk_jce = < '#{oracle_version_major}', version_major => '#{oracle_version_major}u#{oracle_version_minor}', version_minor => 'b#{oracle_version_build}', url_hash => '#{oracle_hash}', java_se => 'jdk', jce => true, } EOL # AdoptOpenJDK URLs are quite generic, so tests are enabled by default # We need to test version 8 and >8 (here we use 9), because namings are different after version 8 adopt_enabled = true unless os[:family].casecmp('SLES').zero? adopt_version8_major = '8' adopt_version8_minor = '202' adopt_version8_build = '08' adopt_version9_major = '9' adopt_version9_full = '9.0.4' adopt_version9_build = '11' install_adopt_jdk_jre = < '#{adopt_version8_major}', version_major => '#{adopt_version8_major}u#{adopt_version8_minor}', version_minor => 'b#{adopt_version8_build}', java => 'jre', } java::adopt { 'test_adopt_jdk_version8': version => '#{adopt_version8_major}', version_major => '#{adopt_version8_major}u#{adopt_version8_minor}', version_minor => 'b#{adopt_version8_build}', java => 'jdk', } java::adopt { 'test_adopt_jre_version9': version => '#{adopt_version9_major}', version_major => '#{adopt_version9_full}', version_minor => '#{adopt_version9_build}', java => 'jre', } java::adopt { 'test_adopt_jdk_version9': version => '#{adopt_version9_major}', version_major => '#{adopt_version9_full}', version_minor => '#{adopt_version9_build}', java => 'jdk', } EOL sap_enabled = true sap_version7 = '7' sap_version7_full = '7.1.072' sap_version8 = '8' sap_version8_full = '8.1.065' sap_version11 = '11' sap_version11_full = '11.0.7' sap_version14 = '14' sap_version14_full = '14.0.1' install_sap_jdk_jre = < '#{sap_version7}', version_full => '#{sap_version7_full}', java => 'jdk', } java::sap { 'test_sap_jdk_version8': version => '#{sap_version8}', version_full => '#{sap_version8_full}', java => 'jdk', } java::sap { 'test_sap_jre_version11': version => '#{sap_version11}', version_full => '#{sap_version11_full}', java => 'jre', } java::sap { 'test_sap_jdk_version11': version => '#{sap_version11}', version_full => '#{sap_version11_full}', java => 'jdk', } java::sap { 'test_sap_jre_version14': version => '#{sap_version14}', version_full => '#{sap_version14_full}', java => 'jre', } java::sap { 'test_sap_jdk_version14': version => '#{sap_version14}', version_full => '#{sap_version14_full}', java => 'jdk', } EOL context 'installing java jre', unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do it 'installs jre' do idempotent_apply(java_class_jre) end end context 'installing java jdk', unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do it 'installs jdk' do idempotent_apply(java_class) end end context 'with failure cases' do it 'fails to install java with a blank version' do apply_manifest(blank_version, expect_failures: true) end it 'fails to install java with an incorrect distribution' do apply_manifest(incorrect_distro, expect_failures: true) end it 'fails to install java with a blank distribution' do apply_manifest(blank_distro, expect_failures: true) end it 'fails to install java with an incorrect package' do apply_manifest(incorrect_package, expect_failures: true) end it 'fails on debian or RHEL when passed fake java_alternative and path' do if os[:family] == 'sles' apply_manifest(bogus_alternative, catch_failures: true) else apply_manifest(bogus_alternative, expect_failures: true) end end end context 'java::oracle', if: oracle_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do let(:install_path) do (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' end let(:version_suffix) do (os[:family] == 'redhat') ? '-amd64' : '' end it 'installs oracle jdk and jre' do idempotent_apply(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 idempotent_apply(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 idempotent_apply(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 end context 'java::adopt', if: adopt_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do let(:install_path) do (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' end let(:version_suffix) do (os[:family] == 'redhat') ? '-amd64' : '' end it 'installs adopt jdk and jre' do idempotent_apply(install_adopt_jdk_jre) end end context 'java::adopt', if: sap_enabled && ['Sles'].include?(os[:family]), unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do let(:install_path) do (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' end it 'installs adopt jdk and jre' do idempotent_apply(install_sap_jdk_jre) end end diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index 0480ea6..0792d6e 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -1,251 +1,253 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java', type: :class do context 'when select openjdk for CentOS 5.8' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '5.8' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.6.0-openjdk-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.6.0/') } end context 'when select openjdk for CentOS 6.3' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '6.3' }, 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/') } end context 'when select openjdk for CentOS 7.1.1503' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '7.1.1503' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.8.0-openjdk-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0/') } end context 'when select openjdk for CentOS 6.2' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '6.2' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.6.0-openjdk-devel') } it { is_expected.not_to contain_exec('update-java-alternatives') } end context 'when select Oracle JRE with alternatives for CentOS 6.3' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '6.3' }, architecture: 'x86_64' } } } let(:params) { { 'package' => 'jre', 'java_alternative' => '/usr/bin/java', 'java_alternative_path' => '/usr/java/jre1.7.0_67/bin/java' } } it { is_expected.to contain_package('java').with_name('jre') } it { is_expected.to contain_exec('create-java-alternatives').with_command('alternatives --install /usr/bin/java java /usr/java/jre1.7.0_67/bin/java 20000') } it { is_expected.to contain_exec('update-java-alternatives').with_command('alternatives --set java /usr/java/jre1.7.0_67/bin/java') } end context 'when select passed value for CentOS 5.3' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '5.3' }, architecture: 'x86_64' } } } let(:params) { { 'package' => 'jdk', 'java_home' => '/usr/local/lib/jre' } } it { is_expected.to contain_package('java').with_name('jdk') } it { is_expected.not_to contain_exec('update-java-alternatives') } end context 'when select default for CentOS 5.3' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '5.3' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.6.0-openjdk-devel') } it { is_expected.not_to contain_exec('update-java-alternatives') } end context 'when select jdk for Debian Buster (10.0)' do let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'buster' }, release: { major: '10' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jdk' } } it { is_expected.to contain_package('java').with_name('openjdk-11-jdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/') } end context 'when select jre for Debian Buster (10.0)' do let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'buster' }, release: { major: '10' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jre' } } it { is_expected.to contain_package('java').with_name('openjdk-11-jre-headless') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/') } end context 'when select jdk for Ubuntu Trusty (14.04)' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'trusty' }, release: { major: '14.04' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jdk' } } 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 Trusty (14.04)' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'trusty' }, release: { major: '14.04' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jre' } } 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 let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'xenial' }, release: { major: '16.04' }, architecture: 'armv7l' } } } 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-armhf/') } end context 'when select jdk for Ubuntu xenial (16.04) on ARM64' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'xenial' }, release: { major: '16.04' }, architecture: 'aarch64' } } } 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-arm64/') } end context 'when select openjdk for Oracle Linux' do let(:facts) { { os: { family: 'RedHat', name: 'OracleLinux', release: { full: '6.4' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk-devel') } end context 'when select openjdk for Oracle Linux 6.2' do let(:facts) { { os: { family: 'RedHat', name: 'OracleLinux', release: { full: '6.2' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.6.0-openjdk-devel') } end context 'when select passed value for Oracle Linux' do let(:facts) { { os: { family: 'RedHat', name: 'OracleLinux', release: { full: '6.3' }, 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 passed value for Scientific Linux' do let(:facts) { { os: { family: 'RedHat', name: 'Scientific', release: { full: '6.4' }, architecture: 'x86_64' } } } let(:params) { { 'distribution' => 'jre' } } it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0/') } end context 'when select passed value for Scientific Linux CERN (SLC)' do let(:facts) { { os: { family: 'RedHat', name: 'SLC', release: { full: '6.4' }, architecture: 'x86_64' } } } let(:params) { { 'distribution' => 'jre' } } it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0/') } end context 'when select default for OpenSUSE 12.3' do let(:facts) { { os: { family: 'Suse', name: 'OpenSUSE', release: { major: '12.3' }, 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/lib64/jvm/java-1.7.0-openjdk-1.7.0/') } end context 'when select default for SLES 11.3' do let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '11.3' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1_6_0-ibm-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.6.0-ibm-1.6.0/') } end context 'when select default for SLES 11.4' do let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '11.4' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1_7_1-ibm-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.7.1-ibm-1.7.1/') } end context 'when select default for SLES 12.0' do let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '12.0', major: '12' }, 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/lib64/jvm/java-1.7.0-openjdk-1.7.0/') } end context 'when select default for SLES 12.1' do let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '12.1', major: '12' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1_8_0-openjdk-devel') } 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 describe 'custom java package' do let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'jessie' }, release: { major: '8' }, architecture: 'amd64' } } } context 'when all params provided' do let(:params) do { 'distribution' => 'custom', 'package' => 'custom_jdk', 'java_alternative' => 'java-custom_jdk', 'java_alternative_path' => '/opt/custom_jdk/bin/java', 'java_home' => '/opt/custom_jdk', } end it { is_expected.to contain_package('java').with_name('custom_jdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/opt/custom_jdk') } it { is_expected.to contain_exec('update-java-alternatives').with_command('update-java-alternatives --set java-custom_jdk --jre') } end context 'with missing parameters' do let(:params) do { 'distribution' => 'custom', 'package' => 'custom_jdk', } end it do expect { catalogue }.to raise_error Puppet::Error, %r{is not supported. Missing default values} end end end describe 'incompatible OSs' do [ { os: { family: 'windows', name: 'windows', release: { full: '8.1' }, }, }, { os: { family: 'Darwin', name: 'Darwin', release: { full: '13.3.0' }, }, }, { os: { family: 'AIX', name: 'AIX', release: { full: '7100-02-00-000' }, }, }, { os: { family: 'AIX', name: 'AIX', release: { full: '6100-07-04-1216' }, }, }, { os: { family: 'AIX', name: 'AIX', release: { full: '5300-12-01-1016' }, }, }, ].each do |facts| let(:facts) { facts } it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} end end end end diff --git a/spec/defines/adopt_spec.rb b/spec/defines/adopt_spec.rb index 514e788..400aa1f 100644 --- a/spec/defines/adopt_spec.rb +++ b/spec/defines/adopt_spec.rb @@ -1,358 +1,360 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java::adopt', type: :define do context 'with CentOS 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '6.0' } } } } context 'when manage_symlink is set to true' do let(:params) do { ensure: 'present', version: '11', java: 'jdk', basedir: '/usr/java', manage_symlink: true, symlink_name: 'java_home', } end let(:title) { 'jdk11_symlink' } it { is_expected.to contain_file('/usr/java/java_home') } end context 'when manage_symlink is not set' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11_nosymlink' } it { is_expected.not_to contain_file('/usr/java/java_home') } end context 'when AdoptOpenJDK Java 8 JDK' do let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when AdoptOpenJDK Java 9 JDK' do let(:params) { { ensure: 'present', version: '9', java: 'jdk' } } let(:title) { 'jdk9' } it { is_expected.to contain_archive('/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').with_command('tar -zxf /tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz]') } end context 'when AdoptOpenJDK Java 10 JDK' do let(:params) { { ensure: 'present', version: '10', java: 'jdk' } } let(:title) { 'jdk10' } it { is_expected.to contain_archive('/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').with_command('tar -zxf /tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz]') } end context 'when AdoptOpenJDK Java 11 JDK' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11' } it { is_expected.to contain_archive('/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').with_command('tar -zxf /tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz]') } end context 'when AdoptOpenJDK Java 12 JDK' do let(:params) { { ensure: 'present', version: '12', java: 'jdk' } } let(:title) { 'jdk12' } it { is_expected.to contain_archive('/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').with_command('tar -zxf /tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz]') } end context 'when AdoptOpenJDK Java 8 JRE' do let(:params) { { ensure: 'present', version: '8', java: 'jre' } } let(:title) { 'jre8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when AdoptOpenJDK Java 9 JRE' do let(:params) { { ensure: 'present', version: '9', java: 'jre' } } let(:title) { 'jre9' } it { is_expected.to contain_archive('/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').with_command('tar -zxf /tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz]') } end context 'when AdoptOpenJDK Java 10 JRE' do let(:params) { { ensure: 'present', version: '10', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').with_command('tar -zxf /tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz]') } end context 'when AdoptOpenJDK Java 11 JRE' do let(:params) { { ensure: 'present', version: '11', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').with_command('tar -zxf /tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz]') } end context 'when AdoptOpenJDK Java 12 JRE' do let(:params) { { ensure: 'present', version: '12', java: 'jre' } } let(:title) { 'jre12' } it { is_expected.to contain_archive('/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').with_command('tar -zxf /tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz]') } end context 'when installing multiple versions' do let(:params) do { ensure: 'present', version_major: '8u202', version_minor: 'b08', java: 'jdk', } end let(:title) { 'jdk8' } let(:pre_condition) do <<-EOL java::adopt { 'jdk8172': ensure => 'present', version_major => '8u172', version_minor => 'b11', java => 'jdk', } EOL end it { is_expected.to compile } end context 'when specifying package_type tar.gz and basedir' do let(:params) do { ensure: 'present', version: '8', java: 'jdk', basedir: '/usr/java', package_type: 'tar.gz', } end let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when manage_basedir is set to true' do let(:params) do { ensure: 'present', version: '8', java: 'jdk', basedir: '/usr/java', manage_basedir: true, } end let(:title) { 'jdk8' } it { is_expected.to contain_file('/usr/java') } end end context 'with Ubuntu 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '16.04' } } } } context 'when AdoptOpenJDK Java 8 JDK' do let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when AdoptOpenJDK Java 9 JDK' do let(:params) { { ensure: 'present', version: '9', java: 'jdk' } } let(:title) { 'jdk9' } it { is_expected.to contain_archive('/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').with_command('tar -zxf /tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz]') } end context 'when AdoptOpenJDK Java 10 JDK' do let(:params) { { ensure: 'present', version: '10', java: 'jdk' } } let(:title) { 'jdk10' } it { is_expected.to contain_archive('/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').with_command('tar -zxf /tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz]') } end context 'when AdoptOpenJDK Java 11 JDK' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11' } it { is_expected.to contain_archive('/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').with_command('tar -zxf /tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz]') } end context 'when AdoptOpenJDK Java 12 JDK' do let(:params) { { ensure: 'present', version: '12', java: 'jdk' } } let(:title) { 'jdk12' } it { is_expected.to contain_archive('/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').with_command('tar -zxf /tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz]') } end context 'when AdoptOpenJDK Java 8 JRE' do let(:params) { { ensure: 'present', version: '8', java: 'jre' } } let(:title) { 'jre8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when AdoptOpenJDK Java 9 JRE' do let(:params) { { ensure: 'present', version: '9', java: 'jre' } } let(:title) { 'jre9' } it { is_expected.to contain_archive('/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').with_command('tar -zxf /tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz]') } end context 'when AdoptOpenJDK Java 10 JRE' do let(:params) { { ensure: 'present', version: '10', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').with_command('tar -zxf /tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz]') } end context 'when AdoptOpenJDK Java 11 JRE' do let(:params) { { ensure: 'present', version: '11', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').with_command('tar -zxf /tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz]') } end context 'when AdoptOpenJDK Java 12 JRE' do let(:params) { { ensure: 'present', version: '12', java: 'jre' } } let(:title) { 'jre12' } it { is_expected.to contain_archive('/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').with_command('tar -zxf /tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz]') } end context 'when installing multiple versions' do let(:params) do { ensure: 'present', version_major: '8u202', version_minor: 'b08', java: 'jdk', } end let(:title) { 'jdk8' } let(:pre_condition) do <<-EOL java::adopt { 'jdk8172': ensure => 'present', version_major => '8u172', version_minor => 'b11', java => 'jdk', } EOL end it { is_expected.to compile } end end describe 'incompatible OSes' do [ { kernel: 'Windows', os: { family: 'Windows', name: 'Windows', release: { full: '8.1', }, }, }, { kernel: 'Darwin', os: { family: 'Darwin', name: 'Darwin', release: { full: '13.3.0', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '7100-02-00-000', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '6100-07-04-1216', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '5300-12-01-1016', }, }, }, ].each do |facts| let(:facts) { facts } let(:title) { 'jdk' } it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} end end end end diff --git a/spec/defines/download_spec.rb b/spec/defines/download_spec.rb index ae8ca75..f120c50 100644 --- a/spec/defines/download_spec.rb +++ b/spec/defines/download_spec.rb @@ -1,158 +1,160 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java::download', type: :define do let(:url) { 'http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz' } context 'with CentOS 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '6.0' } } } } context 'when passing URL to url parameter' do let(:params) do { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: url, } end let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.rpm') } end context 'when no url provided' do let(:params) do { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', } end let(:title) { 'jdk8' } it { is_expected.to raise_error Puppet::Error } end context 'when manage_symlink is set to true' do let(:params) do { ensure: 'present', version: '6', java_se: 'jdk', basedir: '/usr/java', manage_symlink: true, symlink_name: 'java_home', url: url, } end let(:title) { 'jdk6' } it { is_expected.to contain_file('/usr/java/java_home') } end context 'when manage_symlink is not set' do let(:params) do { ensure: 'present', version: '6', java_se: 'jdk', basedir: '/usr/java', url: url, } end let(:title) { 'jdk6_nosymlink' } it { is_expected.not_to contain_file('/usr/java/java_home') } end end context 'with Ubuntu 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '16.04' } } } } context 'when passing URL to url parameter' do let(:params) { { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: url } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.tar.gz') } end end context 'with Debian 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Debian', release: { full: '10.0' } } } } context 'when passing URL to url parameter' do let(:params) { { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: url } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.tar.gz') } end end describe 'incompatible OSes' do [ { kernel: 'Windows', os: { family: 'Windows', name: 'Windows', release: { full: '8.1', }, }, }, { kernel: 'Darwin', os: { family: 'Darwin', name: 'Darwin', release: { full: '13.3.0', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '7100-02-00-000', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '6100-07-04-1216', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '5300-12-01-1016', }, }, }, ].each do |facts| let(:facts) { facts } let(:title) { 'jdk' } it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} end end end end diff --git a/spec/defines/sap_spec.rb b/spec/defines/sap_spec.rb index 9d10686..ee4fb88 100644 --- a/spec/defines/sap_spec.rb +++ b/spec/defines/sap_spec.rb @@ -1,255 +1,257 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java::sap', type: :define do context 'with CentOS 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '6.0' } } } } context 'when manage_symlink is set to true' do let(:params) do { ensure: 'present', version: '11', java: 'jdk', basedir: '/usr/java', manage_symlink: true, symlink_name: 'java_home', } end let(:title) { 'jdk11_symlink' } it { is_expected.to contain_file('/usr/java/java_home') } end context 'when manage_symlink is not set' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11_nosymlink' } it { is_expected.not_to contain_file('/usr/java/java_home') } end context 'when sapjvm 7' do let(:params) { { ensure: 'present', version: '7', java: 'jdk' } } let(:title) { 'jdk7' } it { is_expected.to contain_archive('/tmp/sapjvm-7.1.072-linux-x64.zip') } end context 'when sapjvm 8' do let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } end context 'when sapmachine 11 jdk' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11' } it { is_expected.to contain_archive('/tmp/sapmachine-jdk-11.0.7_linux-x64_bin.tar.gz') } end context 'when sapmachine 11 jre' do let(:params) { { ensure: 'present', version: '11', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/sapmachine-jre-11.0.7_linux-x64_bin.tar.gz') } end context 'when sapmachine 14 jdk' do let(:params) { { ensure: 'present', version: '14', java: 'jdk' } } let(:title) { 'jdk14' } it { is_expected.to contain_archive('/tmp/sapmachine-jdk-14.0.1_linux-x64_bin.tar.gz') } end context 'when sapmachine 14 jre' do let(:params) { { ensure: 'present', version: '14', java: 'jre' } } let(:title) { 'jre14' } it { is_expected.to contain_archive('/tmp/sapmachine-jre-14.0.1_linux-x64_bin.tar.gz') } end context 'when installing multiple versions' do let(:params) do { ensure: 'present', version_full: '11.0.7', java: 'jdk', } end let(:title) { 'jdk1107' } let(:pre_condition) do <<-EOL java::sap { 'jdk1106': ensure => 'present', version_full => '11.0.6', java => 'jdk', } EOL end it { is_expected.to compile } end context 'when specifying basedir' do let(:params) do { ensure: 'present', version: '8', java: 'jdk', basedir: '/usr/java', } end let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } end context 'when manage_basedir is set to true' do let(:params) do { ensure: 'present', version: '8', java: 'jdk', basedir: '/usr/java', manage_basedir: true, } end let(:title) { 'jdk8' } it { is_expected.to contain_file('/usr/java') } end end context 'with Ubuntu 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '16.04' } } } } context 'when sapjvm 7' do let(:params) { { ensure: 'present', version: '7', java: 'jdk' } } let(:title) { 'jdk7' } it { is_expected.to contain_archive('/tmp/sapjvm-7.1.072-linux-x64.zip') } end context 'when sapjvm 8' do let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } end context 'when sapmachine 11 jdk' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11' } it { is_expected.to contain_archive('/tmp/sapmachine-jdk-11.0.7_linux-x64_bin.tar.gz') } end context 'when sapmachine 11 jre' do let(:params) { { ensure: 'present', version: '11', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/sapmachine-jre-11.0.7_linux-x64_bin.tar.gz') } end context 'when sapmachine 14 jdk' do let(:params) { { ensure: 'present', version: '14', java: 'jdk' } } let(:title) { 'jdk14' } it { is_expected.to contain_archive('/tmp/sapmachine-jdk-14.0.1_linux-x64_bin.tar.gz') } end context 'when sapmachine 14 jre' do let(:params) { { ensure: 'present', version: '14', java: 'jre' } } let(:title) { 'jre14' } it { is_expected.to contain_archive('/tmp/sapmachine-jre-14.0.1_linux-x64_bin.tar.gz') } end context 'when installing multiple versions' do let(:params) do { ensure: 'present', version_full: '11.0.7', java: 'jdk', } end let(:title) { 'jdk1107' } let(:pre_condition) do <<-EOL java::sap { 'jdk1106': ensure => 'present', version_full => '11.0.6', java => 'jdk', } EOL end it { is_expected.to compile } end end describe 'incompatible OSes' do [ { kernel: 'Windows', os: { family: 'Windows', name: 'Windows', release: { full: '8.1', }, }, }, { kernel: 'Darwin', os: { family: 'Darwin', name: 'Darwin', release: { full: '13.3.0', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '7100-02-00-000', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '6100-07-04-1216', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '5300-12-01-1016', }, }, }, ].each do |facts| let(:facts) { facts } let(:title) { 'jdk' } it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} end end end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 3c3b402..664fc0e 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + UNSUPPORTED_PLATFORMS = ['darwin', 'windows'].freeze diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index 2e897cb..ce4d062 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -1,28 +1,30 @@ +# frozen_string_literal: true + if ENV['COVERAGE'] == 'yes' require 'simplecov' require 'simplecov-console' require 'codecov' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Console, SimpleCov::Formatter::Codecov, ] SimpleCov.start do track_files 'lib/**/*.rb' add_filter '/spec' # do not track vendored files add_filter '/vendor' add_filter '/.vendor' # do not track gitignored files # this adds about 4 seconds to the coverage check # this could definitely be optimized add_filter do |f| # system returns true if exit status is 0, which with git-check-ignore means file is ignored system("git check-ignore --quiet #{f.filename}") end end end diff --git a/spec/unit/facter/java_default_home_spec.rb b/spec/unit/facter/java_default_home_spec.rb index 31ecd68..11fb206 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -1,54 +1,56 @@ +# frozen_string_literal: true + require 'spec_helper' java_7_path = '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java' java_7_home = '/usr/lib/jvm/java-7-openjdk-amd64' java_8_path = '/usr/lib/jvm/oracle-java8-jre-amd64/bin/java' java_8_home = '/usr/lib/jvm/oracle-java8-jre-amd64' def unlink_and_delete(filename) if File.symlink?(filename) File.unlink(filename) end return unless File.exist?(filename) File.delete(filename) end def symlink_and_test(symlink_path, java_home) File.symlink(symlink_path, './java_test') expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('./java_test') expect(File).to receive(:realpath).with('./java_test').and_return(symlink_path) expect(Facter.value(:java_default_home)).to eql java_home end describe 'java_default_home' do before(:each) do Facter.clear allow(Facter.fact(:kernel)).to receive(:value).once.and_return('Linux') end context 'when java found in PATH' do context 'when java is in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java' do it do unlink_and_delete('./java_test') symlink_and_test(java_7_path, java_7_home) unlink_and_delete('./java_test') end end context 'when java is in /usr/lib/jvm/oracle-java8-jre-amd64/bin/java' do it do unlink_and_delete('./java_test') symlink_and_test(java_8_path, java_8_home) unlink_and_delete('./java_test') end end end 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(nil) expect(Facter.value(:java_default_home)).to be_nil end end end diff --git a/spec/unit/facter/java_libjvm_path_spec.rb b/spec/unit/facter/java_libjvm_path_spec.rb index 3efcb47..dde5aa5 100644 --- a/spec/unit/facter/java_libjvm_path_spec.rb +++ b/spec/unit/facter/java_libjvm_path_spec.rb @@ -1,26 +1,28 @@ +# frozen_string_literal: true + 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).and_return('Linux') allow(Facter.fact(:java_default_home)).to receive(:value).and_return(java_default_home) end context 'when libjvm exists' do it do allow(Facter.fact(:java_major_version)).to receive(:value).and_return(8) 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}/lib/**/libjvm.so").and_return([]) expect(Facter.value(:java_libjvm_path)).to be nil end end end diff --git a/spec/unit/facter/java_major_version_spec.rb b/spec/unit/facter/java_major_version_spec.rb index 3b50e00..62a3df7 100644 --- a/spec/unit/facter/java_major_version_spec.rb +++ b/spec/unit/facter/java_major_version_spec.rb @@ -1,25 +1,27 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java_major_version' do before(:each) do Facter.clear end context 'when java_version fact present, returns major version' do before :each do allow(Facter.fact(:java_version)).to receive(:value).and_return('1.7.0_71') end it do expect(Facter.fact(:java_major_version).value).to eq('7') end end context 'when java not present, returns nil' do before :each do allow(Facter.fact(:java_version)).to receive(:value).and_return(nil) end it do expect(Facter.fact(:java_major_version).value).to be_nil end end end diff --git a/spec/unit/facter/java_patch_level_spec.rb b/spec/unit/facter/java_patch_level_spec.rb index 4287b29..216fdec 100644 --- a/spec/unit/facter/java_patch_level_spec.rb +++ b/spec/unit/facter/java_patch_level_spec.rb @@ -1,25 +1,27 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java_patch_level' do before(:each) do Facter.clear end context 'when java is installed returns java patch version extracted from java_version fact' do before :each do allow(Facter.fact(:java_version)).to receive(:value).and_return('1.7.0_71') end it do expect(Facter.fact(:java_patch_level).value).to eq('71') end end context 'when java is not installed returns nil' do before :each do allow(Facter.fact(:java_version)).to receive(:value).and_return('nil') end it do expect(Facter.fact(:java_patch_level).value).to be_nil end end end diff --git a/spec/unit/facter/java_version_spec.rb b/spec/unit/facter/java_version_spec.rb index 5d65a04..bb4b167 100644 --- a/spec/unit/facter/java_version_spec.rb +++ b/spec/unit/facter/java_version_spec.rb @@ -1,93 +1,95 @@ +# frozen_string_literal: true + require 'spec_helper' openjdk_7_output = "Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true\n"\ "openjdk version \"1.7.0_71\"\n"\ "OpenJDK Runtime Environment (build 1.7.0_71-b14)\n"\ "OpenJDK 64-Bit Server VM (build 24.71-b01, mixed mode)\n" jdk_7_hotspot_output = "Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true\n"\ "java version \"1.7.0_71\"\n"\ "Java(TM) SE Runtime Environment (build 1.7.0_71-b14)\n"\ "Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)\n" describe 'java_version' do before(:each) do Facter.clear end context 'when java present, returns java version' do context 'on OpenBSD', with_env: true do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') end let(:facts) { { operatingsystem: 'OpenBSD' } } it do expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('/usr/local/jdk-1.7.0/jre/bin/java') expect(Facter::Util::Resolution).to receive(:exec).with('java -Xmx12m -version 2>&1').and_return(openjdk_7_output) expect(Facter.value(:java_version)).to eq('1.7.0_71') end end context 'when on Darwin' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin') end let(:facts) { { operatingsystem: 'Darwin' } } 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('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output) expect(Facter.value(:java_version)).to eql '1.7.0_71' end end context 'when on other systems' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS') end let(:facts) { { operatingsystem: 'MyOS' } } it do expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('/path/to/java') expect(Facter::Util::Resolution).to receive(:exec).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output) expect(Facter.value(:java_version)).to eq('1.7.0_71') end end end context 'when java not present, returns nil' do context 'on OpenBSD', with_env: true do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') end let(:facts) { { operatingsystem: 'OpenBSD' } } it do allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(Facter::Util::Resolution).to receive(:which).and_return(nil) expect(Facter.value(:java_version)).to be_nil end end context 'when on Darwin' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin') end let(:facts) { { operatingsystem: 'Darwin' } } 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.value(:java_version)).to be_nil end end context 'when on other systems' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS') end let(:facts) { { operatingsystem: 'MyOS' } } it do expect(Facter::Util::Resolution).to receive(:which).at_least(1).with('java').and_return(false) expect(Facter.value(:java_version)).to be_nil end end end end