From fae3edbd7164a53a77a8095b6967e77ebf9b1ea0 Mon Sep 17 00:00:00 2001 From: david22swan Date: Fri, 31 Mar 2023 17:43:16 +0100 Subject: [PATCH 01/15] (MAINT) PDK Update --- .devcontainer/devcontainer.json | 2 +- Gemfile | 38 ++++++++++++++++----------------- Rakefile | 1 + metadata.json | 4 ++-- 4 files changed, 23 insertions(+), 22 deletions(-) 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/Gemfile b/Gemfile index 1881afe1..6886de2a 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 "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.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 "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 "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/metadata.json b/metadata.json index 578a1e85..586ceac7 100644 --- a/metadata.json +++ b/metadata.json @@ -81,6 +81,6 @@ } ], "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" } From 776bbd99265d35389211e9de50c28779c11343b7 Mon Sep 17 00:00:00 2001 From: david22swan Date: Fri, 31 Mar 2023 17:43:35 +0100 Subject: [PATCH 02/15] (CONT-784) Add Support for Puppet 8 / Drop Support for Puppet 6 --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 586ceac7..ad69c15d 100644 --- a/metadata.json +++ b/metadata.json @@ -77,7 +77,7 @@ "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", From 680d7a201f278329f63d08d8db4b5c32d835b383 Mon Sep 17 00:00:00 2001 From: david22swan Date: Fri, 31 Mar 2023 17:44:01 +0100 Subject: [PATCH 03/15] (CONT-784) Unpin puppet_agent --- .fixtures.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index fc5c840f..c675307e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,9 +3,7 @@ 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: - repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.12.1 + puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' provision: 'https://github.com/puppetlabs/provision.git' symlinks: java: "#{source_dir}" From c3255393c5fbc92390205b11de488916a9944d06 Mon Sep 17 00:00:00 2001 From: david22swan Date: Fri, 31 Mar 2023 17:44:17 +0100 Subject: [PATCH 04/15] (CONT-784) Unpin puppet_litmus --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 6886de2a..f1907698 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,7 @@ group :development do 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 "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] gem "serverspec", '~> 2.41', require: false end From 8de236e0c55be73cb8a52636b8215ff01116a324 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 12:16:38 +0100 Subject: [PATCH 05/15] (CONT-784) Update Rubocop Versions New Versions: rubocop = 1.48.1 rubocop-performance = 1.16.0 rubocop-rspec = 2.19.0 --- .rubocop.yml | 444 +--------------------------------------------- .rubocop_todo.yml | 201 +++++++++++++++++++++ Gemfile | 6 +- 3 files changed, 210 insertions(+), 441 deletions(-) create mode 100644 .rubocop_todo.yml 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..129b1735 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,201 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-17 11:16:28 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: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'spec/unit/facter/java_default_home_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstArgumentIndentation: + Exclude: + - 'spec/classes/java_spec.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'spec/classes/java_spec.rb' + +# Offense count: 12 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: leading, trailing +Layout/LineContinuationLeadingSpace: + Exclude: + - 'spec/acceptance/install_spec.rb' + +# Offense count: 27 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: space, no_space +Layout/LineContinuationSpacing: + Exclude: + - 'spec/acceptance/install_spec.rb' + - 'spec/unit/facter/java_version_spec.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/LineEndStringConcatenationIndentation: + Exclude: + - 'spec/acceptance/install_spec.rb' + +# Offense count: 12 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'spec/acceptance/install_spec.rb' + - 'spec/defines/adopt_spec.rb' + - 'spec/defines/adoptium_spec.rb' + - 'spec/defines/sap_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Performance/StringInclude: + Exclude: + - 'lib/facter/java_default_home.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: be, be_nil +RSpec/BeNil: + Exclude: + - 'spec/unit/facter/java_libjvm_path_spec.rb' + +# Offense count: 8 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/acceptance/install_spec.rb' + - 'spec/unit/facter/java_version_spec.rb' + +# 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: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowConsecutiveOneLiners. +RSpec/EmptyLineAfterExample: + Exclude: + - 'spec/classes/java_spec.rb' + +# Offense count: 11 +# This cop supports safe autocorrection (--autocorrect). +RSpec/EmptyLineAfterExampleGroup: + Exclude: + - 'spec/classes/java_spec.rb' + - 'spec/defines/adopt_spec.rb' + - 'spec/defines/adoptium_spec.rb' + - 'spec/defines/sap_spec.rb' + - 'spec/unit/facter/java_version_spec.rb' + +# Offense count: 10 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowConsecutiveOneLiners. +RSpec/EmptyLineAfterHook: + Exclude: + - '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: 1 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 6 + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit +RSpec/ImplicitSubject: + Exclude: + - 'spec/classes/java_spec.rb' + - 'spec/defines/download_spec.rb' + +# Offense count: 12 +# Configuration parameters: AllowedPatterns. +# AllowedPatterns: ^expect_, ^assert_ +RSpec/NoExpectationExample: + Exclude: + - 'spec/acceptance/install_spec.rb' + - 'spec/unit/facter/java_default_home_spec.rb' + +# Offense count: 8 +RSpec/StubbedMock: + Exclude: + - 'spec/unit/facter/java_default_home_spec.rb' + - 'spec/unit/facter/java_version_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/IfUnlessModifier: + Exclude: + - 'spec/unit/facter/java_default_home_spec.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantRegexpEscape: + Exclude: + - 'lib/facter/java_version.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 100 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - '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/spec_helper.rb' diff --git a/Gemfile b/Gemfile index f1907698..3f6f5c7d 100644 --- a/Gemfile +++ b/Gemfile @@ -30,9 +30,9 @@ group :development do 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 "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 From 6f30dbedbfb357d21927b755e7af3eace6911424 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 12:30:30 +0100 Subject: [PATCH 06/15] (CONT-784) Rubocop Auto Fixes 1-5 - Layout/EmptyLineAfterGuardClause - Layout/FirstArgumentIndentation - Layout/HashAlignment - Layout/LineContinuationLeadingSpace - Layout/LineContinuationSpacing --- .rubocop_todo.yml | 41 --------------------- spec/acceptance/install_spec.rb | 42 +++++++++++----------- spec/classes/java_spec.rb | 18 +++++----- spec/unit/facter/java_default_home_spec.rb | 1 + spec/unit/facter/java_version_spec.rb | 12 +++---- 5 files changed, 37 insertions(+), 77 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 129b1735..16508ce5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,47 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLineAfterGuardClause: - Exclude: - - 'spec/unit/facter/java_default_home_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Layout/FirstArgumentIndentation: - Exclude: - - 'spec/classes/java_spec.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'spec/classes/java_spec.rb' - -# Offense count: 12 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: leading, trailing -Layout/LineContinuationLeadingSpace: - Exclude: - - 'spec/acceptance/install_spec.rb' - -# Offense count: 27 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AutoCorrect, EnforcedStyle. -# SupportedStyles: space, no_space -Layout/LineContinuationSpacing: - Exclude: - - 'spec/acceptance/install_spec.rb' - - 'spec/unit/facter/java_version_spec.rb' - # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index 3dd4cb91..0c03ea58 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 diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index 35d477aa..b7834cb0 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -38,11 +38,11 @@ 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', - }, - ) + { + 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 @@ -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 diff --git a/spec/unit/facter/java_default_home_spec.rb b/spec/unit/facter/java_default_home_spec.rb index af0841f6..f6032ef7 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -12,6 +12,7 @@ def unlink_and_delete(filename) File.unlink(filename) end return unless File.exist?(filename) + File.delete(filename) end diff --git a/spec/unit/facter/java_version_spec.rb b/spec/unit/facter/java_version_spec.rb index d65097c0..f0375ff7 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 From 9484496f6e18fca37fe2a554dc3c083ec0ec64b4 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 12:34:24 +0100 Subject: [PATCH 07/15] (CONT-784) Rubocop Auto Fixes 6-10 - Layout/LineEndStringConcatenationIndentation - RSpec/BeNil - RSpec/EmptyLineAfterExample - RSpec/EmptyLineAfterExampleGroup - RSpec/EmptyLineAfterHook --- .rubocop_todo.yml | 42 --------------------- spec/acceptance/install_spec.rb | 16 ++++---- spec/classes/java_spec.rb | 3 ++ spec/defines/adopt_spec.rb | 2 + spec/defines/adoptium_spec.rb | 2 + spec/defines/sap_spec.rb | 2 + spec/unit/facter/java_libjvm_path_spec.rb | 2 +- spec/unit/facter/java_major_version_spec.rb | 2 + spec/unit/facter/java_patch_level_spec.rb | 2 + spec/unit/facter/java_version_spec.rb | 10 +++++ 10 files changed, 32 insertions(+), 51 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 16508ce5..90456554 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented -Layout/LineEndStringConcatenationIndentation: - Exclude: - - 'spec/acceptance/install_spec.rb' - # Offense count: 12 # Configuration parameters: ForbiddenDelimiters. # ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) @@ -30,14 +22,6 @@ Performance/StringInclude: Exclude: - 'lib/facter/java_default_home.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: be, be_nil -RSpec/BeNil: - Exclude: - - 'spec/unit/facter/java_libjvm_path_spec.rb' - # Offense count: 8 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without @@ -67,32 +51,6 @@ RSpec/DescribeClass: - 'spec/unit/facter/java_patch_level_spec.rb' - 'spec/unit/facter/java_version_spec.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterExample: - Exclude: - - 'spec/classes/java_spec.rb' - -# Offense count: 11 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyLineAfterExampleGroup: - Exclude: - - 'spec/classes/java_spec.rb' - - 'spec/defines/adopt_spec.rb' - - 'spec/defines/adoptium_spec.rb' - - 'spec/defines/sap_spec.rb' - - 'spec/unit/facter/java_version_spec.rb' - -# Offense count: 10 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterHook: - Exclude: - - '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: 1 # Configuration parameters: CountAsOne. RSpec/ExampleLength: diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index 0c03ea58..863738c2 100644 --- a/spec/acceptance/install_spec.rb +++ b/spec/acceptance/install_spec.rb @@ -10,18 +10,18 @@ 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" \ - '}' + "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" \ - '}' + "distribution => 'sun-jre',\n" \ + '}' _sun_jdk = "class { 'java':\n " \ - "distribution => 'sun-jdk',\n" \ - '}' + "distribution => 'sun-jdk',\n" \ + '}' blank_version = "class { 'java':\n " \ "version => '',\n" \ diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index b7834cb0..180d2516 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -36,6 +36,7 @@ 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( { @@ -44,6 +45,7 @@ }, ) } + it { is_expected.to contain_exec('update-java-alternatives').with_command(['alternatives', '--set', 'java', '/usr/java/jre1.7.0_67/bin/java']) } end @@ -189,6 +191,7 @@ 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 { diff --git a/spec/defines/adopt_spec.rb b/spec/defines/adopt_spec.rb index 6cc959da..c6d0035b 100644 --- a/spec/defines/adopt_spec.rb +++ b/spec/defines/adopt_spec.rb @@ -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 { @@ -296,6 +297,7 @@ it { is_expected.to compile } end end + describe 'incompatible OSes' do [ { diff --git a/spec/defines/adoptium_spec.rb b/spec/defines/adoptium_spec.rb index f9f82a1e..968e9627 100644 --- a/spec/defines/adoptium_spec.rb +++ b/spec/defines/adoptium_spec.rb @@ -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 { @@ -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 { diff --git a/spec/defines/sap_spec.rb b/spec/defines/sap_spec.rb index 97f23076..815c81aa 100644 --- a/spec/defines/sap_spec.rb +++ b/spec/defines/sap_spec.rb @@ -108,6 +108,7 @@ 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 { @@ -193,6 +194,7 @@ it { is_expected.to compile } end end + describe 'incompatible OSes' do [ { 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 f0375ff7..9ece9b61 100644 --- a/spec/unit/facter/java_version_spec.rb +++ b/spec/unit/facter/java_version_spec.rb @@ -23,6 +23,7 @@ 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 @@ -31,10 +32,12 @@ 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 @@ -43,11 +46,13 @@ 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 @@ -64,6 +69,7 @@ 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 From eac2c20a3101c5148cf00fc0a6e76a93f8ee0472 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 13:30:23 +0100 Subject: [PATCH 08/15] (CONT-784) Rubocop Auto Fixes 11-15 - RSpec/ImplicitSubject - Style/IfUnlessModifier - Style/RedundantRegexpEscape - Style/RescueStandardError - Style/TrailingCommaInHashLiteral --- .rubocop_todo.yml | 42 ++--------------- lib/facter/java_version.rb | 2 +- spec/classes/java_spec.rb | 28 +++++------ spec/defines/adopt_spec.rb | 40 ++++++++-------- spec/defines/adoptium_spec.rb | 54 +++++++++++----------- spec/defines/download_spec.rb | 42 ++++++++--------- spec/defines/sap_spec.rb | 40 ++++++++-------- spec/spec_helper.rb | 4 +- spec/unit/facter/java_default_home_spec.rb | 4 +- 9 files changed, 110 insertions(+), 146 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 90456554..66066be1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-04-17 11:16:28 UTC using RuboCop version 1.48.1. +# 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 @@ -57,10 +57,9 @@ RSpec/ExampleLength: Max: 6 # Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit -RSpec/ImplicitSubject: +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: Exclude: - 'spec/classes/java_spec.rb' - 'spec/defines/download_spec.rb' @@ -79,40 +78,7 @@ RSpec/StubbedMock: - 'spec/unit/facter/java_default_home_spec.rb' - 'spec/unit/facter/java_version_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'spec/unit/facter/java_default_home_spec.rb' - # Offense count: 1 Style/MixinUsage: Exclude: - 'spec/spec_helper.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpEscape: - Exclude: - - 'lib/facter/java_version.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'spec/spec_helper.rb' - -# Offense count: 100 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - '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/spec_helper.rb' 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/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index 180d2516..f049a2eb 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -38,10 +38,10 @@ it { is_expected.to contain_package('java').with_name('jre') } it { - is_expected.to contain_exec('create-java-alternatives').with( + 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', + unless: 'alternatives --display java | grep -q /usr/java/jre1.7.0_67/bin/java' }, ) } @@ -183,7 +183,7 @@ '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 @@ -196,7 +196,7 @@ let(:params) do { 'distribution' => 'custom', - 'package' => 'custom_jdk', + 'package' => 'custom_jdk' } end @@ -212,36 +212,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 c6d0035b..6d725b54 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,7 +125,7 @@ ensure: 'present', version_major: '8u202', version_minor: 'b08', - java: 'jdk', + java: 'jdk' } end let(:title) { 'jdk8' } @@ -152,7 +152,7 @@ version: '8', java: 'jdk', basedir: '/usr/java', - package_type: 'tar.gz', + package_type: 'tar.gz' } end let(:title) { 'jdk8' } @@ -169,7 +169,7 @@ version: '8', java: 'jdk', basedir: '/usr/java', - manage_basedir: true, + manage_basedir: true } end let(:title) { 'jdk8' } @@ -277,7 +277,7 @@ ensure: 'present', version_major: '8u202', version_minor: 'b08', - java: 'jdk', + java: 'jdk' } end let(:title) { 'jdk8' } @@ -306,9 +306,9 @@ family: 'Windows', name: 'Windows', release: { - full: '8.1', - }, - }, + full: '8.1' + } + } }, { kernel: 'Darwin', @@ -316,9 +316,9 @@ family: 'Darwin', name: 'Darwin', release: { - full: '13.3.0', - }, - }, + full: '13.3.0' + } + } }, { kernel: 'AIX', @@ -326,9 +326,9 @@ family: 'AIX', name: 'AIX', release: { - full: '7100-02-00-000', - }, - }, + full: '7100-02-00-000' + } + } }, { kernel: 'AIX', @@ -336,9 +336,9 @@ family: 'AIX', name: 'AIX', release: { - full: '6100-07-04-1216', - }, - }, + full: '6100-07-04-1216' + } + } }, { kernel: 'AIX', @@ -346,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 968e9627..1ce7a192 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,7 +86,7 @@ version_major: '16', version_minor: '0', version_patch: '2', - version_build: '7', + version_build: '7' } end let(:title) { 'jdk16' } @@ -115,7 +115,7 @@ version_minor: '0', version_patch: '2', version_build: '7', - basedir: '/usr/java', + basedir: '/usr/java' } end let(:title) { 'jdk16' } @@ -134,7 +134,7 @@ version_patch: '2', version_build: '7', basedir: '/usr/java', - manage_basedir: true, + manage_basedir: true } end let(:title) { 'jdk16' } @@ -154,7 +154,7 @@ version_minor: '0', version_patch: '2', version_build: '7', - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk16' } @@ -172,7 +172,7 @@ version_minor: '0', version_patch: '1', version_build: '12', - symlink_name: 'java_home', + symlink_name: 'java_home' } end let(:title) { 'jdk17' } @@ -189,7 +189,7 @@ version_major: '16', version_minor: '0', version_patch: '2', - version_build: '7', + version_build: '7' } end let(:title) { 'jdk16' } @@ -218,7 +218,7 @@ version_minor: '0', version_patch: '2', version_build: '7', - basedir: '/usr/lib/jvm', + basedir: '/usr/lib/jvm' } end let(:title) { 'jdk16' } @@ -237,7 +237,7 @@ version_patch: '2', version_build: '7', basedir: '/usr/lib/jvm', - manage_basedir: true, + manage_basedir: true } end let(:title) { 'jdk16' } @@ -254,9 +254,9 @@ family: 'Windows', name: 'Windows', release: { - full: '8.1', - }, - }, + full: '8.1' + } + } }, { kernel: 'Darwin', @@ -264,9 +264,9 @@ family: 'Darwin', name: 'Darwin', release: { - full: '13.3.0', - }, - }, + full: '13.3.0' + } + } }, { kernel: 'AIX', @@ -274,9 +274,9 @@ family: 'AIX', name: 'AIX', release: { - full: '7100-02-00-000', - }, - }, + full: '7100-02-00-000' + } + } }, { kernel: 'AIX', @@ -284,9 +284,9 @@ family: 'AIX', name: 'AIX', release: { - full: '6100-07-04-1216', - }, - }, + full: '6100-07-04-1216' + } + } }, { kernel: 'AIX', @@ -294,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 815c81aa..bad2d677 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,7 +76,7 @@ { ensure: 'present', version_full: '11.0.7', - java: 'jdk', + java: 'jdk' } end let(:title) { 'jdk1107' } @@ -101,7 +101,7 @@ ensure: 'present', version: '8', java: 'jdk', - basedir: '/usr/java', + basedir: '/usr/java' } end let(:title) { 'jdk8' } @@ -116,7 +116,7 @@ version: '8', java: 'jdk', basedir: '/usr/java', - manage_basedir: true, + manage_basedir: true } end let(:title) { 'jdk8' } @@ -175,7 +175,7 @@ { ensure: 'present', version_full: '11.0.7', - java: 'jdk', + java: 'jdk' } end let(:title) { 'jdk1107' } @@ -203,9 +203,9 @@ family: 'Windows', name: 'Windows', release: { - full: '8.1', - }, - }, + full: '8.1' + } + } }, { kernel: 'Darwin', @@ -213,9 +213,9 @@ family: 'Darwin', name: 'Darwin', release: { - full: '13.3.0', - }, - }, + full: '13.3.0' + } + } }, { kernel: 'AIX', @@ -223,9 +223,9 @@ family: 'AIX', name: 'AIX', release: { - full: '7100-02-00-000', - }, - }, + full: '7100-02-00-000' + } + } }, { kernel: 'AIX', @@ -233,9 +233,9 @@ family: 'AIX', name: 'AIX', release: { - full: '6100-07-04-1216', - }, - }, + full: '6100-07-04-1216' + } + } }, { kernel: 'AIX', @@ -243,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 f6032ef7..9f105d1d 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -8,9 +8,7 @@ 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) From 38098a2b327e48dc5dea90cadb25545258645002 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 13:53:09 +0100 Subject: [PATCH 09/15] (CONT-784) Rubocop Unsafe Auto Fixes 1 - Performance/StringInclude --- .rubocop_todo.yml | 6 ------ lib/facter/java_default_home.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 66066be1..b8a320fb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -16,12 +16,6 @@ Naming/HeredocDelimiterNaming: - 'spec/defines/adoptium_spec.rb' - 'spec/defines/sap_spec.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Performance/StringInclude: - Exclude: - - 'lib/facter/java_default_home.rb' - # Offense count: 8 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without 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)) From 08bab67083e330d596e8f11b7afa9b24bd5135a0 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 14:48:03 +0100 Subject: [PATCH 10/15] (CONT-784) Rubocop Manual Fixes 1 - Naming/HeredocDelimiterNaming --- .rubocop_todo.yml | 10 ---------- spec/acceptance/install_spec.rb | 24 ++++++++++++------------ spec/defines/adopt_spec.rb | 8 ++++---- spec/defines/adoptium_spec.rb | 8 ++++---- spec/defines/sap_spec.rb | 8 ++++---- 5 files changed, 24 insertions(+), 34 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b8a320fb..5f836dbb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,16 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 12 -# Configuration parameters: ForbiddenDelimiters. -# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) -Naming/HeredocDelimiterNaming: - Exclude: - - 'spec/acceptance/install_spec.rb' - - 'spec/defines/adopt_spec.rb' - - 'spec/defines/adoptium_spec.rb' - - 'spec/defines/sap_spec.rb' - # Offense count: 8 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index 863738c2..0e5c1264 100644 --- a/spec/acceptance/install_spec.rb +++ b/spec/acceptance/install_spec.rb @@ -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,7 +208,7 @@ version_full => '#{sap_version14_full}', java => 'jdk', } -EOL +MANIFEST describe 'installing' do context 'installing java jre' do diff --git a/spec/defines/adopt_spec.rb b/spec/defines/adopt_spec.rb index 6d725b54..1d97a0c7 100644 --- a/spec/defines/adopt_spec.rb +++ b/spec/defines/adopt_spec.rb @@ -131,7 +131,7 @@ 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 } @@ -283,7 +283,7 @@ let(:title) { 'jdk8' } let(:pre_condition) do - <<-EOL + <<-MANIFEST java::adopt { 'jdk8172': ensure => 'present', @@ -291,7 +291,7 @@ version_minor => 'b11', java => 'jdk', } - EOL + MANIFEST end it { is_expected.to compile } diff --git a/spec/defines/adoptium_spec.rb b/spec/defines/adoptium_spec.rb index 1ce7a192..ba268912 100644 --- a/spec/defines/adoptium_spec.rb +++ b/spec/defines/adoptium_spec.rb @@ -92,7 +92,7 @@ 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 } @@ -195,7 +195,7 @@ let(:title) { 'jdk16' } let(:pre_condition) do - <<-EOL + <<-MANIFEST java::adoptium { 'jdk17': ensure => 'present', @@ -204,7 +204,7 @@ version_patch => '1', version_build => '12', } - EOL + MANIFEST end it { is_expected.to compile } diff --git a/spec/defines/sap_spec.rb b/spec/defines/sap_spec.rb index bad2d677..3340f332 100644 --- a/spec/defines/sap_spec.rb +++ b/spec/defines/sap_spec.rb @@ -82,14 +82,14 @@ 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 } @@ -181,14 +181,14 @@ 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 } From 99090961f58482709381c355365f42f74f11cdae Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 14:50:57 +0100 Subject: [PATCH 11/15] (CONT-784) Rubocop Manual Fixes 2 - RSpec/ContextWording --- .rubocop_todo.yml | 8 ----- spec/acceptance/install_spec.rb | 14 ++++----- spec/classes/java_spec.rb | 44 +++++++++++++-------------- spec/unit/facter/java_version_spec.rb | 4 +-- 4 files changed, 31 insertions(+), 39 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5f836dbb..3fe23e73 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 8 -# Configuration parameters: Prefixes, AllowedPatterns. -# Prefixes: when, with, without -RSpec/ContextWording: - Exclude: - - 'spec/acceptance/install_spec.rb' - - 'spec/unit/facter/java_version_spec.rb' - # Offense count: 11 # Configuration parameters: IgnoredMetadata. RSpec/DescribeClass: diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index 0e5c1264..6e3a1d3f 100644 --- a/spec/acceptance/install_spec.rb +++ b/spec/acceptance/install_spec.rb @@ -211,19 +211,19 @@ MANIFEST describe 'installing' do - context 'installing java jre' do + context 'when installing java jre' do it 'installs jre' do idempotent_apply(java_class_jre) end end - context 'installing java jdk' do + context 'when installing java jdk' do it 'installs jdk' do idempotent_apply(java_class) 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) end @@ -249,7 +249,7 @@ 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 @@ -279,7 +279,7 @@ 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 @@ -293,7 +293,7 @@ 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 @@ -307,7 +307,7 @@ 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 diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index f049a2eb..a3462671 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -3,35 +3,35 @@ 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' } } @@ -49,14 +49,14 @@ 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' } } @@ -64,14 +64,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' } } @@ -79,7 +79,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' } } @@ -87,7 +87,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' } } @@ -95,7 +95,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' } } @@ -103,26 +103,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' } } @@ -130,7 +130,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' } } @@ -138,35 +138,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') } diff --git a/spec/unit/facter/java_version_spec.rb b/spec/unit/facter/java_version_spec.rb index 9ece9b61..8b42f87a 100644 --- a/spec/unit/facter/java_version_spec.rb +++ b/spec/unit/facter/java_version_spec.rb @@ -18,7 +18,7 @@ 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') @@ -64,7 +64,7 @@ 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') From 0e90b58a8118dd6642eec4545d9dc2236ea50bc9 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 14:53:54 +0100 Subject: [PATCH 12/15] (CONT-784) Rubocop Manual Fixes 3 - RSpec/ExampleLength --- .rubocop_todo.yml | 5 ----- spec/classes/java_spec.rb | 6 ++---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3fe23e73..6dc83c2f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -27,11 +27,6 @@ RSpec/DescribeClass: - 'spec/unit/facter/java_patch_level_spec.rb' - 'spec/unit/facter/java_version_spec.rb' -# Offense count: 1 -# Configuration parameters: CountAsOne. -RSpec/ExampleLength: - Max: 6 - # Offense count: 3 # Configuration parameters: EnforcedStyle, IgnoreSharedExamples. # SupportedStyles: always, named_only diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index a3462671..de2f3966 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -39,10 +39,8 @@ it { 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' - }, + { 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' }, ) } From 06fd02bc5140e8d7d00f41bf21bc6390b7e35d83 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 14:58:47 +0100 Subject: [PATCH 13/15] (CONT-784) Rubocop Manual Fixes 4 - RSpec/StubbedMock --- .rubocop_todo.yml | 6 ------ spec/unit/facter/java_default_home_spec.rb | 4 ++-- spec/unit/facter/java_version_spec.rb | 12 ++++++------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6dc83c2f..0157c284 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -43,12 +43,6 @@ RSpec/NoExpectationExample: - 'spec/acceptance/install_spec.rb' - 'spec/unit/facter/java_default_home_spec.rb' -# Offense count: 8 -RSpec/StubbedMock: - Exclude: - - 'spec/unit/facter/java_default_home_spec.rb' - - 'spec/unit/facter/java_version_spec.rb' - # Offense count: 1 Style/MixinUsage: Exclude: diff --git a/spec/unit/facter/java_default_home_spec.rb b/spec/unit/facter/java_default_home_spec.rb index 9f105d1d..480fec9d 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -16,8 +16,8 @@ def unlink_and_delete(filename) 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 diff --git a/spec/unit/facter/java_version_spec.rb b/spec/unit/facter/java_version_spec.rb index 8b42f87a..821f940d 100644 --- a/spec/unit/facter/java_version_spec.rb +++ b/spec/unit/facter/java_version_spec.rb @@ -27,8 +27,8 @@ 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 @@ -41,8 +41,8 @@ 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 @@ -56,8 +56,8 @@ 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 From 572fd1e1d3f290a54200d46bb1a1be221fb5a6f9 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 15:25:14 +0100 Subject: [PATCH 14/15] (CONT-784) Rubocop Manual Fixes 5 - RSpec/NoExpectationExample --- .rubocop_todo.yml | 8 ------- spec/acceptance/install_spec.rb | 28 +++++++++++----------- spec/unit/facter/java_default_home_spec.rb | 4 ++-- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0157c284..b9ca46bc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -35,14 +35,6 @@ RSpec/NamedSubject: - 'spec/classes/java_spec.rb' - 'spec/defines/download_spec.rb' -# Offense count: 12 -# Configuration parameters: AllowedPatterns. -# AllowedPatterns: ^expect_, ^assert_ -RSpec/NoExpectationExample: - Exclude: - - 'spec/acceptance/install_spec.rb' - - 'spec/unit/facter/java_default_home_spec.rb' - # Offense count: 1 Style/MixinUsage: Exclude: diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index 6e3a1d3f..2dd687f3 100644 --- a/spec/acceptance/install_spec.rb +++ b/spec/acceptance/install_spec.rb @@ -213,38 +213,38 @@ describe 'installing' 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 '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 '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 @@ -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,13 +267,13 @@ 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 @@ -289,7 +289,7 @@ 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 @@ -303,7 +303,7 @@ 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 @@ -313,7 +313,7 @@ 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/unit/facter/java_default_home_spec.rb b/spec/unit/facter/java_default_home_spec.rb index 480fec9d..0bb26367 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -31,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 @@ -39,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 From c59589144b1a3ee933a03353030aff85be3c07bd Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 17 Apr 2023 15:29:13 +0100 Subject: [PATCH 15/15] (CONT-784) Repin puppet_agent --- .fixtures.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index c675307e..4de712c2 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,7 +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: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + puppet_agent: + repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + ref: v4.13.0 provision: 'https://github.com/puppetlabs/provision.git' symlinks: java: "#{source_dir}"