diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fe7a8b12..cdd65d22 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ "settings": { "terminal.integrated.profiles.linux": { "bash": { - "path": "bash", + "path": "bash" } } }, diff --git a/.fixtures.yml b/.fixtures.yml index fc5c840f..4de712c2 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,9 +3,9 @@ fixtures: archive: "https://github.com/voxpupuli/puppet-archive.git" facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" - puppet_agent: + puppet_agent: repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.12.1 + ref: v4.13.0 provision: 'https://github.com/puppetlabs/provision.git' symlinks: java: "#{source_dir}" diff --git a/.rubocop.yml b/.rubocop.yml index 31e8248f..2367276d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,8 +3,11 @@ require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.5' + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.7' Include: - "**/*.rb" Exclude: @@ -71,6 +74,7 @@ Style/TrailingCommaInArrayLiteral: Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets +inherit_from: ".rubocop_todo.yml" RSpec/MessageSpies: EnforcedStyle: receive Style/Documentation: @@ -79,441 +83,5 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets -Performance/AncestorsInclude: - Enabled: true -Performance/BigDecimalWithNumericArgument: - Enabled: true -Performance/BlockGivenWithExplicitBlock: - Enabled: true -Performance/CaseWhenSplat: - Enabled: true -Performance/ConstantRegexp: - Enabled: true -Performance/MethodObjectAsBlock: - Enabled: true -Performance/RedundantSortBlock: - Enabled: true -Performance/RedundantStringChars: - Enabled: true -Performance/ReverseFirst: - Enabled: true -Performance/SortReverse: - Enabled: true -Performance/Squeeze: - Enabled: true -Performance/StringInclude: - Enabled: true -Performance/Sum: - Enabled: true -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Bundler/InsecureProtocolSource: - Enabled: false -Gemspec/DuplicatedAssignment: - Enabled: false -Gemspec/OrderedDependencies: - Enabled: false -Gemspec/RequiredRubyVersion: - Enabled: false -Gemspec/RubyVersionGlobalsUsage: - Enabled: false -Layout/ArgumentAlignment: - Enabled: false -Layout/BeginEndAlignment: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: false -Layout/EmptyComment: - Enabled: false -Layout/EmptyLineAfterGuardClause: - Enabled: false -Layout/EmptyLinesAroundArguments: - Enabled: false -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/FirstArgumentIndentation: - Enabled: false -Layout/HashAlignment: - Enabled: false -Layout/HeredocIndentation: - Enabled: false -Layout/LeadingEmptyLines: - Enabled: false -Layout/SpaceAroundMethodCallOperator: - Enabled: false -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false -Layout/SpaceInsideReferenceBrackets: - Enabled: false -Lint/BigDecimalNew: - Enabled: false -Lint/BooleanSymbol: - Enabled: false -Lint/ConstantDefinitionInBlock: - Enabled: false -Lint/DeprecatedOpenSSLConstant: - Enabled: false -Lint/DisjunctiveAssignmentInConstructor: - Enabled: false -Lint/DuplicateElsifCondition: - Enabled: false -Lint/DuplicateRequire: - Enabled: false -Lint/DuplicateRescueException: - Enabled: false -Lint/EmptyConditionalBody: - Enabled: false -Lint/EmptyFile: - Enabled: false -Lint/ErbNewArguments: - Enabled: false -Lint/FloatComparison: - Enabled: false -Lint/HashCompareByIdentity: - Enabled: false -Lint/IdentityComparison: - Enabled: false -Lint/InterpolationCheck: - Enabled: false -Lint/MissingCopEnableDirective: - Enabled: false -Lint/MixedRegexpCaptureTypes: - Enabled: false -Lint/NestedPercentLiteral: - Enabled: false -Lint/NonDeterministicRequireOrder: - Enabled: false -Lint/OrderedMagicComments: - Enabled: false -Lint/OutOfRangeRegexpRef: - Enabled: false -Lint/RaiseException: - Enabled: false -Lint/RedundantCopEnableDirective: - Enabled: false -Lint/RedundantRequireStatement: - Enabled: false -Lint/RedundantSafeNavigation: - Enabled: false -Lint/RedundantWithIndex: - Enabled: false -Lint/RedundantWithObject: - Enabled: false -Lint/RegexpAsCondition: - Enabled: false -Lint/ReturnInVoidContext: - Enabled: false -Lint/SafeNavigationConsistency: - Enabled: false -Lint/SafeNavigationWithEmpty: - Enabled: false -Lint/SelfAssignment: - Enabled: false -Lint/SendWithMixinArgument: - Enabled: false -Lint/ShadowedArgument: - Enabled: false -Lint/StructNewOverride: - Enabled: false -Lint/ToJSON: - Enabled: false -Lint/TopLevelReturnWithArgument: - Enabled: false -Lint/TrailingCommaInAttributeDeclaration: - Enabled: false -Lint/UnreachableLoop: - Enabled: false -Lint/UriEscapeUnescape: - Enabled: false -Lint/UriRegexp: - Enabled: false -Lint/UselessMethodDefinition: - Enabled: false -Lint/UselessTimes: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Migration/DepartmentName: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Naming/BlockParameterName: - Enabled: false -Naming/HeredocDelimiterCase: - Enabled: false -Naming/HeredocDelimiterNaming: - Enabled: false -Naming/MemoizedInstanceVariableName: - Enabled: false -Naming/MethodParameterName: - Enabled: false -Naming/RescuedExceptionsVariableName: - Enabled: false -Naming/VariableNumber: - Enabled: false -Performance/BindCall: - Enabled: false -Performance/DeletePrefix: - Enabled: false -Performance/DeleteSuffix: - Enabled: false -Performance/InefficientHashSearch: - Enabled: false -Performance/UnfreezeString: - Enabled: false -Performance/UriDefaultParser: - Enabled: false -RSpec/Be: - Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false -RSpec/Capybara/FeatureMethods: - Enabled: false -RSpec/Capybara/VisibilityMatcher: - Enabled: false -RSpec/ContextMethod: - Enabled: false -RSpec/ContextWording: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/EmptyHook: - Enabled: false -RSpec/EmptyLineAfterExample: - Enabled: false -RSpec/EmptyLineAfterExampleGroup: - Enabled: false -RSpec/EmptyLineAfterHook: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWithoutDescription: - Enabled: false -RSpec/ExpectChange: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/FactoryBot/AttributeDefinedStatically: - Enabled: false -RSpec/FactoryBot/CreateList: - Enabled: false -RSpec/FactoryBot/FactoryClassName: - Enabled: false -RSpec/HooksBeforeExamples: - Enabled: false -RSpec/ImplicitBlockExpectation: - Enabled: false -RSpec/ImplicitSubject: - Enabled: false -RSpec/LeakyConstantDeclaration: - Enabled: false -RSpec/LetBeforeExamples: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false RSpec/MultipleExpectations: - Enabled: false -RSpec/MultipleMemoizedHelpers: - Enabled: false -RSpec/MultipleSubjects: - Enabled: false -RSpec/NestedGroups: - Enabled: false -RSpec/PredicateMatcher: - Enabled: false -RSpec/ReceiveCounts: - Enabled: false -RSpec/ReceiveNever: - Enabled: false -RSpec/RepeatedExampleGroupBody: - Enabled: false -RSpec/RepeatedExampleGroupDescription: - Enabled: false -RSpec/RepeatedIncludeExample: - Enabled: false -RSpec/ReturnFromStub: - Enabled: false -RSpec/SharedExamples: - Enabled: false -RSpec/StubbedMock: - Enabled: false -RSpec/UnspecifiedException: - Enabled: false -RSpec/VariableDefinition: - Enabled: false -RSpec/VoidExpect: - Enabled: false -RSpec/Yield: - Enabled: false -Security/Open: - Enabled: false -Style/AccessModifierDeclarations: - Enabled: false -Style/AccessorGrouping: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/BisectedAttrAccessor: - Enabled: false -Style/CaseLikeIf: - Enabled: false -Style/ClassEqualityComparison: - Enabled: false -Style/ColonMethodDefinition: - Enabled: false -Style/CombinableLoops: - Enabled: false -Style/CommentedKeyword: - Enabled: false -Style/Dir: - Enabled: false -Style/DoubleCopDisableDirective: - Enabled: false -Style/EmptyBlockParameter: - Enabled: false -Style/EmptyLambdaParameter: - Enabled: false -Style/Encoding: - Enabled: false -Style/EvalWithLocation: - Enabled: false -Style/ExpandPathArguments: - Enabled: false -Style/ExplicitBlockArgument: - Enabled: false -Style/ExponentialNotation: - Enabled: false -Style/FloatDivision: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalStdStream: - Enabled: false -Style/HashAsLastArrayItem: - Enabled: false -Style/HashLikeCase: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/KeywordParametersOrder: - Enabled: false -Style/MinMax: - Enabled: false -Style/MixinUsage: - Enabled: false -Style/MultilineWhenThen: - Enabled: false -Style/NegatedUnless: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OptionalBooleanParameter: - Enabled: false -Style/OrAssignment: - Enabled: false -Style/RandomWithOffset: - Enabled: false -Style/RedundantAssignment: - Enabled: false -Style/RedundantCondition: - Enabled: false -Style/RedundantConditional: - Enabled: false -Style/RedundantFetchBlock: - Enabled: false -Style/RedundantFileExtensionInRequire: - Enabled: false -Style/RedundantRegexpCharacterClass: - Enabled: false -Style/RedundantRegexpEscape: - Enabled: false -Style/RedundantSelfAssignment: - Enabled: false -Style/RedundantSort: - Enabled: false -Style/RescueStandardError: - Enabled: false -Style/SingleArgumentDig: - Enabled: false -Style/SlicingWithRange: - Enabled: false -Style/SoleNestedConditional: - Enabled: false -Style/StderrPuts: - Enabled: false -Style/StringConcatenation: - Enabled: false -Style/Strip: - Enabled: false -Style/SymbolProc: - Enabled: false -Style/TrailingBodyOnClass: - Enabled: false -Style/TrailingBodyOnMethodDefinition: - Enabled: false -Style/TrailingBodyOnModule: - Enabled: false -Style/TrailingCommaInHashLiteral: - Enabled: false -Style/TrailingMethodEndStatement: - Enabled: false -Style/UnpackFirst: - Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/DuplicateRegexpCharacterClassElement: - Enabled: false -Lint/EmptyBlock: - Enabled: false -Lint/EmptyClass: - Enabled: false -Lint/NoReturnInBeginEndBlocks: - Enabled: false -Lint/ToEnumArguments: - Enabled: false -Lint/UnexpectedBlockArity: - Enabled: false -Lint/UnmodifiedReduceAccumulator: - Enabled: false -Performance/CollectionLiteralInLoop: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionCompact: - Enabled: false -Style/DocumentDynamicEvalDefinition: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/NilLambda: - Enabled: false -Style/RedundantArgument: - Enabled: false -Style/SwapValues: - Enabled: false + Max: 3 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..b9ca46bc --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,41 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-17 12:22:29 UTC using RuboCop version 1.48.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 11 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - '**/spec/features/**/*' + - '**/spec/requests/**/*' + - '**/spec/routing/**/*' + - '**/spec/system/**/*' + - '**/spec/views/**/*' + - 'spec/acceptance/install_spec.rb' + - 'spec/classes/java_spec.rb' + - 'spec/defines/adopt_spec.rb' + - 'spec/defines/adoptium_spec.rb' + - 'spec/defines/download_spec.rb' + - 'spec/defines/sap_spec.rb' + - 'spec/unit/facter/java_default_home_spec.rb' + - 'spec/unit/facter/java_libjvm_path_spec.rb' + - 'spec/unit/facter/java_major_version_spec.rb' + - 'spec/unit/facter/java_patch_level_spec.rb' + - 'spec/unit/facter/java_version_spec.rb' + +# Offense count: 3 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: + Exclude: + - 'spec/classes/java_spec.rb' + - 'spec/defines/download_spec.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' diff --git a/Gemfile b/Gemfile index 1881afe1..3f6f5c7d 100644 --- a/Gemfile +++ b/Gemfile @@ -14,31 +14,31 @@ def location_for(place_or_version, fake_version = nil) end group :development do - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "voxpupuli-puppet-lint-plugins", '~> 3.1', require: false - gem "facterdb", '~> 1.18', require: false - gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false - gem "puppetlabs_spec_helper", '>= 3.0.0', '< 5.0.0', require: false - gem "rspec-puppet-facts", '~> 2.0', require: false - gem "codecov", '~> 0.2', require: false - gem "dependency_checker", '~> 0.2', require: false - gem "parallel_tests", '~> 3.4', require: false - gem "pry", '~> 0.10', require: false - gem "simplecov-console", '~> 0.5', require: false - gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.6.1', require: false - gem "rubocop-performance", '= 1.9.1', require: false - gem "rubocop-rspec", '= 2.0.1', require: false - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "github_changelog_generator", '= 1.15.2', require: false + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false + gem "puppetlabs_spec_helper", '~> 5.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 0.2', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.48.1', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "github_changelog_generator", '= 1.15.2', require: false end group :system_tests do - gem "puppet_litmus", '<= 0.34.6', require: false, platforms: [:ruby] - gem "serverspec", '~> 2.41', require: false + gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] + gem "serverspec", '~> 2.41', require: false end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index 2906c15b..0f8754eb 100644 --- a/Rakefile +++ b/Rakefile @@ -43,6 +43,7 @@ end PuppetLint.configuration.send('disable_relative') + if Bundler.rubygems.find_name('github_changelog_generator').any? GitHubChangelogGenerator::RakeTask.new :changelog do |config| raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? diff --git a/lib/facter/java_default_home.rb b/lib/facter/java_default_home.rb index a818ad68..a93a13ae 100644 --- a/lib/facter/java_default_home.rb +++ b/lib/facter/java_default_home.rb @@ -21,7 +21,7 @@ nil else java_path = File.realpath(java_bin) - java_default_home = if %r{/jre/}.match?(java_path) + java_default_home = if java_path.include?('/jre/') File.dirname(File.dirname(File.dirname(java_path))) else File.dirname(File.dirname(java_path)) diff --git a/lib/facter/java_version.rb b/lib/facter/java_version.rb index 8c0c02c5..241d8760 100644 --- a/lib/facter/java_version.rb +++ b/lib/facter/java_version.rb @@ -22,6 +22,6 @@ elsif Facter::Core::Execution.which('java') version = Facter::Core::Execution.execute('java -Xmx12m -version 2>&1').lines.find { |line| line.include?('version') } end - version[%r{\"(.*?)\"}, 1] if version + version[%r{"(.*?)"}, 1] if version end end diff --git a/metadata.json b/metadata.json index 578a1e85..ad69c15d 100644 --- a/metadata.json +++ b/metadata.json @@ -77,10 +77,10 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.24.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "2.7.1-0-g9a16c87", - "pdk-version": "2.6.0" + "template-ref": "heads/main-0-gc6d4446", + "pdk-version": "2.7.1" } diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index 3dd4cb91..2dd687f3 100644 --- a/spec/acceptance/install_spec.rb +++ b/spec/acceptance/install_spec.rb @@ -3,45 +3,45 @@ require 'spec_helper_acceptance' require 'pry' -java_class_jre = "class { 'java':\n"\ - " distribution => 'jre',\n"\ +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"\ - '}' +_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_jre = "class { 'java':\n " \ + "distribution => 'sun-jre',\n" \ + '}' -_sun_jdk = "class { 'java':\n"\ - " distribution => 'sun-jdk',\n"\ - '}' +_sun_jdk = "class { 'java':\n " \ + "distribution => 'sun-jdk',\n" \ + '}' -blank_version = "class { 'java':\n"\ - " version => '',\n"\ +blank_version = "class { 'java':\n " \ + "version => '',\n" \ '}' -incorrect_distro = "class { 'java':\n"\ - " distribution => 'xyz',\n"\ +incorrect_distro = "class { 'java':\n " \ + "distribution => 'xyz',\n" \ '}' -blank_distro = "class { 'java':\n"\ - " distribution => '',\n"\ +blank_distro = "class { 'java':\n " \ + "distribution => '',\n" \ '}' -incorrect_package = "class { 'java':\n"\ - " package => 'xyz',\n"\ +incorrect_package = "class { 'java':\n " \ + "package => 'xyz',\n" \ '}' -bogus_alternative = "class { 'java':\n"\ - " java_alternative => 'whatever',\n"\ - " java_alternative_path => '/whatever',\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 @@ -54,7 +54,7 @@ oracle_version_build = '09' oracle_hash = '42970487e3af4f5aa5bca3f542482c60' -install_oracle_jdk_jre = < '#{oracle_version_major}', @@ -71,9 +71,9 @@ url_hash => '#{oracle_hash}', java_se => 'jdk', } -EOL +MANIFEST -install_oracle_jre_jce = < '#{oracle_version_major}', @@ -84,9 +84,9 @@ jce => true, } -EOL +MANIFEST -install_oracle_jdk_jce = < '#{oracle_version_major}', @@ -96,7 +96,7 @@ java_se => 'jdk', jce => true, } -EOL +MANIFEST # 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 @@ -109,7 +109,7 @@ adopt_version9_full = '9.0.4' adopt_version9_build = '11' -install_adopt_jdk_jre = < '#{adopt_version8_major}', @@ -138,13 +138,13 @@ version_minor => '#{adopt_version9_build}', java => 'jdk', } -EOL +MANIFEST # Adoptium adoptium_enabled = true unless os[:family].casecmp('SLES').zero? -install_adoptium_jdk = < '16', @@ -159,7 +159,7 @@ version_patch => '1', version_build => '12', } -EOL +MANIFEST sap_enabled = true sap_version7 = '7' @@ -171,7 +171,7 @@ sap_version14 = '14' sap_version14_full = '14.0.1' -install_sap_jdk_jre = < '#{sap_version7}', @@ -208,48 +208,48 @@ version_full => '#{sap_version14_full}', java => 'jdk', } -EOL +MANIFEST describe 'installing' do - context 'installing java jre' do + context 'when installing java jre' do it 'installs jre' do - idempotent_apply(java_class_jre) + expect { idempotent_apply(java_class_jre) }.not_to raise_error end end - context 'installing java jdk' do + context 'when installing java jdk' do it 'installs jdk' do - idempotent_apply(java_class) + expect { idempotent_apply(java_class) }.not_to raise_error end end - context 'with failure cases' do + context 'when with failure cases' do it 'fails to install java with a blank version' do - apply_manifest(blank_version, expect_failures: true) + expect { apply_manifest(blank_version, expect_failures: true) }.not_to raise_error end it 'fails to install java with an incorrect distribution' do - apply_manifest(incorrect_distro, expect_failures: true) + expect { apply_manifest(incorrect_distro, expect_failures: true) }.not_to raise_error end it 'fails to install java with a blank distribution' do - apply_manifest(blank_distro, expect_failures: true) + expect { apply_manifest(blank_distro, expect_failures: true) }.not_to raise_error end it 'fails to install java with an incorrect package' do - apply_manifest(incorrect_package, expect_failures: true) + expect { apply_manifest(incorrect_package, expect_failures: true) }.not_to raise_error 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) + expect { apply_manifest(bogus_alternative, catch_failures: true) }.not_to raise_error else - apply_manifest(bogus_alternative, expect_failures: true) + expect { apply_manifest(bogus_alternative, expect_failures: true) }.not_to raise_error end end end - context 'java::oracle', if: oracle_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do + context 'when 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 @@ -259,7 +259,7 @@ end it 'installs oracle jdk and jre' do - idempotent_apply(install_oracle_jdk_jre) + expect { idempotent_apply(install_oracle_jdk_jre) }.not_to raise_error 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) @@ -267,19 +267,19 @@ end it 'installs oracle jdk with jce' do - idempotent_apply(install_oracle_jdk_jce) + expect { idempotent_apply(install_oracle_jdk_jce) }.not_to raise_error 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) + expect { idempotent_apply(install_oracle_jre_jce) }.not_to raise_error 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 + context 'when 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 @@ -289,11 +289,11 @@ end it 'installs adopt jdk and jre' do - idempotent_apply(install_adopt_jdk_jre) + expect { idempotent_apply(install_adopt_jdk_jre) }.not_to raise_error end end - context 'java::adoptium', if: adoptium_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do + context 'when java::adoptium', if: adoptium_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do let(:install_path) do (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' end @@ -303,17 +303,17 @@ end it 'installs adopt jdk and jre' do - idempotent_apply(install_adoptium_jdk) + expect { idempotent_apply(install_adoptium_jdk) }.not_to raise_error end end - context 'java::sap', if: sap_enabled && ['Sles'].include?(os[:family]), unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do + context 'when java::sap', 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) + expect { idempotent_apply(install_sap_jdk_jre) }.not_to raise_error end end end diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index 35d477aa..de2f3966 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -3,58 +3,58 @@ require 'spec_helper' describe 'java', type: :class do - context 'when select openjdk for CentOS 5.8' do + context 'when selecting 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 + context 'when selecting 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 + context 'when selecting 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 + context 'when selecting 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 + context 'when selecting 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'], - unless: 'alternatives --display java | grep -q /usr/java/jre1.7.0_67/bin/java', - }, - ) + expect(subject).to contain_exec('create-java-alternatives').with( + { command: ['alternatives', '--install', '/usr/bin/java', 'java', '/usr/java/jre1.7.0_67/bin/java', '20000'], + unless: 'alternatives --display java | grep -q /usr/java/jre1.7.0_67/bin/java' }, + ) } + 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 Malicious JRE with alternatives for CentOS 6.3' do + context 'when selecting Malicious 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 ; rm -rf /etc' } } it { is_expected.to contain_exec('create-java-alternatives').with_unless('alternatives --display java | grep -q /usr/java\\ \\;\\ rm\\ -rf\\ /etc') } end - context 'when select passed value for CentOS 5.3' do + context 'when selecting 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' } } @@ -62,14 +62,14 @@ it { is_expected.not_to contain_exec('update-java-alternatives') } end - context 'when select default for CentOS 5.3' do + context 'when selecting 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 + context 'when selecting 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' } } @@ -77,7 +77,7 @@ 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 + context 'when selecting 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' } } @@ -85,7 +85,7 @@ 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 Bionic (18.04)' do + context 'when selecting jdk for Ubuntu Bionic (18.04)' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'bionic' }, release: { major: '18.04' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jdk' } } @@ -93,7 +93,7 @@ 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 Ubuntu Bionic (18.04)' do + context 'when selecting jre for Ubuntu Bionic (18.04)' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'bionic' }, release: { major: '18.04' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jre' } } @@ -101,26 +101,26 @@ 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 openjdk for Oracle Linux' do + context 'when selecting 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 + context 'when selecting 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 + context 'when selecting 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 + context 'when selecting passed value for Scientific Linux' do let(:facts) { { os: { family: 'RedHat', name: 'Scientific', release: { full: '6.4' }, architecture: 'x86_64' } } } let(:params) { { 'distribution' => 'jre' } } @@ -128,7 +128,7 @@ 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 + context 'when selecting 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' } } @@ -136,35 +136,35 @@ 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 + context 'when selecting 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 + context 'when selecting 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 + context 'when selecting 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 + context 'when selecting 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 + context 'when selecting 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') } @@ -177,11 +177,11 @@ context 'when all params provided' do let(:params) do { - 'distribution' => 'custom', - 'package' => 'custom_jdk', - 'java_alternative' => 'java-custom_jdk', + 'distribution' => 'custom', + 'package' => 'custom_jdk', + 'java_alternative' => 'java-custom_jdk', 'java_alternative_path' => '/opt/custom_jdk/bin/java', - 'java_home' => '/opt/custom_jdk', + 'java_home' => '/opt/custom_jdk' } end @@ -189,11 +189,12 @@ 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', + 'package' => 'custom_jdk' } end @@ -209,36 +210,36 @@ os: { family: 'windows', name: 'windows', - release: { full: '8.1' }, - }, + release: { full: '8.1' } + } }, { os: { family: 'Darwin', name: 'Darwin', - release: { full: '13.3.0' }, - }, + release: { full: '13.3.0' } + } }, { os: { family: 'AIX', name: 'AIX', - release: { full: '7100-02-00-000' }, - }, + release: { full: '7100-02-00-000' } + } }, { os: { family: 'AIX', name: 'AIX', - release: { full: '6100-07-04-1216' }, - }, + release: { full: '6100-07-04-1216' } + } }, { os: { family: 'AIX', name: 'AIX', - release: { full: '5300-12-01-1016' }, - }, + release: { full: '5300-12-01-1016' } + } }, ].each do |facts| let(:facts) { facts } diff --git a/spec/defines/adopt_spec.rb b/spec/defines/adopt_spec.rb index 6cc959da..1d97a0c7 100644 --- a/spec/defines/adopt_spec.rb +++ b/spec/defines/adopt_spec.rb @@ -14,7 +14,7 @@ java: 'jdk', basedir: '/usr/java', manage_symlink: true, - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk11_symlink' } @@ -125,13 +125,13 @@ ensure: 'present', version_major: '8u202', version_minor: 'b08', - java: 'jdk', + java: 'jdk' } end let(:title) { 'jdk8' } let(:pre_condition) do - <<-EOL + <<-MANIFEST java::adopt { 'jdk8172': ensure => 'present', @@ -139,7 +139,7 @@ version_minor => 'b11', java => 'jdk', } - EOL + MANIFEST end it { is_expected.to compile } @@ -152,7 +152,7 @@ version: '8', java: 'jdk', basedir: '/usr/java', - package_type: 'tar.gz', + package_type: 'tar.gz' } end let(:title) { 'jdk8' } @@ -161,6 +161,7 @@ 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 { @@ -168,7 +169,7 @@ version: '8', java: 'jdk', basedir: '/usr/java', - manage_basedir: true, + manage_basedir: true } end let(:title) { 'jdk8' } @@ -276,13 +277,13 @@ ensure: 'present', version_major: '8u202', version_minor: 'b08', - java: 'jdk', + java: 'jdk' } end let(:title) { 'jdk8' } let(:pre_condition) do - <<-EOL + <<-MANIFEST java::adopt { 'jdk8172': ensure => 'present', @@ -290,12 +291,13 @@ version_minor => 'b11', java => 'jdk', } - EOL + MANIFEST end it { is_expected.to compile } end end + describe 'incompatible OSes' do [ { @@ -304,9 +306,9 @@ family: 'Windows', name: 'Windows', release: { - full: '8.1', - }, - }, + full: '8.1' + } + } }, { kernel: 'Darwin', @@ -314,9 +316,9 @@ family: 'Darwin', name: 'Darwin', release: { - full: '13.3.0', - }, - }, + full: '13.3.0' + } + } }, { kernel: 'AIX', @@ -324,9 +326,9 @@ family: 'AIX', name: 'AIX', release: { - full: '7100-02-00-000', - }, - }, + full: '7100-02-00-000' + } + } }, { kernel: 'AIX', @@ -334,9 +336,9 @@ family: 'AIX', name: 'AIX', release: { - full: '6100-07-04-1216', - }, - }, + full: '6100-07-04-1216' + } + } }, { kernel: 'AIX', @@ -344,9 +346,9 @@ family: 'AIX', name: 'AIX', release: { - full: '5300-12-01-1016', - }, - }, + full: '5300-12-01-1016' + } + } }, ].each do |facts| let(:facts) { facts } diff --git a/spec/defines/adoptium_spec.rb b/spec/defines/adoptium_spec.rb index f9f82a1e..ba268912 100644 --- a/spec/defines/adoptium_spec.rb +++ b/spec/defines/adoptium_spec.rb @@ -16,7 +16,7 @@ version_build: '7', basedir: '/usr/java', manage_symlink: true, - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk16_symlink' } @@ -33,7 +33,7 @@ version_patch: '2', version_build: '7', basedir: '/usr/java', - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk16_nosymlink' } @@ -50,7 +50,7 @@ version_patch: '2', version_build: '7', basedir: '/usr/java', - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk16' } @@ -69,7 +69,7 @@ version_patch: '1', version_build: '12', basedir: '/usr/java', - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk17' } @@ -86,13 +86,13 @@ version_major: '16', version_minor: '0', version_patch: '2', - version_build: '7', + version_build: '7' } end let(:title) { 'jdk16' } let(:pre_condition) do - <<-EOL + <<-MANIFEST java::adoptium { 'jdk17': ensure => 'present', @@ -101,7 +101,7 @@ version_patch => '1', version_build => '12', } - EOL + MANIFEST end it { is_expected.to compile } @@ -115,7 +115,7 @@ version_minor: '0', version_patch: '2', version_build: '7', - basedir: '/usr/java', + basedir: '/usr/java' } end let(:title) { 'jdk16' } @@ -124,6 +124,7 @@ it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').with_command(['tar', '-zxf', '/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz', '-C', '/usr/java']) } it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').that_requires('Archive[/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz]') } end + context 'when manage_basedir is set to true' do let(:params) do { @@ -133,7 +134,7 @@ version_patch: '2', version_build: '7', basedir: '/usr/java', - manage_basedir: true, + manage_basedir: true } end let(:title) { 'jdk16' } @@ -153,7 +154,7 @@ version_minor: '0', version_patch: '2', version_build: '7', - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk16' } @@ -171,7 +172,7 @@ version_minor: '0', version_patch: '1', version_build: '12', - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk17' } @@ -188,13 +189,13 @@ version_major: '16', version_minor: '0', version_patch: '2', - version_build: '7', + version_build: '7' } end let(:title) { 'jdk16' } let(:pre_condition) do - <<-EOL + <<-MANIFEST java::adoptium { 'jdk17': ensure => 'present', @@ -203,7 +204,7 @@ version_patch => '1', version_build => '12', } - EOL + MANIFEST end it { is_expected.to compile } @@ -217,7 +218,7 @@ version_minor: '0', version_patch: '2', version_build: '7', - basedir: '/usr/lib/jvm', + basedir: '/usr/lib/jvm' } end let(:title) { 'jdk16' } @@ -226,6 +227,7 @@ it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').with_command(['tar', '-zxf', '/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz', '-C', '/usr/lib/jvm']) } it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').that_requires('Archive[/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz]') } end + context 'when manage_basedir is set to true' do let(:params) do { @@ -235,7 +237,7 @@ version_patch: '2', version_build: '7', basedir: '/usr/lib/jvm', - manage_basedir: true, + manage_basedir: true } end let(:title) { 'jdk16' } @@ -252,9 +254,9 @@ family: 'Windows', name: 'Windows', release: { - full: '8.1', - }, - }, + full: '8.1' + } + } }, { kernel: 'Darwin', @@ -262,9 +264,9 @@ family: 'Darwin', name: 'Darwin', release: { - full: '13.3.0', - }, - }, + full: '13.3.0' + } + } }, { kernel: 'AIX', @@ -272,9 +274,9 @@ family: 'AIX', name: 'AIX', release: { - full: '7100-02-00-000', - }, - }, + full: '7100-02-00-000' + } + } }, { kernel: 'AIX', @@ -282,9 +284,9 @@ family: 'AIX', name: 'AIX', release: { - full: '6100-07-04-1216', - }, - }, + full: '6100-07-04-1216' + } + } }, { kernel: 'AIX', @@ -292,9 +294,9 @@ family: 'AIX', name: 'AIX', release: { - full: '5300-12-01-1016', - }, - }, + full: '5300-12-01-1016' + } + } }, ].each do |facts| let(:facts) { facts } diff --git a/spec/defines/download_spec.rb b/spec/defines/download_spec.rb index f2b0c286..42a4f4d0 100644 --- a/spec/defines/download_spec.rb +++ b/spec/defines/download_spec.rb @@ -15,13 +15,13 @@ version_major: '8u201', version_minor: 'b09', java_se: 'jdk', - url: url, + url: url } end let(:title) { 'jdk8' } it { - is_expected.to contain_archive('/tmp/jdk-8-8u201-b09-linux-x64.rpm') + expect(subject).to contain_archive('/tmp/jdk-8-8u201-b09-linux-x64.rpm') } end @@ -31,13 +31,13 @@ ensure: 'present', version_major: '8u201', version_minor: 'b09', - java_se: 'jdk', + java_se: 'jdk' } end let(:title) { 'jdk8' } it { - is_expected.to raise_error Puppet::Error + expect(subject).to raise_error Puppet::Error } end @@ -50,7 +50,7 @@ basedir: '/usr/java', manage_symlink: true, symlink_name: 'java_home', - url: url, + url: url } end let(:title) { 'jdk6' } @@ -65,7 +65,7 @@ version: '6', java_se: 'jdk', basedir: '/usr/java', - url: url, + url: url } end let(:title) { 'jdk6_nosymlink' } @@ -104,9 +104,9 @@ family: 'Windows', name: 'Windows', release: { - full: '8.1', - }, - }, + full: '8.1' + } + } }, { kernel: 'Darwin', @@ -114,9 +114,9 @@ family: 'Darwin', name: 'Darwin', release: { - full: '13.3.0', - }, - }, + full: '13.3.0' + } + } }, { kernel: 'AIX', @@ -124,9 +124,9 @@ family: 'AIX', name: 'AIX', release: { - full: '7100-02-00-000', - }, - }, + full: '7100-02-00-000' + } + } }, { kernel: 'AIX', @@ -134,9 +134,9 @@ family: 'AIX', name: 'AIX', release: { - full: '6100-07-04-1216', - }, - }, + full: '6100-07-04-1216' + } + } }, { kernel: 'AIX', @@ -144,9 +144,9 @@ family: 'AIX', name: 'AIX', release: { - full: '5300-12-01-1016', - }, - }, + full: '5300-12-01-1016' + } + } }, ].each do |facts| let(:facts) { facts } diff --git a/spec/defines/sap_spec.rb b/spec/defines/sap_spec.rb index 97f23076..3340f332 100644 --- a/spec/defines/sap_spec.rb +++ b/spec/defines/sap_spec.rb @@ -14,7 +14,7 @@ java: 'jdk', basedir: '/usr/java', manage_symlink: true, - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk11_symlink' } @@ -76,20 +76,20 @@ { ensure: 'present', version_full: '11.0.7', - java: 'jdk', + java: 'jdk' } end let(:title) { 'jdk1107' } let(:pre_condition) do - <<-EOL + <<-MANIFEST java::sap { 'jdk1106': ensure => 'present', version_full => '11.0.6', java => 'jdk', } - EOL + MANIFEST end it { is_expected.to compile } @@ -101,13 +101,14 @@ ensure: 'present', version: '8', java: 'jdk', - basedir: '/usr/java', + 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 { @@ -115,7 +116,7 @@ version: '8', java: 'jdk', basedir: '/usr/java', - manage_basedir: true, + manage_basedir: true } end let(:title) { 'jdk8' } @@ -174,25 +175,26 @@ { ensure: 'present', version_full: '11.0.7', - java: 'jdk', + java: 'jdk' } end let(:title) { 'jdk1107' } let(:pre_condition) do - <<-EOL + <<-MANIFEST java::sap { 'jdk1106': ensure => 'present', version_full => '11.0.6', java => 'jdk', } - EOL + MANIFEST end it { is_expected.to compile } end end + describe 'incompatible OSes' do [ { @@ -201,9 +203,9 @@ family: 'Windows', name: 'Windows', release: { - full: '8.1', - }, - }, + full: '8.1' + } + } }, { kernel: 'Darwin', @@ -211,9 +213,9 @@ family: 'Darwin', name: 'Darwin', release: { - full: '13.3.0', - }, - }, + full: '13.3.0' + } + } }, { kernel: 'AIX', @@ -221,9 +223,9 @@ family: 'AIX', name: 'AIX', release: { - full: '7100-02-00-000', - }, - }, + full: '7100-02-00-000' + } + } }, { kernel: 'AIX', @@ -231,9 +233,9 @@ family: 'AIX', name: 'AIX', release: { - full: '6100-07-04-1216', - }, - }, + full: '6100-07-04-1216' + } + } }, { kernel: 'AIX', @@ -241,9 +243,9 @@ family: 'AIX', name: 'AIX', release: { - full: '5300-12-01-1016', - }, - }, + full: '5300-12-01-1016' + } + } }, ].each do |facts| let(:facts) { facts } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07db7342..c6e55257 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,7 @@ default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ @@ -26,7 +26,7 @@ begin default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end diff --git a/spec/unit/facter/java_default_home_spec.rb b/spec/unit/facter/java_default_home_spec.rb index af0841f6..0bb26367 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -8,17 +8,16 @@ java_8_home = '/usr/lib/jvm/oracle-java8-jre-amd64' def unlink_and_delete(filename) - if File.symlink?(filename) - File.unlink(filename) - end + File.unlink(filename) if File.symlink?(filename) 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::Core::Execution).to receive(:which).with('java').and_return('./java_test') - expect(File).to receive(:realpath).with('./java_test').and_return(symlink_path) + allow(Facter::Core::Execution).to receive(:which).with('java').and_return('./java_test') + allow(File).to receive(:realpath).with('./java_test').and_return(symlink_path) expect(Facter.value(:java_default_home)).to eql java_home end @@ -32,7 +31,7 @@ def symlink_and_test(symlink_path, java_home) 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) + expect { symlink_and_test(java_7_path, java_7_home) }.not_to raise_error unlink_and_delete('./java_test') end end @@ -40,7 +39,7 @@ def symlink_and_test(symlink_path, java_home) 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) + expect { symlink_and_test(java_8_path, java_8_home) }.not_to raise_error unlink_and_delete('./java_test') end end diff --git a/spec/unit/facter/java_libjvm_path_spec.rb b/spec/unit/facter/java_libjvm_path_spec.rb index dde5aa51..585dafa4 100644 --- a/spec/unit/facter/java_libjvm_path_spec.rb +++ b/spec/unit/facter/java_libjvm_path_spec.rb @@ -22,7 +22,7 @@ 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 + 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 62a3df7d..2260f41f 100644 --- a/spec/unit/facter/java_major_version_spec.rb +++ b/spec/unit/facter/java_major_version_spec.rb @@ -11,6 +11,7 @@ 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 @@ -20,6 +21,7 @@ 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 diff --git a/spec/unit/facter/java_patch_level_spec.rb b/spec/unit/facter/java_patch_level_spec.rb index 216fdec2..a8d66ca9 100644 --- a/spec/unit/facter/java_patch_level_spec.rb +++ b/spec/unit/facter/java_patch_level_spec.rb @@ -11,6 +11,7 @@ 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 @@ -20,6 +21,7 @@ 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 diff --git a/spec/unit/facter/java_version_spec.rb b/spec/unit/facter/java_version_spec.rb index d65097c0..821f940d 100644 --- a/spec/unit/facter/java_version_spec.rb +++ b/spec/unit/facter/java_version_spec.rb @@ -2,14 +2,14 @@ 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_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"\ +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 @@ -18,52 +18,58 @@ end context 'when java present, returns java version' do - context 'on OpenBSD', with_env: true do + context 'when on OpenBSD', with_env: true do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') end + let(:facts) { { operatingsystem: 'OpenBSD' } } it do - expect(Facter::Core::Execution).to receive(:which).with('java').and_return('/usr/local/jdk-1.7.0/jre/bin/java') - expect(Facter::Core::Execution).to receive(:execute).with('java -Xmx12m -version 2>&1').and_return(openjdk_7_output) + allow(Facter::Core::Execution).to receive(:which).with('java').and_return('/usr/local/jdk-1.7.0/jre/bin/java') + allow(Facter::Core::Execution).to receive(:execute).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(:kernel)).to receive(:value).and_return('Darwin') end + let(:facts) { { kernel: 'Darwin' } } it do - expect(Facter::Core::Execution).to receive(:execute).with('/usr/libexec/java_home --failfast', { on_fail: false }).and_return('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home') - expect(Facter::Core::Execution).to receive(:execute).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output) + allow(Facter::Core::Execution).to receive(:execute).with('/usr/libexec/java_home --failfast', { on_fail: false }).and_return('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home') + allow(Facter::Core::Execution).to receive(:execute).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 + context 'when on other systems' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS') allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') end + let(:facts) { { operatingsystem: 'MyOS' } } it do - expect(Facter::Core::Execution).to receive(:which).with('java').and_return('/path/to/java') - expect(Facter::Core::Execution).to receive(:execute).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output) + allow(Facter::Core::Execution).to receive(:which).with('java').and_return('/path/to/java') + allow(Facter::Core::Execution).to receive(:execute).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 + context 'when on OpenBSD', with_env: true do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') end + let(:facts) { { operatingsystem: 'OpenBSD' } } it do @@ -72,10 +78,12 @@ expect(Facter.value(:java_version)).to be_nil end end + context 'when on Darwin' do before(:each) do allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin') end + let(:facts) { { kernel: 'Darwin' } } it do @@ -83,11 +91,13 @@ 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') allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') end + let(:facts) { { operatingsystem: 'MyOS' } } it do