From 7024bc8066acd0070819d44956fea1028d739ce7 Mon Sep 17 00:00:00 2001 From: Eimhin Laverty Date: Mon, 17 Jun 2019 11:47:45 +0100 Subject: [PATCH] (FM-8253) Run pdk-update and re-enable rubocop This commit updates the pdk-template to heads/master-0-g7b1d6ae. Additionally, in order to align the module with other supported modules I have re-enabled rubocop which is what the majority of the changes in this commit are for. --- .gitignore | 2 + .pdkignore | 4 + .puppet-lint.rc | 1 + .rubocop.yml | 712 ++---------------- .sync.yml | 5 +- .travis.yml | 37 +- .vscode/extensions.json | 6 + Gemfile | 160 ++-- Rakefile | 15 - appveyor.yml | 1 + lib/facter/choco_install_path.rb | 2 +- lib/facter/choco_temp_dir.rb | 2 +- lib/facter/chocolateyversion.rb | 2 +- .../provider/chocolateyconfig/windows.rb | 39 +- .../provider/chocolateyfeature/windows.rb | 33 +- .../provider/chocolateysource/windows.rb | 57 +- lib/puppet/provider/package/chocolatey.rb | 160 ++-- lib/puppet/type/chocolateyconfig.rb | 20 +- lib/puppet/type/chocolateyfeature.rb | 11 +- lib/puppet/type/chocolateysource.rb | 62 +- lib/puppet_x/chocolatey/chocolatey_common.rb | 161 ++-- lib/puppet_x/chocolatey/chocolatey_install.rb | 47 +- lib/puppet_x/chocolatey/chocolatey_version.rb | 44 +- metadata.json | 8 +- spec/acceptance/config_values_spec.rb | 23 +- spec/acceptance/features_spec.rb | 104 ++- spec/acceptance/package_spec.rb | 70 +- spec/acceptance/sources_spec.rb | 456 ++++++----- spec/classes/config_spec.rb | 49 +- spec/classes/init_spec.rb | 196 +++-- spec/classes/install_spec.rb | 53 +- spec/spec_helper.rb | 4 +- spec/spec_helper_acceptance.rb | 4 +- spec/spec_helper_local.rb | 12 +- spec/support/examples/failing_manifest.rb | 9 +- .../examples/manifest_removes_value.rb | 10 +- .../examples/password_value_should_be.rb | 14 +- .../examples/successful_config_change.rb | 9 +- spec/support/utilities/helpers.rb | 24 +- spec/unit/facter/choco_install_path_spec.rb | 14 +- spec/unit/facter/choco_temp_dir.rb | 13 +- spec/unit/facter/chocolateyversion_spec.rb | 15 +- .../provider/chocolateyconfig/windows_spec.rb | 174 +++-- .../chocolateyfeature/windows_spec.rb | 102 +-- .../provider/chocolateysource/windows_spec.rb | 602 ++++++--------- .../provider/package/chocolatey_spec.rb | 632 ++++++++-------- .../unit/puppet/type/chocolateyconfig_spec.rb | 51 +- .../puppet/type/chocolateyfeature_spec.rb | 32 +- .../unit/puppet/type/chocolateysource_spec.rb | 82 +- .../chocolatey/chocolatey_common_spec.rb | 30 +- .../chocolatey/chocolatey_install_spec.rb | 107 +-- .../chocolatey/chocolatey_version_spec.rb | 26 +- 52 files changed, 1872 insertions(+), 2636 deletions(-) create mode 100644 .vscode/extensions.json diff --git a/.gitignore b/.gitignore index 650022e5..3f4e2e84 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ /convert_report.txt /update_report.txt .DS_Store +.envrc +/inventory.yaml diff --git a/.pdkignore b/.pdkignore index b713b3b1..54d2cda3 100644 --- a/.pdkignore +++ b/.pdkignore @@ -22,6 +22,8 @@ /convert_report.txt /update_report.txt .DS_Store +.envrc +/inventory.yaml /appveyor.yml /.fixtures.yml /Gemfile @@ -30,8 +32,10 @@ /.gitlab-ci.yml /.pdkignore /Rakefile +/rakelib/ /.rspec /.rubocop.yml /.travis.yml /.yardopts /spec/ +/.vscode/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc index e69de29b..cc96ece0 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -0,0 +1 @@ +--relative diff --git a/.rubocop.yml b/.rubocop.yml index f8d2f89a..71b6810a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,7 @@ --- -require: rubocop-rspec +require: +- rubocop-rspec +- rubocop-i18n AllCops: DisplayCopNames: true TargetRubyVersion: '2.1' @@ -17,274 +19,88 @@ AllCops: - "**/Vagrantfile" - "**/Guardfile" inherit_from: ".rubocop_todo.yml" -Bundler/DuplicatedGem: - Enabled: false -Bundler/OrderedGems: - Enabled: false -Layout/AccessModifierIndentation: - Enabled: false -Layout/AlignArray: - Enabled: false -Layout/AlignHash: - Enabled: false -Layout/AlignParameters: - Enabled: false -Layout/BlockEndNewline: - Enabled: false -Layout/CaseIndentation: - Enabled: false -Layout/ClosingParenthesisIndentation: - Enabled: false -Layout/CommentIndentation: - Enabled: false -Layout/DotPosition: - Enabled: false -Layout/ElseAlignment: - Enabled: false -Layout/EmptyLineAfterMagicComment: - Enabled: false -Layout/EmptyLineBetweenDefs: - Enabled: false -Layout/EmptyLines: - Enabled: false -Layout/EmptyLinesAroundAccessModifier: - Enabled: false -Layout/EmptyLinesAroundBeginBody: - Enabled: false -Layout/EmptyLinesAroundBlockBody: - Enabled: false -Layout/EmptyLinesAroundClassBody: - Enabled: false -Layout/EmptyLinesAroundExceptionHandlingKeywords: - Enabled: false -Layout/EmptyLinesAroundMethodBody: - Enabled: false -Layout/EmptyLinesAroundModuleBody: +Metrics/LineLength: + Description: People have wide screens, use them. + Max: 200 +GetText: Enabled: false +GetText/DecorateString: + Description: We don't want to decorate test output. + Exclude: + - spec/**/* +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/FormatString: + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 + EnforcedStyle: percent_r +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +Style/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true Layout/EndOfLine: Enabled: false -Layout/ExtraSpacing: - Enabled: false -Layout/FirstParameterIndentation: - Enabled: false -Layout/IndentArray: - Enabled: false -Layout/IndentAssignment: - Enabled: false -Layout/IndentHash: - Enabled: false Layout/IndentHeredoc: Enabled: false -Layout/IndentationConsistency: - Enabled: false -Layout/IndentationWidth: - Enabled: false -Layout/InitialIndentation: - Enabled: false -Layout/LeadingCommentSpace: - Enabled: false -Layout/MultilineArrayBraceLayout: - Enabled: false -Layout/MultilineBlockLayout: - Enabled: false -Layout/MultilineHashBraceLayout: - Enabled: false -Layout/MultilineMethodCallBraceLayout: - Enabled: false -Layout/MultilineMethodCallIndentation: - Enabled: false -Layout/MultilineMethodDefinitionBraceLayout: - Enabled: false -Layout/MultilineOperationIndentation: - Enabled: false -Layout/RescueEnsureAlignment: - Enabled: false -Layout/SpaceAfterColon: - Enabled: false -Layout/SpaceAfterComma: - Enabled: false -Layout/SpaceAfterMethodName: - Enabled: false -Layout/SpaceAfterNot: - Enabled: false -Layout/SpaceAfterSemicolon: - Enabled: false -Layout/SpaceAroundBlockParameters: - Enabled: false -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: false -Layout/SpaceAroundKeyword: - Enabled: false -Layout/SpaceAroundOperators: - Enabled: false -Layout/SpaceBeforeBlockBraces: - Enabled: false -Layout/SpaceBeforeComma: - Enabled: false -Layout/SpaceBeforeComment: - Enabled: false -Layout/SpaceBeforeFirstArg: - Enabled: false -Layout/SpaceBeforeSemicolon: - Enabled: false -Layout/SpaceInLambdaLiteral: - Enabled: false -Layout/SpaceInsideArrayPercentLiteral: - Enabled: false -Layout/SpaceInsideBlockBraces: - Enabled: false -Layout/SpaceInsideBrackets: - Enabled: false -Layout/SpaceInsideHashLiteralBraces: - Enabled: false -Layout/SpaceInsideParens: - Enabled: false -Layout/SpaceInsidePercentLiteralDelimiters: - Enabled: false -Layout/SpaceInsideRangeLiteral: - Enabled: false -Layout/SpaceInsideStringInterpolation: - Enabled: false -Layout/Tab: - Enabled: false -Layout/TrailingBlankLines: - Enabled: false -Layout/TrailingWhitespace: - Enabled: false -Lint/AmbiguousBlockAssociation: - Enabled: false -Lint/AmbiguousOperator: - Enabled: false -Lint/AmbiguousRegexpLiteral: - Enabled: false -Lint/AssignmentInCondition: - Enabled: false -Lint/BlockAlignment: - Enabled: false -Lint/CircularArgumentReference: - Enabled: false -Lint/ConditionPosition: - Enabled: false -Lint/Debugger: - Enabled: false -Lint/DefEndAlignment: - Enabled: false -Lint/DeprecatedClassMethods: - Enabled: false -Lint/DuplicateCaseCondition: - Enabled: false -Lint/DuplicateMethods: - Enabled: false -Lint/DuplicatedKey: - Enabled: false -Lint/EachWithObjectArgument: - Enabled: false -Lint/ElseLayout: - Enabled: false -Lint/EmptyEnsure: - Enabled: false -Lint/EmptyExpression: - Enabled: false -Lint/EmptyInterpolation: - Enabled: false -Lint/EmptyWhen: - Enabled: false -Lint/EndAlignment: - Enabled: false -Lint/EndInMethod: - Enabled: false -Lint/EnsureReturn: - Enabled: false -Lint/FloatOutOfRange: - Enabled: false -Lint/FormatParameterMismatch: - Enabled: false -Lint/HandleExceptions: - Enabled: false -Lint/ImplicitStringConcatenation: - Enabled: false -Lint/IneffectiveAccessModifier: - Enabled: false -Lint/InheritException: - Enabled: false -Lint/InvalidCharacterLiteral: - Enabled: false -Lint/LiteralInCondition: - Enabled: false -Lint/LiteralInInterpolation: - Enabled: false -Lint/Loop: - Enabled: false -Lint/MultipleCompare: - Enabled: false -Lint/NestedMethodDefinition: - Enabled: false -Lint/NextWithoutAccumulator: - Enabled: false -Lint/NonLocalExitFromIterator: - Enabled: false -Lint/ParenthesesAsGroupedExpression: - Enabled: false -Lint/PercentStringArray: - Enabled: false -Lint/PercentSymbolArray: - Enabled: false -Lint/RandOne: - Enabled: false -Lint/RequireParentheses: - Enabled: false -Lint/RescueException: - Enabled: false -Lint/RescueType: - Enabled: false -Lint/SafeNavigationChain: - Enabled: false -Lint/ScriptPermission: - Enabled: false -Lint/ShadowedException: - Enabled: false -Lint/ShadowingOuterLocalVariable: - Enabled: false -Lint/StringConversionInInterpolation: - Enabled: false -Lint/UnderscorePrefixedVariableName: - Enabled: false -Lint/UnifiedInteger: - Enabled: false -Lint/UnneededDisable: - Enabled: false -Lint/UnneededSplatExpansion: - Enabled: false -Lint/UnreachableCode: - Enabled: false -Lint/UnusedBlockArgument: - Enabled: false -Lint/UnusedMethodArgument: - Enabled: false -Lint/UselessAccessModifier: - Enabled: false -Lint/UselessAssignment: - Enabled: false -Lint/UselessComparison: - Enabled: false -Lint/UselessElseWithoutRescue: - Enabled: false -Lint/UselessSetterCall: - Enabled: false -Lint/Void: - Enabled: false Metrics/AbcSize: Enabled: false Metrics/BlockLength: Enabled: false -Metrics/BlockNesting: - Enabled: false Metrics/ClassLength: Enabled: false Metrics/CyclomaticComplexity: Enabled: false -Metrics/LineLength: - Enabled: false Metrics/MethodLength: Enabled: false Metrics/ModuleLength: @@ -293,403 +109,19 @@ Metrics/ParameterLists: Enabled: false Metrics/PerceivedComplexity: Enabled: false -Performance/Caller: - Enabled: false -Performance/CaseWhenSplat: - Enabled: false -Performance/Casecmp: - Enabled: false -Performance/CompareWithBlock: - Enabled: false -Performance/Count: - Enabled: false -Performance/Detect: - Enabled: false -Performance/DoubleStartEndWith: - Enabled: false -Performance/EndWith: - Enabled: false -Performance/FixedSize: - Enabled: false -Performance/FlatMap: - Enabled: false -Performance/HashEachMethods: - Enabled: false -Performance/LstripRstrip: - Enabled: false -Performance/RangeInclude: - Enabled: false -Performance/RedundantBlockCall: - Enabled: false -Performance/RedundantMatch: - Enabled: false -Performance/RedundantMerge: - Enabled: false -Performance/RedundantSortBy: - Enabled: false -Performance/RegexpMatch: - Enabled: false -Performance/ReverseEach: - Enabled: false -Performance/Sample: - Enabled: false -Performance/Size: - Enabled: false -Performance/StartWith: - Enabled: false -Performance/StringReplacement: - Enabled: false -Performance/TimesMap: - Enabled: false -RSpec/AnyInstance: - Enabled: false -RSpec/AroundBlock: - Enabled: false -RSpec/BeEql: - Enabled: false -RSpec/BeforeAfterAll: - Enabled: false RSpec/DescribeClass: Enabled: false -RSpec/DescribeMethod: - Enabled: false -RSpec/DescribeSymbol: - Enabled: false -RSpec/DescribedClass: - Enabled: false -RSpec/EmptyExampleGroup: - Enabled: false -RSpec/EmptyLineAfterFinalLet: - Enabled: false -RSpec/EmptyLineAfterSubject: - Enabled: false RSpec/ExampleLength: Enabled: false -RSpec/ExampleWording: - Enabled: false -RSpec/ExpectActual: - Enabled: false -RSpec/ExpectOutput: - Enabled: false -RSpec/FilePath: - Enabled: false -RSpec/Focus: - Enabled: false -RSpec/HookArgument: - Enabled: false -RSpec/ImplicitExpect: - Enabled: false -RSpec/InstanceSpy: - Enabled: false -RSpec/InstanceVariable: - Enabled: false -RSpec/ItBehavesLike: - Enabled: false -RSpec/IteratedExpectation: - Enabled: false -RSpec/LeadingSubject: - Enabled: false -RSpec/LetSetup: - Enabled: false -RSpec/MessageChain: - Enabled: false RSpec/MessageExpectation: Enabled: false -RSpec/MessageSpies: - Enabled: false -RSpec/MultipleDescribes: - Enabled: false RSpec/MultipleExpectations: Enabled: false -RSpec/NamedSubject: - Enabled: false RSpec/NestedGroups: Enabled: false -RSpec/NotToNot: - Enabled: false -RSpec/OverwritingSetup: - Enabled: false -RSpec/RepeatedDescription: - Enabled: false -RSpec/RepeatedExample: - Enabled: false -RSpec/ScatteredLet: - Enabled: false -RSpec/ScatteredSetup: - Enabled: false -RSpec/SharedContext: - Enabled: false -RSpec/SingleArgumentMessageChain: - Enabled: false -RSpec/SubjectStub: - Enabled: false -RSpec/VerifiedDoubles: - Enabled: false -Security/Eval: - Enabled: false -Security/JSONLoad: - Enabled: false -Security/MarshalLoad: - Enabled: false -Security/YAMLLoad: - Enabled: false -Style/AccessorMethodName: - Enabled: false -Style/Alias: - Enabled: false -Style/AndOr: - Enabled: false -Style/ArrayJoin: - Enabled: false Style/AsciiComments: Enabled: false -Style/AsciiIdentifiers: - Enabled: false -Style/Attr: - Enabled: false -Style/BarePercentLiterals: - Enabled: false -Style/BeginBlock: - Enabled: false -Style/BlockComments: - Enabled: false -Style/BlockDelimiters: - Enabled: false -Style/BracesAroundHashParameters: - Enabled: false -Style/CaseEquality: - Enabled: false -Style/CharacterLiteral: - Enabled: false -Style/ClassAndModuleCamelCase: - Enabled: false -Style/ClassAndModuleChildren: - Enabled: false -Style/ClassCheck: - Enabled: false -Style/ClassMethods: - Enabled: false -Style/ClassVars: - Enabled: false -Style/ColonMethodCall: - Enabled: false -Style/CommandLiteral: - Enabled: false -Style/CommentAnnotation: - Enabled: false -Style/ConditionalAssignment: - Enabled: false -Style/ConstantName: - Enabled: false -Style/DefWithParentheses: - Enabled: false -Style/Documentation: - Enabled: false -Style/DoubleNegation: - Enabled: false -Style/EachForSimpleLoop: - Enabled: false -Style/EachWithObject: - Enabled: false -Style/EmptyCaseCondition: - Enabled: false -Style/EmptyElse: - Enabled: false -Style/EmptyLiteral: - Enabled: false -Style/EmptyMethod: - Enabled: false -Style/EndBlock: - Enabled: false -Style/EvenOdd: - Enabled: false -Style/FileName: - Enabled: false -Style/FlipFlop: - Enabled: false -Style/For: - Enabled: false -Style/FormatString: - Enabled: false -Style/FormatStringToken: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalVars: - Enabled: false -Style/GuardClause: - Enabled: false -Style/HashSyntax: - Enabled: false -Style/IdenticalConditionalBranches: - Enabled: false -Style/IfInsideElse: - Enabled: false Style/IfUnlessModifier: Enabled: false -Style/IfUnlessModifierOfIfUnless: - Enabled: false -Style/IfWithSemicolon: - Enabled: false -Style/InfiniteLoop: - Enabled: false -Style/InverseMethods: - Enabled: false -Style/Lambda: - Enabled: false -Style/LambdaCall: - Enabled: false -Style/LineEndConcatenation: - Enabled: false -Style/MethodCallWithoutArgsParentheses: - Enabled: false -Style/MethodDefParentheses: - Enabled: false -Style/MethodMissing: - Enabled: false -Style/MethodName: - Enabled: false -Style/MixinGrouping: - Enabled: false -Style/ModuleFunction: - Enabled: false -Style/MultilineBlockChain: - Enabled: false -Style/MultilineIfModifier: - Enabled: false -Style/MultilineIfThen: - Enabled: false -Style/MultilineMemoization: - Enabled: false -Style/MultilineTernaryOperator: - Enabled: false -Style/MultipleComparison: - Enabled: false -Style/MutableConstant: - Enabled: false -Style/NegatedIf: - Enabled: false -Style/NegatedWhile: - Enabled: false -Style/NestedModifier: - Enabled: false -Style/NestedParenthesizedCalls: - Enabled: false -Style/NestedTernaryOperator: - Enabled: false -Style/Next: - Enabled: false -Style/NilComparison: - Enabled: false -Style/NonNilCheck: - Enabled: false -Style/Not: - Enabled: false -Style/NumericLiteralPrefix: - Enabled: false -Style/NumericLiterals: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OneLineConditional: - Enabled: false -Style/OpMethod: - Enabled: false -Style/OptionalArguments: - Enabled: false -Style/ParallelAssignment: - Enabled: false -Style/ParenthesesAroundCondition: - Enabled: false -Style/PercentLiteralDelimiters: - Enabled: false -Style/PercentQLiterals: - Enabled: false -Style/PerlBackrefs: - Enabled: false -Style/PredicateName: - Enabled: false -Style/PreferredHashMethods: - Enabled: false -Style/Proc: - Enabled: false -Style/RaiseArgs: - Enabled: false -Style/RedundantBegin: - Enabled: false -Style/RedundantException: - Enabled: false -Style/RedundantFreeze: - Enabled: false -Style/RedundantParentheses: - Enabled: false -Style/RedundantReturn: - Enabled: false -Style/RedundantSelf: - Enabled: false -Style/RegexpLiteral: - Enabled: false -Style/RescueModifier: - Enabled: false -Style/SafeNavigation: - Enabled: false -Style/SelfAssignment: - Enabled: false -Style/Semicolon: - Enabled: false -Style/SignalException: - Enabled: false -Style/SingleLineMethods: - Enabled: false -Style/SpecialGlobalVars: - Enabled: false -Style/StabbyLambdaParentheses: - Enabled: false -Style/StringLiterals: - Enabled: false -Style/StringLiteralsInInterpolation: - Enabled: false -Style/StructInheritance: - Enabled: false -Style/SymbolArray: - Enabled: false -Style/SymbolLiteral: - Enabled: false Style/SymbolProc: Enabled: false -Style/TernaryParentheses: - Enabled: false -Style/TrailingCommaInArguments: - Enabled: false -Style/TrailingCommaInLiteral: - Enabled: false -Style/TrailingUnderscoreVariable: - Enabled: false -Style/TrivialAccessors: - Enabled: false -Style/UnlessElse: - Enabled: false -Style/UnneededCapitalW: - Enabled: false -Style/UnneededInterpolation: - Enabled: false -Style/UnneededPercentQ: - Enabled: false -Style/VariableInterpolation: - Enabled: false -Style/VariableName: - Enabled: false -Style/VariableNumber: - Enabled: false -Style/WhenThen: - Enabled: false -Style/WhileUntilDo: - Enabled: false -Style/WhileUntilModifier: - Enabled: false -Style/WordArray: - Enabled: false -Style/YodaCondition: - Enabled: false -Style/ZeroLengthPredicate: - Enabled: false diff --git a/.sync.yml b/.sync.yml index 5745fa0c..2e9b282c 100644 --- a/.sync.yml +++ b/.sync.yml @@ -4,6 +4,10 @@ exclude: - "*.erb" +.gitignore: + required: + - ---.project + Gemfile: required: ':system_tests': @@ -29,7 +33,6 @@ Gemfile: # For the moment don't do any rubocop checks. .rubocop.yml: include_todos: true - selected_profile: off appveyor.yml: matrix_extras: diff --git a/.travis.yml b/.travis.yml index 521510d1..2e541fb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ --- -dist: trusty language: ruby cache: bundler before_install: @@ -12,32 +11,34 @@ script: - 'bundle exec rake $CHECK' bundler_args: --without system_tests rvm: - - 2.5.1 -env: - global: - - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" + - 2.5.3 +stages: + - static + - spec + - acceptance + - + if: tag =~ ^v\d + name: deploy matrix: fast_finish: true include: - - env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" - - - env: CHECK=parallel_spec + env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" + stage: static - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec - rvm: 2.4.4 + rvm: 2.4.5 + stage: spec + - + env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + rvm: 2.5.3 + stage: spec + - + env: DEPLOY_TO_FORGE=yes + stage: deploy branches: only: - master - /^v\d/ notifications: email: false -deploy: - provider: puppetforge - user: puppet - password: - secure: "" - on: - tags: true - all_branches: true - condition: "$DEPLOY_TO_FORGE = yes" diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..61777827 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "jpogran.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/Gemfile b/Gemfile index 22aa3a52..fc49e3bb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,80 +1,80 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' - -def location_for(place_or_version, fake_version = nil) - git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} - file_url_regex = %r{\Afile:\/\/(?.*)} - - if place_or_version && (git_url = place_or_version.match(git_url_regex)) - [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact - elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) - ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] - else - [place_or_version, { require: false }] - end -end - -ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments -minor_version = ruby_version_segments[0..1].join('.') - -group :development do - gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') - gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') - gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') - gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - 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 "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "rototiller", '~> 1.0', require: false -end -group :system_tests do - gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "beaker-testmode_switcher", '~> 0.4', require: false - gem "master_manipulator", require: false - gem "puppet-blacksmith", '~> 3.4', require: false - gem "beaker-windows", '~> 0.6', require: false -end - -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - -gems = {} - -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables - -gems['facter'] = location_for(facter_version) if facter_version -gems['hiera'] = location_for(hiera_version) if hiera_version - -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] -end - -gems.each do |gem_name, gem_params| - gem gem_name, *gem_params -end - -# Evaluate Gemfile.local and ~/.gemfile if they exist -extra_gemfiles = [ - "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), -] - -extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end -end -# vim: syntax=ruby +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + if place_or_version && (git_url = place_or_version.match(git_url_regex)) + [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) + ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] + else + [place_or_version, { require: false }] + end +end + +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') + +group :development do + gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') + gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') + gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') + gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') + gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + 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 "puppet-module-posix-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "rototiller", '~> 1.0', require: false +end +group :system_tests do + gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "beaker-testmode_switcher", '~> 0.4', require: false + gem "master_manipulator", require: false + gem "puppet-blacksmith", '~> 3.4', require: false + gem "beaker-windows", '~> 0.6', require: false +end + +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +gems = {} + +gems['puppet'] = location_for(puppet_version) + +# If facter or hiera versions have been specified via the environment +# variables + +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version + +if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} + # If we're using a Puppet gem on Windows which handles its own win32-xxx gem + # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). + gems['win32-dir'] = ['<= 0.4.9', require: false] + gems['win32-eventlog'] = ['<= 0.6.5', require: false] + gems['win32-process'] = ['<= 0.7.5', require: false] + gems['win32-security'] = ['<= 0.2.5', require: false] + gems['win32-service'] = ['0.8.8', require: false] +end + +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params +end + +# Evaluate Gemfile.local and ~/.gemfile if they exist +extra_gemfiles = [ + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] + +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end +end +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 6ef96722..92276e7b 100644 --- a/Rakefile +++ b/Rakefile @@ -11,21 +11,6 @@ rescue LoadError #Do nothing, only installed with system_tests group end - -# If puppet does not support symlinks (e.g., puppet <= 3.5) we cannot use -# puppetlabs_spec_helper's `rake spec` task because it requires symlink -# support. Redefine `rake spec` to avoid calling `rake spec_prep` (requires -# symlinks to place fixtures) and restrict the pattern match only files under -# the 'unit' directory (tests in other dirs require fixtures). -if Puppet::Util::Platform.windows? and !Puppet::FileSystem.respond_to?(:symlink) - ENV["SPEC"] = "./spec/{unit,integration}/**/*_spec.rb" - Rake::Task[:spec].clear if Rake::Task.task_defined?(:spec) - task :spec do - Rake::Task[:spec_standalone].invoke - Rake::Task[:spec_clean].invoke - end -end - # These lint exclusions are in puppetlabs_spec_helper but needs a version above 0.10.3 # Line length test is 80 chars in puppet-lint 1.1.0 PuppetLint.configuration.send('disable_80chars') diff --git a/appveyor.yml b/appveyor.yml index 58d4e4b3..01416213 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,6 +3,7 @@ version: 1.1.x.{build} branches: only: - master + - release skip_commits: message: /^\(?doc\)?.*/ clone_depth: 10 diff --git a/lib/facter/choco_install_path.rb b/lib/facter/choco_install_path.rb index 3301fd0b..eabe0ead 100644 --- a/lib/facter/choco_install_path.rb +++ b/lib/facter/choco_install_path.rb @@ -2,7 +2,7 @@ require Pathname.new(__FILE__).dirname + '../' + 'puppet_x/chocolatey/chocolatey_install' Facter.add('choco_install_path') do - confine :osfamily => :windows + confine osfamily: :windows setcode do PuppetX::Chocolatey::ChocolateyInstall.install_path || 'C:\ProgramData\chocolatey' end diff --git a/lib/facter/choco_temp_dir.rb b/lib/facter/choco_temp_dir.rb index 4ef472b1..6214c6f1 100644 --- a/lib/facter/choco_temp_dir.rb +++ b/lib/facter/choco_temp_dir.rb @@ -2,7 +2,7 @@ require Pathname.new(__FILE__).dirname + '../' + 'puppet_x/chocolatey/chocolatey_install' Facter.add('choco_temp_dir') do - confine :osfamily => :windows + confine osfamily: :windows setcode do PuppetX::Chocolatey::ChocolateyInstall.temp_dir || ENV['TEMP'] end diff --git a/lib/facter/chocolateyversion.rb b/lib/facter/chocolateyversion.rb index afe3e5e5..0e224ec3 100644 --- a/lib/facter/chocolateyversion.rb +++ b/lib/facter/chocolateyversion.rb @@ -2,7 +2,7 @@ require Pathname.new(__FILE__).dirname + '../' + 'puppet_x/chocolatey/chocolatey_version' Facter.add('chocolateyversion') do - confine :osfamily => :windows + confine osfamily: :windows choco_ver = PuppetX::Chocolatey::ChocolateyVersion.version || '0' setcode do choco_ver.to_s diff --git a/lib/puppet/provider/chocolateyconfig/windows.rb b/lib/puppet/provider/chocolateyconfig/windows.rb index 57217d51..286cb019 100644 --- a/lib/puppet/provider/chocolateyconfig/windows.rb +++ b/lib/puppet/provider/chocolateyconfig/windows.rb @@ -3,24 +3,24 @@ require 'rexml/document' Puppet::Type.type(:chocolateyconfig).provide(:windows) do - confine :operatingsystem => :windows - defaultfor :operatingsystem => :windows + confine operatingsystem: :windows + defaultfor operatingsystem: :windows require Pathname.new(__FILE__).dirname + '../../../' + 'puppet_x/chocolatey/chocolatey_common' include PuppetX::Chocolatey::ChocolateyCommon - CONFIG_MINIMUM_SUPPORTED_CHOCO_VERSION = '0.9.10.0' + CONFIG_MINIMUM_SUPPORTED_CHOCO_VERSION = '0.9.10.0'.freeze - commands :chocolatey => PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command + commands chocolatey: PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command - def initialize(value={}) + def initialize(value = {}) super(value) @property_flush = {} end def properties if @property_hash.empty? - @property_hash = query || { :ensure => ( :absent )} + @property_hash = query || { ensure: :absent } @property_hash[:ensure] = :absent if @property_hash.empty? end @property_hash.dup @@ -28,23 +28,23 @@ def properties def query self.class.configs.each do |config| - return config.properties if @resource[:name][/\A\S*/].downcase == config.name.downcase + return config.properties if @resource[:name][%r{\A\S*}].casecmp(config.name.downcase).zero? end - return {} + {} end - def self.get_configs + def self.read_configs PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall choco_config = PuppetX::Chocolatey::ChocolateyCommon.choco_config_file - raise Puppet::ResourceError, "Config file not found for Chocolatey. Please make sure you have Chocolatey installed." if choco_config.nil? + raise Puppet::ResourceError, 'Config file not found for Chocolatey. Please make sure you have Chocolatey installed.' if choco_config.nil? raise Puppet::ResourceError, "An install was detected, but was unable to locate config file at #{choco_config}." unless PuppetX::Chocolatey::ChocolateyCommon.file_exists?(choco_config) Puppet.debug("Gathering sources from '#{choco_config}'.") config = REXML::Document.new File.read(choco_config) - config.elements.to_a( '//add' ) + config.elements.to_a('//add') end def self.get_config(element) @@ -63,7 +63,7 @@ def self.get_config(element) end def self.configs - @configs ||= get_configs.collect do |item| + @configs ||= read_configs.map do |item| config = get_config(item) new(config) end @@ -71,7 +71,7 @@ def self.configs def self.refresh_configs @configs = nil - self.configs + configs end def self.instances @@ -106,18 +106,21 @@ def validate # The hash is *not* empty when the validate block is called during a puppet resource run. # If the hash is empty, fail only if :ensure is true and :value is not specified or is an empty string. if @property_hash.empty? && resource[:ensure] == :present && resource[:value].to_s.empty? - raise ArgumentError, "Unless ensure => absent, value is required." + raise ArgumentError, 'Unless ensure => absent, value is required.' end choco_version = Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) - if PuppetX::Chocolatey::ChocolateyCommon.file_exists?(PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command) && choco_version < Gem::Version.new(CONFIG_MINIMUM_SUPPORTED_CHOCO_VERSION) - raise Puppet::ResourceError, "Chocolatey version must be '#{CONFIG_MINIMUM_SUPPORTED_CHOCO_VERSION}' to manage configuration values. Detected '#{choco_version}' as your version. Please upgrade Chocolatey." + validate_check = PuppetX::Chocolatey::ChocolateyCommon.file_exists?(PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command) && + choco_version < Gem::Version.new(CONFIG_MINIMUM_SUPPORTED_CHOCO_VERSION) + if validate_check # rubocop:disable Style/GuardClause + raise Puppet::ResourceError, "Chocolatey version must be '#{CONFIG_MINIMUM_SUPPORTED_CHOCO_VERSION}' to manage configuration values. Detected '#{choco_version}' as your version. "\ + 'Please upgrade Chocolatey.' end end mk_resource_methods def flush - choco_version = Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) + # choco_version = Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) args = [] args << 'config' @@ -141,7 +144,7 @@ def flush begin Puppet::Util::Execution.execute([command(:chocolatey), *args]) rescue Puppet::ExecutionFailure => e - raise Puppet::Error, "An error occurred running choco. Unable to set Chocolateyconfig[#{self.name}]: #{e}" + raise Puppet::Error, "An error occurred running choco. Unable to set Chocolateyconfig[#{name}]: #{e}" end @property_hash.clear diff --git a/lib/puppet/provider/chocolateyfeature/windows.rb b/lib/puppet/provider/chocolateyfeature/windows.rb index 89b16c8a..1f57ad55 100644 --- a/lib/puppet/provider/chocolateyfeature/windows.rb +++ b/lib/puppet/provider/chocolateyfeature/windows.rb @@ -3,17 +3,17 @@ require 'rexml/document' Puppet::Type.type(:chocolateyfeature).provide(:windows) do - confine :operatingsystem => :windows - defaultfor :operatingsystem => :windows + confine operatingsystem: :windows + defaultfor operatingsystem: :windows require Pathname.new(__FILE__).dirname + '../../../' + 'puppet_x/chocolatey/chocolatey_common' include PuppetX::Chocolatey::ChocolateyCommon - FEATURE_MINIMUM_SUPPORTED_CHOCO_VERSION = '0.9.9.0' + FEATURE_MINIMUM_SUPPORTED_CHOCO_VERSION = '0.9.9.0'.freeze - commands :chocolatey => PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command + commands chocolatey: PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command - def initialize(value={}) + def initialize(value = {}) super(value) @property_flush = {} end @@ -27,23 +27,23 @@ def properties def query self.class.choco_features.each do |feature| - return feature.properties if @resource[:name][/\A\S*/].downcase == feature.name.downcase + return feature.properties if @resource[:name][%r{\A\S*}].casecmp(feature.name.downcase).zero? end - return {} + {} end - def self.get_choco_features + def self.read_choco_features PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall choco_config = PuppetX::Chocolatey::ChocolateyCommon.choco_config_file - raise Puppet::ResourceError, "Config file not found for Chocolatey. Please make sure you have Chocolatey installed." if choco_config.nil? + raise Puppet::ResourceError, 'Config file not found for Chocolatey. Please make sure you have Chocolatey installed.' if choco_config.nil? raise Puppet::ResourceError, "An install was detected, but was unable to locate config file at #{choco_config}." unless PuppetX::Chocolatey::ChocolateyCommon.file_exists?(choco_config) Puppet.debug("Gathering features from '#{choco_config}'.") config = REXML::Document.new File.read(choco_config) - config.elements.to_a( '//feature' ) + config.elements.to_a('//feature') end def self.get_choco_feature(element) @@ -54,7 +54,7 @@ def self.get_choco_feature(element) feature[:description] = element.attributes['description'].downcase if element.attributes['description'] enabled = false - enabled = element.attributes['enabled'].downcase == 'true' if element.attributes['enabled'] + enabled = element.attributes['enabled'].casecmp('true').zero? if element.attributes['enabled'] feature[:ensure] = :disabled feature[:ensure] = :enabled if enabled @@ -65,7 +65,7 @@ def self.get_choco_feature(element) end def self.choco_features - get_choco_features.collect do |item| + read_choco_features.map do |item| feature = get_choco_feature(item) new(feature) end @@ -97,8 +97,12 @@ def disable def validate choco_version = Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) - if PuppetX::Chocolatey::ChocolateyCommon.file_exists?(PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command) && choco_version < Gem::Version.new(FEATURE_MINIMUM_SUPPORTED_CHOCO_VERSION) - raise Puppet::ResourceError, "Chocolatey version must be '#{FEATURE_MINIMUM_SUPPORTED_CHOCO_VERSION}' to manage configuration values with Puppet. Detected '#{choco_version}' as your version. Please upgrade Chocolatey to use this resource." + validate_check = PuppetX::Chocolatey::ChocolateyCommon.file_exists?(PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command) && + choco_version < Gem::Version.new(FEATURE_MINIMUM_SUPPORTED_CHOCO_VERSION) + + if validate_check # rubocop:disable Style/GuardClause + raise Puppet::ResourceError, "Chocolatey version must be '#{FEATURE_MINIMUM_SUPPORTED_CHOCO_VERSION}' to manage configuration values with Puppet. "\ + "Detected '#{choco_version}' as your version. Please upgrade Chocolatey to use this resource." end end @@ -122,5 +126,4 @@ def flush self.class.choco_features @property_hash = query end - end diff --git a/lib/puppet/provider/chocolateysource/windows.rb b/lib/puppet/provider/chocolateysource/windows.rb index 8b904b6f..4ea95fa3 100644 --- a/lib/puppet/provider/chocolateysource/windows.rb +++ b/lib/puppet/provider/chocolateysource/windows.rb @@ -3,28 +3,28 @@ require 'rexml/document' Puppet::Type.type(:chocolateysource).provide(:windows) do - confine :operatingsystem => :windows - defaultfor :operatingsystem => :windows + confine operatingsystem: :windows + defaultfor operatingsystem: :windows require Pathname.new(__FILE__).dirname + '../../../' + 'puppet_x/chocolatey/chocolatey_common' include PuppetX::Chocolatey::ChocolateyCommon - MINIMUM_SUPPORTED_CHOCO_VERSION = '0.9.9.0' - MINIMUM_SUPPORTED_CHOCO_VERSION_PRIORITY = '0.9.9.9' - MINIMUM_SUPPORTED_CHOCO_VERSION_BYPASS_PROXY = '0.10.4' - MINIMUM_SUPPORTED_CHOCO_VERSION_ALLOW_SELF_SERVICE = '0.10.4' - MINIMUM_SUPPORTED_CHOCO_VERSION_ADMIN_ONLY = '0.10.8' + MINIMUM_SUPPORTED_CHOCO_VERSION = '0.9.9.0'.freeze + MINIMUM_SUPPORTED_CHOCO_VERSION_PRIORITY = '0.9.9.9'.freeze + MINIMUM_SUPPORTED_CHOCO_VERSION_BYPASS_PROXY = '0.10.4'.freeze + MINIMUM_SUPPORTED_CHOCO_VERSION_ALLOW_SELF_SERVICE = '0.10.4'.freeze + MINIMUM_SUPPORTED_CHOCO_VERSION_ADMIN_ONLY = '0.10.8'.freeze - commands :chocolatey => PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command + commands chocolatey: PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command - def initialize(value={}) + def initialize(value = {}) super(value) @property_flush = {} end def properties if @property_hash.empty? - @property_hash = query || { :ensure => ( :absent )} + @property_hash = query || { ensure: :absent } @property_hash[:ensure] = :absent if @property_hash.empty? end @property_hash.dup @@ -32,23 +32,23 @@ def properties def query self.class.sources.each do |source| - return source.properties if @resource[:name][/\A\S*/].downcase == source.name.downcase + return source.properties if @resource[:name][%r{\A\S*}].casecmp(source.name.downcase).zero? end - return {} + {} end - def self.get_sources + def self.read_sources PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall choco_config = PuppetX::Chocolatey::ChocolateyCommon.choco_config_file - raise Puppet::ResourceError, "Config file not found for Chocolatey. Please make sure you have Chocolatey installed." if choco_config.nil? + raise Puppet::ResourceError, 'Config file not found for Chocolatey. Please make sure you have Chocolatey installed.' if choco_config.nil? raise Puppet::ResourceError, "An install was detected, but was unable to locate config file at #{choco_config}." unless PuppetX::Chocolatey::ChocolateyCommon.file_exists?(choco_config) Puppet.debug("Gathering sources from '#{choco_config}'.") config = REXML::Document.new File.read(choco_config) - config.elements.to_a( '//source' ) + config.elements.to_a('//source') end def self.get_source(element) @@ -59,7 +59,7 @@ def self.get_source(element) source[:location] = element.attributes['value'].downcase if element.attributes['value'] disabled = false - disabled = element.attributes['disabled'].downcase == 'true' if element.attributes['disabled'] + disabled = element.attributes['disabled'].casecmp('true').zero? if element.attributes['disabled'] source[:ensure] = :present source[:ensure] = :disabled if disabled @@ -84,7 +84,7 @@ def self.get_source(element) end def self.sources - @sources ||= get_sources.collect do |item| + @sources ||= read_sources.map do |item| source = get_source(item) new(source) end @@ -92,7 +92,7 @@ def self.sources def self.refresh_sources @sources = nil - self.sources + sources end def self.instances @@ -126,7 +126,8 @@ def destroy def validate choco_version = Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) if PuppetX::Chocolatey::ChocolateyCommon.file_exists?(PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command) && choco_version < Gem::Version.new(MINIMUM_SUPPORTED_CHOCO_VERSION) - raise Puppet::ResourceError, "Chocolatey version must be '#{MINIMUM_SUPPORTED_CHOCO_VERSION}' to manage configuration values with Puppet. Detected '#{choco_version}' as your version. Please upgrade Chocolatey to use this resource." + raise Puppet::ResourceError, "Chocolatey version must be '#{MINIMUM_SUPPORTED_CHOCO_VERSION}' to manage configuration values with Puppet. "\ + "Detected '#{choco_version}' as your version. Please upgrade Chocolatey to use this resource." end if choco_version < Gem::Version.new(MINIMUM_SUPPORTED_CHOCO_VERSION_PRIORITY) && resource[:priority] && resource[:priority] != 0 @@ -142,7 +143,8 @@ def validate end if choco_version < Gem::Version.new(MINIMUM_SUPPORTED_CHOCO_VERSION_ADMIN_ONLY) && resource[:admin_only] && resource[:admin_only] != :false - Puppet.warning("Chocolatey is unable to specify administrator only visibility for sources when version is less than #{MINIMUM_SUPPORTED_CHOCO_VERSION_ADMIN_ONLY}. The value you set will be ignored.") + Puppet.warning("Chocolatey is unable to specify administrator only visibility for sources when version is less than #{MINIMUM_SUPPORTED_CHOCO_VERSION_ADMIN_ONLY}. "\ + 'The value you set will be ignored.') end # location is always filled in with puppet resource, but @@ -156,12 +158,13 @@ def validate # resource[:location] is nil when running puppet resource # if you remove `location => value` location_check = resource[:location] if location_check == :absent - if (resource[:ensure] == :present && (location_check.nil? || location_check.strip == '')) - raise ArgumentError, "A non-empty location must be specified when ensure => present." + if resource[:ensure] == :present && (location_check.nil? || location_check.strip == '') + raise ArgumentError, 'A non-empty location must be specified when ensure => present.' end - if resource[:password] && resource[:password] != '' - Puppet.debug("The password is not ensurable, so Puppet is unable to change the value using chocolateysource resource. As a workaround, a password change can be in the form of an exec. Reference Chocolateysource[#{resource[:name]}]") + if resource[:password] && resource[:password] != '' # rubocop:disable Style/GuardClause + Puppet.debug('The password is not ensurable, so Puppet is unable to change the value using chocolateysource resource. '\ + "As a workaround, a password change can be in the form of an exec. Reference Chocolateysource[#{resource[:name]}]") end end @@ -187,7 +190,7 @@ def flush if command == 'add' args << '--source' << resource[:location] - if resource[:user] && resource[:user] != '' + if resource[:user] && resource[:user] != '' args << '--user' << resource[:user] args << '--password' << resource[:password] end @@ -213,14 +216,14 @@ def flush begin Puppet::Util::Execution.execute([command(:chocolatey), *args]) rescue Puppet::ExecutionFailure - raise Puppet::Error, "An error occurred running choco. Unable to set Chocolatey source configuration for #{self.inspect}" + raise Puppet::Error, "An error occurred running choco. Unable to set Chocolatey source configuration for #{inspect}" end if property_ensure == :present begin Puppet::Util::Execution.execute([command(:chocolatey), 'source', 'enable', '--name', resource[:name]]) rescue Puppet::ExecutionFailure - raise Puppet::Error, "An error occurred running choco. Unable to set Chocolatey source configuration for #{self.inspect}" + raise Puppet::Error, "An error occurred running choco. Unable to set Chocolatey source configuration for #{inspect}" end end diff --git a/lib/puppet/provider/package/chocolatey.rb b/lib/puppet/provider/package/chocolatey.rb index cc2b73fc..294c7bd1 100644 --- a/lib/puppet/provider/package/chocolatey.rb +++ b/lib/puppet/provider/package/chocolatey.rb @@ -3,8 +3,7 @@ require 'rexml/document' require Pathname.new(__FILE__).dirname + '../../../' + 'puppet_x/chocolatey/chocolatey_install' -Puppet::Type.type(:package).provide(:chocolatey, :parent => Puppet::Provider::Package) do - +Puppet::Type.type(:package).provide(:chocolatey, parent: Puppet::Provider::Package) do desc "Manages packages using Chocolatey (Windows package manager). The syntax for Chocolatey using the puppet provider is a much @@ -21,7 +20,7 @@ See the ReadMe for more information." - confine :operatingsystem => :windows + confine operatingsystem: :windows has_feature :installable has_feature :uninstallable has_feature :upgradeable @@ -34,35 +33,35 @@ require Pathname.new(__FILE__).dirname + '../../../' + 'puppet_x/chocolatey/chocolatey_common' include PuppetX::Chocolatey::ChocolateyCommon - commands :chocolatey => PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command + commands chocolatey: PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command - def initialize(value={}) + def initialize(value = {}) super(value) end - def print() + def print notice("The value is: '${name}'") end - def self.is_compiled_choco? + def self.compiled_choco? Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::FIRST_COMPILED_CHOCO_VERSION) end - def is_compiled_choco? - self.class.is_compiled_choco? + def compiled_choco? + self.class.compiled_choco? end - def get_choco_features + def read_choco_features PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall choco_config = PuppetX::Chocolatey::ChocolateyCommon.choco_config_file - raise Puppet::ResourceError, "Config file not found for Chocolatey. Please make sure you have Chocolatey installed." if choco_config.nil? + raise Puppet::ResourceError, 'Config file not found for Chocolatey. Please make sure you have Chocolatey installed.' if choco_config.nil? raise Puppet::ResourceError, "An install was detected, but was unable to locate config file at #{choco_config}." unless PuppetX::Chocolatey::ChocolateyCommon.file_exists?(choco_config) Puppet.debug("Gathering sources from '#{choco_config}'.") config = REXML::Document.new File.read(choco_config) - config.elements.to_a( '//feature' ) + config.elements.to_a('//feature') end def get_choco_feature(element) @@ -80,25 +79,25 @@ def get_choco_feature(element) end def choco_features - @choco_features ||= get_choco_features.collect do |item| + @choco_features ||= read_choco_features.map do |item| get_choco_feature(item) end end - def is_use_package_exit_codes_feature_enabled? - use_package_exit_codes_feature = choco_features.find { |choco_feature| choco_feature[:name] == "usepackageexitcodes" } + def use_package_exit_codes_feature_enabled? + use_package_exit_codes_feature = choco_features.find { |choco_feature| choco_feature[:name] == 'usepackageexitcodes' } return false if use_package_exit_codes_feature.nil? # Verifies that the feature has been explicitly set - true is the default value, # but implementing this without an explicit check would break existing users. # This is unlikely to work because Puppet itself will not know how to handle these # alternate exit codes. - return true if use_package_exit_codes_feature[:enabled].downcase == 'true' and use_package_exit_codes_feature[:set_explicitly].downcase == 'true' + return true if use_package_exit_codes_feature[:enabled].casecmp('true').zero? && use_package_exit_codes_feature[:set_explicitly].casecmp('true').zero? false end def install PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall - choco_exe = is_compiled_choco? + choco_exe = compiled_choco? # always unhold on install unhold if choco_exe @@ -112,17 +111,17 @@ def install should = @resource.should(:ensure) case should when true, false, Symbol - args << @resource[:name][/\A\S*/] + args << @resource[:name][%r{\A\S*}] else args.clear - if choco_exe - args << 'upgrade' - else - args << 'update' - end + args << if choco_exe + 'upgrade' + else + 'update' + end # Add the package version - args << @resource[:name][/\A\S*/] << '--version' << @resource[:ensure] + args << @resource[:name][%r{\A\S*}] << '--version' << @resource[:ensure] end if choco_exe @@ -135,31 +134,29 @@ def install args << @resource[:install_options] - if Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES) and - not is_use_package_exit_codes_feature_enabled? + if Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES) && + !use_package_exit_codes_feature_enabled? args << '--ignore-package-exit-codes' end @resource[:package_settings] ||= {} if @resource[:package_settings]['verbose'] - Puppet.info "Calling chocolatey with arguments: " + args.join(' ') + Puppet.info 'Calling chocolatey with arguments: ' + args.join(' ') elsif Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS) args << '--no-progress' end output = chocolatey(*args) - if @resource[:package_settings]['log_output'] - Puppet.info "Output from chocolatey: " + output - end + Puppet.info 'Output from chocolatey: ' + output if @resource[:package_settings]['log_output'] end def uninstall PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall - choco_exe = is_compiled_choco? + choco_exe = compiled_choco? # always unhold on uninstall unhold if choco_exe - args = 'uninstall', @resource[:name][/\A\S*/] + args = 'uninstall', @resource[:name][%r{\A\S*}] if choco_exe args << '-fy' @@ -174,32 +171,30 @@ def uninstall args << @resource[:uninstall_options] - if Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES) and - not is_use_package_exit_codes_feature_enabled? + if Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES) && + !use_package_exit_codes_feature_enabled? args << '--ignore-package-exit-codes' end @resource[:package_settings] ||= {} - if @resource[:package_settings]['verbose'] - Puppet.info "Calling chocolatey with arguments: " + args.join(' ') - end + Puppet.info 'Calling chocolatey with arguments: ' + args.join(' ') if @resource[:package_settings]['verbose'] output = chocolatey(*args) - if @resource[:package_settings]['log_output'] - Puppet.info "Output from chocolatey: " + output - end + Puppet.info 'Output from chocolatey: ' + output if @resource[:package_settings]['log_output'] end def update PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall - choco_exe = is_compiled_choco? + choco_exe = compiled_choco? # always unhold on upgrade unhold if choco_exe + args = [] + if choco_exe - args = 'upgrade', @resource[:name][/\A\S*/], '-y' + args << 'upgrade' << @resource[:name][%r{\A\S*}] << '-y' else - args = 'update', @resource[:name][/\A\S*/] + args << 'update' << @resource[:name][%r{\A\S*}] end if @resource[:source] @@ -208,24 +203,24 @@ def update args << @resource[:install_options] - if Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES) and - not is_use_package_exit_codes_feature_enabled? + if Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES) && + !use_package_exit_codes_feature_enabled? args << '--ignore-package-exit-codes' end - if self.query + if query @resource[:package_settings] ||= {} if @resource[:package_settings]['verbose'] - Puppet.info "Calling chocolatey with arguments: " + args.join(' ') + Puppet.info 'Calling chocolatey with arguments: ' + args.join(' ') elsif Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS) args << '--no-progress' end output = chocolatey(*args) if @resource[:package_settings]['log_output'] - Puppet.info "Output from chocolatey: " + output + Puppet.info 'Output from chocolatey: ' + output end else - self.install + install end end @@ -238,31 +233,31 @@ def update # Query provides the information for the single package identified by @Resource[:name]. def query self.class.instances.each do |package| - return package.properties if @resource[:name][/\A\S*/].downcase == package.name.downcase + return package.properties if @resource[:name][%r{\A\S*}].casecmp(package.name.downcase).zero? end - return nil + nil end def self.listcmd args = [] args << 'list' args << '-lo' - if is_compiled_choco? + if compiled_choco? args << '-r' end - [output = command(:chocolatey), *args] + [command(:chocolatey), *args] end def self.instances packages = [] PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall - choco_exe = is_compiled_choco? + choco_exe = compiled_choco? begin pins = [] pin_output = nil unless choco_exe - #don't add -r yet, as there is an issue in 0.9.9.9/0.9.9.10 that returns full list plus pins + # don't add -r yet, as there is an issue in 0.9.9.9/0.9.9.10 that returns full list plus pins pin_output = Puppet::Util::Execution.execute([command(:chocolatey), 'pin', 'list']) if choco_exe unless pin_output.nil? pin_output.split("\n").each { |pin| pins << pin.split('|')[0] } @@ -271,15 +266,15 @@ def self.instances execpipe(listcmd) do |process| process.each_line do |line| line.chomp! - if line.empty? or line.match(/Reading environment variables.*/); next; end - raise Puppet::Error, "At least one source must be enabled." if line.match(/Unable to search for packages.*/) - if choco_exe - values = line.split('|') - else - values = line.split(' ') - end + next if line.empty? || line.match(%r{Reading environment variables.*}) + raise Puppet::Error, 'At least one source must be enabled.' if line =~ %r{Unable to search for packages.*} + values = if choco_exe + line.split('|') + else + line.split(' ') + end values[1] = :held if pins.include? values[0] - packages << new({ :name => values[0].downcase, :ensure => values[1], :provider => self.name }) + packages << new(name: values[0].downcase, ensure: values[1], provider: name) end end rescue Puppet::ExecutionFailure @@ -290,12 +285,13 @@ def self.instances end def latestcmd - choco_exe = is_compiled_choco? - if choco_exe - args = 'upgrade', '--noop', @resource[:name][/\A\S*/], '-r' - else - args = 'version', @resource[:name][/\A\S*/] - end + choco_exe = compiled_choco? + args = [] + args = if choco_exe + args << 'upgrade' << '--noop' << @resource[:name][%r{\A\S*}] << '-r' + else + args << 'version' << @resource[:name][%r{\A\S*}] + end if @resource[:source] args << '--source' << @resource[:source] @@ -304,10 +300,9 @@ def latestcmd unless choco_exe args << '| findstr /R "latest" | findstr /V "latestCompare"' end - @resource[:package_settings] ||= {} if @resource[:package_settings]['verbose'] - Puppet.info "Calling chocolatey with arguments: " + args.join(' ') + Puppet.info 'Calling chocolatey with arguments: ' + args.join(' ') end [command(:chocolatey), *args] end @@ -319,13 +314,13 @@ def latest execpipe(latestcmd) do |process| process.each_line do |line| line.chomp! - if line.empty?; next; end - if is_compiled_choco? + next if line.empty? + if compiled_choco? values = line.split('|') package_ver = values[2] else # Example: ( latest : 2013.08.19.155043 ) - values = line.split(':').collect(&:strip).delete_if(&:empty?) + values = line.split(':').map(&:strip).delete_if(&:empty?) package_ver = values[1] end end @@ -338,31 +333,30 @@ def latest end def hold - raise ArgumentError, 'Only choco v0.9.9+ can use ensure => held' unless is_compiled_choco? + raise ArgumentError, 'Only choco v0.9.9+ can use ensure => held' unless compiled_choco? install - args = 'pin', 'add', '-n', @resource[:name][/\A\S*/] + args = 'pin', 'add', '-n', @resource[:name][%r{\A\S*}] chocolatey(*args) end def unhold - return unless is_compiled_choco? + return unless compiled_choco? - Puppet::Util::Execution.execute([command(:chocolatey), 'pin','remove', '-n', @resource[:name][/\A\S*/]], :failonfail => false) + Puppet::Util::Execution.execute([command(:chocolatey), 'pin', 'remove', '-n', @resource[:name][%r{\A\S*}]], failonfail: false) end def package_settings # Not actually used end + def package_settings= # Not actually used end - def package_settings_insync?(should, is) - return true - end - - + def package_settings_insync?(_should, _is) + true + end end diff --git a/lib/puppet/type/chocolateyconfig.rb b/lib/puppet/type/chocolateyconfig.rb index 35fa4f8f..fc97785d 100644 --- a/lib/puppet/type/chocolateyconfig.rb +++ b/lib/puppet/type/chocolateyconfig.rb @@ -2,8 +2,7 @@ require 'pathname' Puppet::Type.newtype(:chocolateyconfig) do - - @doc = <<-'EOT' + @doc = <<-EOT Allows managing config settings for Chocolatey. Configuration values provide settings for users to configure aspects of Chocolatey and the way it @@ -20,7 +19,6 @@ def retrieve provider.properties[:ensure] end - end newparam(:name) do @@ -30,8 +28,8 @@ def retrieve will be encrypted in the configuration file." validate do |value| - if value.nil? or value.empty? - raise ArgumentError, "A non-empty name must be specified." + if value.nil? || value.empty? + raise ArgumentError, 'A non-empty name must be specified.' end end @@ -42,7 +40,7 @@ def retrieve end def insync?(is) - is.downcase == should.downcase + is.casecmp(should.downcase).zero? end end @@ -53,18 +51,18 @@ def insync?(is) configuration file." validate do |value| - if value.nil? or value.empty? - raise ArgumentError, "A non-empty value must be specified. To unset value, use ensure => absent" + if value.nil? || value.empty? + raise ArgumentError, 'A non-empty value must be specified. To unset value, use ensure => absent' end end def insync?(is) - if (resource[:name] =~ /password/i) + if resource[:name] =~ %r{password}i # If name contains password, it is # always in sync if there is a value - return (is.nil? || is.empty?) == (should.nil? || should.empty?) + (is.nil? || is.empty?) == (should.nil? || should.empty?) else - return is.downcase == should.downcase + is.casecmp(should.downcase).zero? end end end diff --git a/lib/puppet/type/chocolateyfeature.rb b/lib/puppet/type/chocolateyfeature.rb index da5ebcc7..445e0687 100644 --- a/lib/puppet/type/chocolateyfeature.rb +++ b/lib/puppet/type/chocolateyfeature.rb @@ -2,7 +2,6 @@ require 'pathname' Puppet::Type.newtype(:chocolateyfeature) do - @doc = <<-'EOT' Allows managing features for Chocolatey. Features are configuration that act as feature flippers to turn on or @@ -13,11 +12,11 @@ EOT newparam(:name) do - desc "The name of the feature. Used for uniqueness." + desc 'The name of the feature. Used for uniqueness.' validate do |value| - if value.nil? or value.empty? - raise ArgumentError, "A non-empty name must be specified." + if value.nil? || value.empty? + raise ArgumentError, 'A non-empty name must be specified.' end end @@ -28,7 +27,7 @@ end def insync?(is) - is.downcase == should.downcase + is.casecmp(should.downcase).zero? end end @@ -43,7 +42,7 @@ def retrieve validate do if self[:ensure].nil? && provider.properties[:ensure].nil? - raise ArgumentError, "Invalid value for ensure. Valid values are enabled or disabled." + raise ArgumentError, 'Invalid value for ensure. Valid values are enabled or disabled.' end if provider.respond_to?(:validate) diff --git a/lib/puppet/type/chocolateysource.rb b/lib/puppet/type/chocolateysource.rb index 5a5cd0ac..fa46e9f7 100644 --- a/lib/puppet/type/chocolateysource.rb +++ b/lib/puppet/type/chocolateysource.rb @@ -2,7 +2,6 @@ require 'pathname' Puppet::Type.newtype(:chocolateysource) do - @doc = <<-'EOT' Allows managing sources for Chocolatey. A source can be a folder, a CIFS share, a NuGet Http OData feed, or a full @@ -20,15 +19,14 @@ def retrieve provider.properties[:ensure] end - end newparam(:name) do - desc "The name of the source. Used for uniqueness." + desc 'The name of the source. Used for uniqueness.' validate do |value| - if value.nil? or value.empty? - raise ArgumentError, "A non-empty name must be specified." + if value.nil? || value.empty? + raise ArgumentError, 'A non-empty name must be specified.' end end @@ -39,7 +37,7 @@ def retrieve end def insync?(is) - is.downcase == should.downcase + is.casecmp(should.downcase).zero? end end @@ -50,13 +48,13 @@ def insync?(is) `ensure`)." validate do |value| - if value.nil? or value.empty? - raise ArgumentError, "A non-empty location must be specified." + if value.nil? || value.empty? + raise ArgumentError, 'A non-empty location must be specified.' end end def insync?(is) - is.downcase == should.downcase + is.casecmp(should.downcase).zero? end end @@ -68,7 +66,7 @@ def insync?(is) the property at all." def insync?(is) - is.downcase == should.downcase + is.casecmp(should.downcase).zero? end defaultto '' @@ -99,21 +97,21 @@ def insync?(is) validate do |value| if value.nil? - raise ArgumentError, "A non-empty priority must be specified." + raise ArgumentError, 'A non-empty priority must be specified.' end - raise ArgumentError, "An integer is necessary for priority. Specify 0 or remove for no priority." unless resource.is_numeric?(value) + raise ArgumentError, 'An integer is necessary for priority. Specify 0 or remove for no priority.' unless resource.numeric?(value) end defaultto(0) end - newproperty(:bypass_proxy, :boolean => true) do + newproperty(:bypass_proxy, boolean: true) do desc "Option to specify whether this source should explicitly bypass any explicitly or system configured proxies. Requires at least Chocolatey v0.10.4. Defaults to false." - + newvalues(:true, :false) defaultto(:false) @@ -122,7 +120,7 @@ def insync?(is) end end - newproperty(:admin_only, :boolean => true) do + newproperty(:admin_only, boolean: true) do desc "Option to specify whether this source should visible to Windows user accounts in the Administrators group only. @@ -130,7 +128,7 @@ def insync?(is) Requires Chocolatey for Business (C4B) v1.12.2+ and at least Chocolatey v0.10.8 for the setting to be respected. Defaults to false." - + newvalues(:true, :false) defaultto(:false) @@ -139,7 +137,7 @@ def insync?(is) end end - newproperty(:allow_self_service, :boolean => true) do + newproperty(:allow_self_service, boolean: true) do desc "Option to specify whether this source should be allowed to be used with Chocolatey Self Service. @@ -149,7 +147,7 @@ def insync?(is) Also requires at least Chocolatey v0.10.4 for the setting to be enabled. Defaults to false." - + newvalues(:true, :false) defaultto(:false) @@ -159,8 +157,9 @@ def insync?(is) end validate do - if (!self[:user].nil? && self[:user].strip != '' && (self[:password].nil? || self[:password] == '')) || ((self[:user].nil? || self[:user].strip == '') && !self[:password].nil? && self[:password] != '') - raise ArgumentError, "If specifying user/password, you must specify both values." + if (!self[:user].nil? && self[:user].strip != '' && (self[:password].nil? || self[:password] == '')) || + ((self[:user].nil? || self[:user].strip == '') && !self[:password].nil? && self[:password] != '') + raise ArgumentError, 'If specifying user/password, you must specify both values.' end if provider.respond_to?(:validate) @@ -174,19 +173,22 @@ def insync?(is) def munge_boolean(value) case value - when true, "true", :true - :true - when false, "false", :false - :false - else - fail("munge_boolean only takes booleans") + when true, 'true', :true + :true + when false, 'false', :false + :false + else + raise('munge_boolean only takes booleans') end end - def is_numeric?(value) + def numeric?(value) # this is what stdlib does. Not sure if we want to emulate or not. - #numeric = %r{^-?(?:(?:[1-9]\d*)|0)$} - #if value.is_a? Integer or (value.is_a? String and value.match numeric) - Float(value) != nil rescue false + # numeric = %r{^-?(?:(?:[1-9]\d*)|0)$} + # if value.is_a? Integer or (value.is_a? String and value.match numeric) + + !Float(value).nil? + rescue + false end end diff --git a/lib/puppet_x/chocolatey/chocolatey_common.rb b/lib/puppet_x/chocolatey/chocolatey_common.rb index 048aec17..a6706c0d 100644 --- a/lib/puppet_x/chocolatey/chocolatey_common.rb +++ b/lib/puppet_x/chocolatey/chocolatey_common.rb @@ -2,90 +2,83 @@ require Pathname.new(__FILE__).dirname + 'chocolatey_version' require Pathname.new(__FILE__).dirname + 'chocolatey_install' -module PuppetX - module Chocolatey - module ChocolateyCommon - - ## determines if C# version of choco - FIRST_COMPILED_CHOCO_VERSION = '0.9.9.0' unless defined? FIRST_COMPILED_CHOCO_VERSION - MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES = '0.9.10.0' unless defined? MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES - MINIMUM_SUPPORTED_CHOCO_UNINSTALL_SOURCE = '0.9.10.0' unless defined? MINIMUM_SUPPORTED_CHOCO_UNINSTALL_SOURCE - MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS = '0.10.4.0' unless defined? MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS - - def file_exists?(path) - File.exist?(path) - end - module_function :file_exists? - - def chocolatey_command - if Puppet::Util::Platform.windows? - # When attempting to find the choco command executable, the following - # paths are checked: - # - Start with the install_path. If choco is found with environment - # variables through the registry or a check on the - # ChocolateyInstall env var (first install of Choco may only have - # this), then use that path. - # - Next look to the most commonly used install location (ProgramData) - # - Fall back to the older install location for older installations - # - If all else fails, attempt to find Chocolatey in the default place - # it installs - chocoInstallPath = PuppetX::Chocolatey::ChocolateyInstall.install_path - - chocopath = (chocoInstallPath if (chocoInstallPath && file_exists?("#{chocoInstallPath}\\choco.exe"))) || - ('C:\ProgramData\chocolatey' if file_exists?('C:\ProgramData\chocolatey\choco.exe')) || - ('C:\Chocolatey' if file_exists?('C:\Chocolatey\choco.exe')) || - "#{ENV['ALLUSERSPROFILE']}\\chocolatey" - - chocopath += '\choco.exe' - else - chocopath = 'choco.exe' - end - - chocopath - end - module_function :chocolatey_command - - def set_env_chocolateyinstall - ENV['ChocolateyInstall'] = PuppetX::Chocolatey::ChocolateyInstall.install_path - end - module_function :set_env_chocolateyinstall - - def choco_version - @chocoversion ||= self.strip_beta_from_version(PuppetX::Chocolatey::ChocolateyVersion.version) - end - module_function :choco_version - - def self.strip_beta_from_version(value) - return nil if value.nil? - - value.split(/-/)[0] - end - - def choco_config_file - chocoInstallPath = PuppetX::Chocolatey::ChocolateyInstall.install_path - choco_config = "#{chocoInstallPath}\\config\\chocolatey.config" - - # choco may be installed, but a config file doesn't exist until the - # first run of choco - trigger that by checking the version - choco_run_ensure_config = choco_version - - return choco_config if file_exists?(choco_config) - - old_choco_config = "#{chocoInstallPath}\\chocolateyinstall\\chocolatey.config" - - return old_choco_config if file_exists?(old_choco_config) - - return nil - end - module_function :choco_config_file - - # clears the cached values - def clear_cached_values - @chocoversion = nil - @compiled_choco = nil - end - module_function :clear_cached_values - +# Module used for general Chocolatey commands and constants +module PuppetX::Chocolatey::ChocolateyCommon + ## determines if C# version of choco + FIRST_COMPILED_CHOCO_VERSION = '0.9.9.0'.freeze unless defined? FIRST_COMPILED_CHOCO_VERSION + MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES = '0.9.10.0'.freeze unless defined? MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES + MINIMUM_SUPPORTED_CHOCO_UNINSTALL_SOURCE = '0.9.10.0'.freeze unless defined? MINIMUM_SUPPORTED_CHOCO_UNINSTALL_SOURCE + MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS = '0.10.4.0'.freeze unless defined? MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS + + def file_exists?(path) + File.exist?(path) + end + module_function :file_exists? + + def chocolatey_command + if Puppet::Util::Platform.windows? + # When attempting to find the choco command executable, the following + # paths are checked: + # - Start with the install_path. If choco is found with environment + # variables through the registry or a check on the + # ChocolateyInstall env var (first install of Choco may only have + # this), then use that path. + # - Next look to the most commonly used install location (ProgramData) + # - Fall back to the older install location for older installations + # - If all else fails, attempt to find Chocolatey in the default place + # it installs + choco_install_path = PuppetX::Chocolatey::ChocolateyInstall.install_path + + chocopath = (choco_install_path if choco_install_path && file_exists?("#{choco_install_path}\\choco.exe")) || + ('C:\ProgramData\chocolatey' if file_exists?('C:\ProgramData\chocolatey\choco.exe')) || + ('C:\Chocolatey' if file_exists?('C:\Chocolatey\choco.exe')) || + "#{ENV['ALLUSERSPROFILE']}\\chocolatey" + + chocopath += '\choco.exe' + else + chocopath = 'choco.exe' end + + chocopath + end + module_function :chocolatey_command + + def set_env_chocolateyinstall + ENV['ChocolateyInstall'] = PuppetX::Chocolatey::ChocolateyInstall.install_path + end + module_function :set_env_chocolateyinstall + + def choco_version + @chocoversion ||= strip_beta_from_version(PuppetX::Chocolatey::ChocolateyVersion.version) + end + module_function :choco_version + + def self.strip_beta_from_version(value) + return nil if value.nil? + + value.split(%r{-})[0] + end + + def choco_config_file + choco_install_path = PuppetX::Chocolatey::ChocolateyInstall.install_path + choco_config = "#{choco_install_path}\\config\\chocolatey.config" + + # choco may be installed, but a config file doesn't exist until the + # first run of choco - trigger that by checking the version + return choco_config if file_exists?(choco_config) + + old_choco_config = "#{choco_install_path}\\chocolateyinstall\\chocolatey.config" + + return old_choco_config if file_exists?(old_choco_config) + + nil + end + module_function :choco_config_file + + # clears the cached values + def clear_cached_values + @chocoversion = nil + @compiled_choco = nil end + module_function :clear_cached_values end diff --git a/lib/puppet_x/chocolatey/chocolatey_install.rb b/lib/puppet_x/chocolatey/chocolatey_install.rb index f607efbf..4c16007b 100644 --- a/lib/puppet_x/chocolatey/chocolatey_install.rb +++ b/lib/puppet_x/chocolatey/chocolatey_install.rb @@ -1,7 +1,11 @@ +# rubocop:disable Style/ClassAndModuleChildren + +# Puppet Extensions Module module PuppetX + # Chocolatey module module Chocolatey + # Class for installation of Chocolatey class ChocolateyInstall - def self.install_path value = nil @@ -13,7 +17,7 @@ def self.install_path hive.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_READ | 0x100) do |reg| value = reg['ChocolateyInstall'] end - rescue Win32::Registry::Error => e + rescue Win32::Registry::Error value = nil end end @@ -31,33 +35,32 @@ def self.install_path end def self.temp_dir - if Puppet::Util::Platform.windows? - require 'win32/registry' - + return unless Puppet::Util::Platform.windows? + require 'win32/registry' + + value = nil + begin + # looking at current user may likely fail because it's likely going to be LocalSystem + hive = Win32::Registry::HKEY_CURRENT_USER + hive.open('Environment', Win32::Registry::KEY_READ | 0x100) do |reg| + value = reg['TEMP'] + end + rescue Win32::Registry::Error value = nil + end + + if value.nil? begin - # looking at current user may likely fail because it's likely going to be LocalSystem - hive = Win32::Registry::HKEY_CURRENT_USER - hive.open('Environment', Win32::Registry::KEY_READ | 0x100) do |reg| + hive = Win32::Registry::HKEY_LOCAL_MACHINE + hive.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_READ | 0x100) do |reg| value = reg['TEMP'] end - rescue Win32::Registry::Error => e + rescue Win32::Registry::Error value = nil end - - if value.nil? - begin - hive = Win32::Registry::HKEY_LOCAL_MACHINE - hive.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_READ | 0x100) do |reg| - value = reg['TEMP'] - end - rescue Win32::Registry::Error => e - value = nil - end - end - - value end + + value end end end diff --git a/lib/puppet_x/chocolatey/chocolatey_version.rb b/lib/puppet_x/chocolatey/chocolatey_version.rb index a69bef9c..29bcb904 100644 --- a/lib/puppet_x/chocolatey/chocolatey_version.rb +++ b/lib/puppet_x/chocolatey/chocolatey_version.rb @@ -1,32 +1,28 @@ require 'pathname' require Pathname.new(__FILE__).dirname + 'chocolatey_install' -module PuppetX - module Chocolatey - class ChocolateyVersion +# Module responsible for retrieving the version of the currently installed Chocolatey executable +module PuppetX::Chocolatey::ChocolateyVersion + OLD_CHOCO_MESSAGE = 'Please run chocolatey /? or chocolatey help - chocolatey v'.freeze unless defined? OLD_CHOCO_MESSAGE - OLD_CHOCO_MESSAGE = "Please run chocolatey /? or chocolatey help - chocolatey v" unless defined? OLD_CHOCO_MESSAGE - - def self.version - version = nil - choco_path = "#{PuppetX::Chocolatey::ChocolateyInstall.install_path}\\choco.exe" - if Puppet::Util::Platform.windows? && File.exist?(choco_path) - begin - # call `choco -v` - # - new choco will output a single value e.g. `0.9.9` - # - old choco is going to return the default output e.g. `Please run chocolatey /?` - version = Puppet::Util::Execution.execute("#{choco_path} -v").gsub(OLD_CHOCO_MESSAGE,'') - # - other messages, such as upgrade warnings or warnings about - # installing the licensed extension once the license is installed - # may show up when running this comamnd. Remove those as well - version = version.split(/\r\n|\n|\r/).last.strip unless version.nil? - rescue StandardError => e - version = '0' - end - end - - version + def self.version + version = nil + choco_path = "#{PuppetX::Chocolatey::ChocolateyInstall.install_path}\\choco.exe" + if Puppet::Util::Platform.windows? && File.exist?(choco_path) + begin + # call `choco -v` + # - new choco will output a single value e.g. `0.9.9` + # - old choco is going to return the default output e.g. `Please run chocolatey /?` + version = Puppet::Util::Execution.execute("#{choco_path} -v").gsub(OLD_CHOCO_MESSAGE, '') + # - other messages, such as upgrade warnings or warnings about + # installing the licensed extension once the license is installed + # may show up when running this comamnd. Remove those as well + version = version.split(%r{\r\n|\n|\r}).last.strip unless version.nil? + rescue StandardError + version = '0' end end + + version end end diff --git a/metadata.json b/metadata.json index f35ef309..963b5809 100644 --- a/metadata.json +++ b/metadata.json @@ -56,7 +56,7 @@ "chocolatey for business", "chocolatey professional" ], - "pdk-version": "1.8.0", - "template-url": "https://github.com/puppetlabs/pdk-templates", - "template-ref": "heads/master-0-g7281db5" -} \ No newline at end of file + "pdk-version": "1.10.0", + "template-url": "https://github.com/puppetlabs/pdk-templates#master", + "template-ref": "heads/master-0-g7b1d6ae" +} diff --git a/spec/acceptance/config_values_spec.rb b/spec/acceptance/config_values_spec.rb index cf209b61..ac5f635e 100644 --- a/spec/acceptance/config_values_spec.rb +++ b/spec/acceptance/config_values_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper_acceptance' describe 'Chocolatey Config' do - context 'MODULES-3035 - Add New Config Item' do - before(:all) do backup_config end @@ -19,11 +17,10 @@ } PP - it_behaves_like 'a successful config change', chocolatey_src, 'hello123', /this guy/ + it_behaves_like 'a successful config change', chocolatey_src, 'hello123', %r{this guy} end context 'MODULES-3035 - Add a Value to an Existing Config Setting' do - before(:all) do backup_config end @@ -38,12 +35,11 @@ value => 'https://somewhere', } PP - - it_behaves_like 'a successful config change', chocolatey_src, 'proxy', /https\:\/\/somewhere/ + + it_behaves_like 'a successful config change', chocolatey_src, 'proxy', %r{https\:\/\/somewhere} end context 'MODULES-3035 - Config Settings Change Config Value' do - before(:all) do backup_config end @@ -65,14 +61,13 @@ PP # Add the config item - it_behaves_like 'a successful config change', chocolatey_src, 'proxyUser', /bob/ + it_behaves_like 'a successful config change', chocolatey_src, 'proxyUser', %r{bob} # Now that it exists, change its value - it_behaves_like 'a successful config change', chocolatey_src_change, 'proxyUser', /tim/ + it_behaves_like 'a successful config change', chocolatey_src_change, 'proxyUser', %r{tim} end context 'MODULES-3035 Ensure Config Value with Password In Name' do - before(:all) do backup_config end @@ -98,7 +93,6 @@ end context 'MODULES-3035 - Fail to Set Present With No Value' do - before(:all) do backup_config end @@ -113,14 +107,13 @@ } PP - expected_error = /Unless ensure => absent, value is required./ + expected_error = %r{Unless ensure => absent, value is required.} # A manifest with present set, but no values to enforce should not run. it_behaves_like 'a failing manifest', chocolatey_src, expected_error end context 'MODULES-3035 - Config Settings Remove Value with Password in the Name' do - before(:all) do backup_config end @@ -142,13 +135,12 @@ PP # The password will end up a hash, so we specify a regex that just verifies a hash exists. - it_behaves_like 'a successful config change', chocolatey_src, 'proxyPassword', /(.+)/ + it_behaves_like 'a successful config change', chocolatey_src, 'proxyPassword', %r{(.+)} it_behaves_like 'a manifest that removes a config value', chocolatey_src_change, 'proxyPassword' end context 'MODULES-3035 - Remove Value from Config Setting' do - before(:all) do backup_config end @@ -166,4 +158,3 @@ it_behaves_like 'a manifest that removes a config value', chocolatey_src, 'commandExecutionTimeoutSeconds' end end - diff --git a/spec/acceptance/features_spec.rb b/spec/acceptance/features_spec.rb index 64400f27..509ae236 100644 --- a/spec/acceptance/features_spec.rb +++ b/spec/acceptance/features_spec.rb @@ -2,7 +2,6 @@ describe 'Chocolatey features' do context 'MODULES-3034 Disable an Already Disabled Feature' do - before(:all) do backup_config end @@ -17,27 +16,27 @@ } PP - windows_agents.each do | agent | - it 'should verify the features is disabled' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//features/feature[@name='failOnAutoUninstaller']/@enabled", result.output).to_s, 'Was not disabled by default, please adjust test to find another value.') + windows_agents.each do |agent| + it 'verifies the features is disabled' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//features/feature[@name='failOnAutoUninstaller']/@enabled", result.output).to_s, + 'Was not disabled by default, please adjust test to find another value.') end end - it 'Should apply the manifest to disable the feature' do - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + it 'applies the manifest to disable the feature' do + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'should verify the feature is still disabled' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//features/feature[@name='failOnAutoUninstaller']/@enabled", result.output).to_s, 'Was not found disabled') + it 'verifies the feature is still disabled' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//features/feature[@name='failOnAutoUninstaller']/@enabled", result.output).to_s, 'Was not found disabled') end end end end context 'MODULES-3034 Disable an Enabled Feature' do - before(:all) do backup_config end @@ -52,27 +51,26 @@ } PP - windows_agents.each do | agent | - it 'should validate the feature is enabled' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//features/feature[@name='checksumFiles']/@enabled", result.output).to_s, 'Was not enabled by default, please adjust test to find another value.') + windows_agents.each do |agent| + it 'validates the feature is enabled' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//features/feature[@name='checksumFiles']/@enabled", result.output).to_s, 'Was not enabled by default, please adjust test to find another value.') end end - it 'should apply the manifest to disable the feature' do + it 'applies the manifest to disable the feature' do execute_manifest_on(agent, chocolatey_src) end - it 'should validate the feature is now disabled' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//features/feature[@name='checksumFiles']/@enabled", result.output).to_s, 'Was not found disabled') + it 'validates the feature is now disabled' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//features/feature[@name='checksumFiles']/@enabled", result.output).to_s, 'Was not found disabled') end end end end context 'MODULES-3034 Enable a Disabled Feature' do - before(:all) do backup_config end @@ -87,27 +85,27 @@ } PP - windows_agents.each do | agent | - it 'Should verify the feature is disabled' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//features/feature[@name='failOnAutoUninstaller']/@enabled", result.output).to_s, 'Was not disabled by default, please adjust test to find another value.') + windows_agents.each do |agent| + it 'verifies the feature is disabled' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//features/feature[@name='failOnAutoUninstaller']/@enabled", result.output).to_s, + 'Was not disabled by default, please adjust test to find another value.') end end - it 'should apply the manifest to enable the feature' do - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + it 'applies the manifest to enable the feature' do + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the feature is now enabled' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//features/feature[@name='failOnAutoUninstaller']/@enabled", result.output).to_s, 'Was not found enabled') + it 'verifies the feature is now enabled' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//features/feature[@name='failOnAutoUninstaller']/@enabled", result.output).to_s, 'Was not found enabled') end end end end context 'MODULES-3034 - Enable Already Enabled Feature' do - before(:all) do backup_config end @@ -122,27 +120,26 @@ } PP - windows_agents.each do | agent | - it 'Should verify the feature is already enabled' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//features/feature[@name='usePackageExitCodes']/@enabled", result.output).to_s, 'Was not enabled by default, please adjust test to find another value.') + windows_agents.each do |agent| + it 'verifies the feature is already enabled' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//features/feature[@name='usePackageExitCodes']/@enabled", result.output).to_s, 'Was not enabled by default, please adjust test to find another value.') end end - it 'should apply the manifest to enable the feature' do - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + it 'applies the manifest to enable the feature' do + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the feature is still enabled' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//features/feature[@name='usePackageExitCodes']/@enabled", result.output).to_s, 'Was not found enabled') + it 'verifies the feature is still enabled' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//features/feature[@name='usePackageExitCodes']/@enabled", result.output).to_s, 'Was not found enabled') end end end end context 'MODULES-3034 - Enable a non-existent feature' do - before(:all) do backup_config end @@ -157,17 +154,16 @@ } PP - windows_agents.each do | agent | - it 'Should fail to apply the manifest' do - execute_manifest_on(agent, chocolatey_src, :expect_failures => true) do | result | - assert_match(/returned 1: Feature 'idontexistfeature123123' not found/, result.stderr, "stderr did not match expected") + windows_agents.each do |agent| + it 'fails to apply the manifest' do + execute_manifest_on(agent, chocolatey_src, expect_failures: true) do |result| + assert_match(%r{returned 1: Feature 'idontexistfeature123123' not found}, result.stderr, 'stderr did not match expected') end end end end context 'MODULES-3034 - Enable non-existent feature' do - before(:all) do backup_config end @@ -182,17 +178,16 @@ } PP - windows_agents.each do | agent | - it 'Should fail to apply the manifest' do - execute_manifest_on(agent, chocolatey_src, :expect_failures => true) do | result | - assert_match(/returned 1: Feature 'idontexistfeature123123' not found/, result.stderr, "stderr did not match expected") + windows_agents.each do |agent| + it 'fails to apply the manifest' do + execute_manifest_on(agent, chocolatey_src, expect_failures: true) do |result| + assert_match(%r{returned 1: Feature 'idontexistfeature123123' not found}, result.stderr, 'stderr did not match expected') end end end end context 'MODULES-3034 - Attempt to remove feature' do - before(:all) do backup_config end @@ -207,13 +202,12 @@ } PP - windows_agents.each do | agent | - it 'Should fail to apply the manifest' do - execute_manifest_on(agent, chocolatey_src, :expect_failures => true) do | result | - assert_match(/Error: Parameter ensure failed on Chocolateyfeature\[checksumFiles\]: Invalid value \"absent\"/, result.stderr, "stderr did not match expected") + windows_agents.each do |agent| + it 'fails to apply the manifest' do + execute_manifest_on(agent, chocolatey_src, expect_failures: true) do |result| + assert_match(%r{Error: Parameter ensure failed on Chocolateyfeature\[checksumFiles\]: Invalid value \"absent\"}, result.stderr, 'stderr did not match expected') end end end end end - diff --git a/spec/acceptance/package_spec.rb b/spec/acceptance/package_spec.rb index 619919d1..95ebd3eb 100644 --- a/spec/acceptance/package_spec.rb +++ b/spec/acceptance/package_spec.rb @@ -1,11 +1,10 @@ require 'spec_helper_acceptance' describe 'Chocolatey Package' do - context 'MODULES-3037 Install a known good package via manifest and remove via manifest' do package_name = 'vlc' - package_exe_path = %{C:\\'Program Files\\VideoLAN\\VLC\\vlc.exe'} - software_uninstall_command = %{cmd.exe /C C:\\'Program Files\\VideoLAN\\VLC\\uninstall.exe' /S} + package_exe_path = %(C:\\'Program Files\\VideoLAN\\VLC\\vlc.exe') + software_uninstall_command = %(cmd.exe /C C:\\'Program Files\\VideoLAN\\VLC\\uninstall.exe' /S) chocolatey_package_manifest = <<-PP package { "#{package_name}": @@ -23,36 +22,35 @@ PP after(:all) do - windows_agents.each do | agent | - on(agent, powershell("test-path #{package_exe_path}", {'EncodedCommand' => true}), :catch_errors => true) do | result | - on(agent, powershell(software_uninstall_command, {'EncodedCommand' => true}), :catch_errors => true) if result.stdout =~ /True/ + windows_agents.each do |agent| + on(agent, powershell("test-path #{package_exe_path}", 'EncodedCommand' => true), catch_errors: true) do |result| + on(agent, powershell(software_uninstall_command, 'EncodedCommand' => true), catch_errors: true) if result.stdout =~ %r{True} end end end - windows_agents.each do | agent | - - it 'Should verify the package is not installed.' do - on(agent, powershell("test-path #{package_exe_path}", {'EncodedCommand' => true}), :catch_errors => true) do | result | - assert_match(/False/i, result.output, "#{package_name} was present before application of manifest.") + windows_agents.each do |agent| + it 'verifies the package is not installed.' do + on(agent, powershell("test-path #{package_exe_path}", 'EncodedCommand' => true), catch_errors: true) do |result| + assert_match(%r{False}i, result.output, "#{package_name} was present before application of manifest.") end end - it 'Should apply the manifest to install the package' do - execute_manifest_on(agent, chocolatey_package_manifest, :catch_failures => true) do | result | - assert_match(/Notice\: \/Stage\[main\]\/Main\/Package\[#{package_name}\]\/ensure\: created/, result.stdout, "stdout did not report package creation of #{package_name}") + it 'applies the manifest to install the package' do + execute_manifest_on(agent, chocolatey_package_manifest, catch_failures: true) do |result| + assert_match(%r{Notice\: \/Stage\[main\]\/Main\/Package\[#{package_name}\]\/ensure\: created}, result.stdout, "stdout did not report package creation of #{package_name}") end end it "should have a valid version of #{package_name}" do - on(agent, powershell("test-path #{package_exe_path}", {'EncodedCommand' => true}), :catch_errors => true) do |result| - assert_match(/True/i, result.output, "#{package_name} was not present after application of manifest.") + on(agent, powershell("test-path #{package_exe_path}", 'EncodedCommand' => true), catch_errors: true) do |result| + assert_match(%r{True}i, result.output, "#{package_name} was not present after application of manifest.") end end - it 'Should uninstall the package' do - execute_manifest_on(agent, chocolatey_package_manifest_chng, :catch_failures => true) do | result | - assert_match(/Stage\[main\]\/Main\/Package\[#{package_name}\]\/ensure\: removed/, result.stdout, "stdout did not report package removal of #{package_name}") + it 'uninstalls the package' do + execute_manifest_on(agent, chocolatey_package_manifest_chng, catch_failures: true) do |result| + assert_match(%r{Stage\[main\]\/Main\/Package\[#{package_name}\]\/ensure\: removed}, result.stdout, "stdout did not report package removal of #{package_name}") end end end @@ -61,7 +59,7 @@ skip 'UTF-8 Not Suported At This Time - MODULES-3037 Install a known good package with utf-8 via manifest and remove via manifest' do package_name = '竹ChocolateyGUIÖ' package_exe_path = %{C:\\'Program Files (x86)\\ChocolateyGUI\\ChocolateyGUI.exe'} - software_uninstall_command = %{msiexec /x C:\\ProgramData\\chocolatey\\lib\\竹ChocolateyGUIÖ\\tools\\竹ChocolateyGUIÖ.msi /q}.force_encoding("ASCII-8BIT") + software_uninstall_command = %(msiexec /x C:\\ProgramData\\chocolatey\\lib\\竹ChocolateyGUIÖ\\tools\\竹ChocolateyGUIÖ.msi /q).force_encoding('ASCII-8BIT') chocolatey_package_manifest = <<-PP package { "#{package_name}": @@ -79,39 +77,37 @@ PP after(:all) do - windows_agents.each do | agent | - on(agent, powershell("test-path #{package_exe_path}", {'EncodedCommand' => true}), :catch_errors => true) do | result | - on(agent, powershell(software_uninstall_command, {'EncodedCommand' => true}), :catch_errors => true) if result.stdout =~ /True/ + windows_agents.each do |agent| + on(agent, powershell("test-path #{package_exe_path}", 'EncodedCommand' => true), catch_errors: true) do |result| + on(agent, powershell(software_uninstall_command, 'EncodedCommand' => true), catch_errors: true) if result.stdout =~ %r{True} end end end - windows_agents.each do | agent | - - it 'Should verify the package is not installed.' do - on(agent, powershell("test-path #{package_exe_path}", {'EncodedCommand' => true}), :catch_errors => true) do | result | - assert_match(/False/i, result.output, "#{package_name} was present before application of manifest.") + windows_agents.each do |agent| + it 'verifies the package is not installed.' do + on(agent, powershell("test-path #{package_exe_path}", 'EncodedCommand' => true), catch_errors: true) do |result| + assert_match(%r{False}i, result.output, "#{package_name} was present before application of manifest.") end end - it 'Should apply the manifest to install the package' do - execute_manifest_on(agent, chocolatey_package_manifest, :catch_failures => true) do | result | - assert_match(/Notice\: \/Stage\[main\]\/Main\/Package\[#{package_name}\]\/ensure\: created/, result.stdout, "stdout did not report package creation of #{package_name}") + it 'applies the manifest to install the package' do + execute_manifest_on(agent, chocolatey_package_manifest, catch_failures: true) do |result| + assert_match(%r{Notice\: \/Stage\[main\]\/Main\/Package\[#{package_name}\]\/ensure\: created}, result.stdout, "stdout did not report package creation of #{package_name}") end end it "should have a valid version of #{package_name}" do - on(agent, powershell("test-path #{package_exe_path}", {'EncodedCommand' => true}), :catch_errors => true) do |result| - assert_match(/True/i, result.output, "#{package_name} was not present after application of manifest.") + on(agent, powershell("test-path #{package_exe_path}", 'EncodedCommand' => true), catch_errors: true) do |result| + assert_match(%r{True}i, result.output, "#{package_name} was not present after application of manifest.") end end - it 'Should uninstall the package' do - execute_manifest_on(agent, chocolatey_package_manifest_chng, :catch_failures => true) do | result | - assert_match(/Stage\[main\]\/Main\/Package\[#{package_name}\]\/ensure\: removed/, result.stdout, "stdout did not report package removal of #{package_name}") + it 'uninstalls the package' do + execute_manifest_on(agent, chocolatey_package_manifest_chng, catch_failures: true) do |result| + assert_match(%r{Stage\[main\]\/Main\/Package\[#{package_name}\]\/ensure\: removed}, result.stdout, "stdout did not report package removal of #{package_name}") end end end end end - diff --git a/spec/acceptance/sources_spec.rb b/spec/acceptance/sources_spec.rb index 8df1c47a..f82cc3bb 100644 --- a/spec/acceptance/sources_spec.rb +++ b/spec/acceptance/sources_spec.rb @@ -2,7 +2,6 @@ describe 'Chocolatey Source' do context 'MODULES-3037 - Add Priority to an Existing Source' do - before(:all) do backup_config end @@ -11,9 +10,8 @@ reset_config end - windows_agents.each do | agent | - - it 'Should Apply the Manifest' do + windows_agents.each do |agent| + it 'Applies the Manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -22,19 +20,18 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should now have proper priority' do + it 'nows have proper priority' do on(agent, config_content_command) do |result| - assert_match(/1/, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority did not match') + assert_match(%r{1}, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority did not match') end end end end context 'MODULES-4418 - Add Bypass Proxy to an Existing Source' do - before(:all) do backup_config end @@ -43,9 +40,8 @@ reset_config end - windows_agents.each do | agent | - - it 'Should Apply the Manifest' do + windows_agents.each do |agent| + it 'Applies the Manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -54,19 +50,18 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should now bypass system proxies' do + it 'nows bypass system proxies' do on(agent, config_content_command) do |result| - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy did not match') + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy did not match') end end end end context 'MODULES-5897 - Add Self Service to an Existing Source' do - before(:all) do backup_config end @@ -75,9 +70,8 @@ reset_config end - windows_agents.each do | agent | - - it 'Should Apply the Manifest' do + windows_agents.each do |agent| + it 'Applies the Manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -86,19 +80,18 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should now mark the source as usable for self-service' do + it 'nows mark the source as usable for self-service' do on(agent, config_content_command) do |result| - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service did not match') + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service did not match') end end end end context 'MODULES-5898 - Add Admin Only to an Existing Source' do - before(:all) do backup_config end @@ -107,9 +100,8 @@ reset_config end - windows_agents.each do | agent | - - it 'Should Apply the Manifest' do + windows_agents.each do |agent| + it 'Applies the Manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -118,19 +110,18 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should now set the source as visible only to administrators' do + it 'nows set the source as visible only to administrators' do on(agent, config_content_command) do |result| - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only did not match') + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only did not match') end end end end context 'MODULES-3037 - Add Source With All Options' do - before(:all) do backup_config end @@ -139,9 +130,8 @@ reset_config end - windows_agents.each do | agent | - - it 'Should Apply the Manifest' do + windows_agents.each do |agent| + it 'Applies the Manifest' do chocolatey_src = <<-PP chocolateysource {'test': ensure => present, @@ -155,26 +145,25 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should have the correct properties' do - on(agent, config_content_command) do | result | - assert_match(/c:\\packages/, get_xml_value("//sources/source[@id='test']/@value", result.output).to_s, 'Location did not match') - assert_match(/2/, get_xml_value("//sources/source[@id='test']/@priority", result.output).to_s, 'Priority did not match') - assert_match(/bob/, get_xml_value("//sources/source[@id='test']/@user", result.output).to_s, 'User did not match') - assert_match(/.+/, get_xml_value("//sources/source[@id='test']/@password", result.output).to_s, 'Password was not saved') - assert_match(/false/, get_xml_value("//sources/source[@id='test']/@disabled", result.output).to_s, 'Disabled did not match') - assert_match(/true/, get_xml_value("//sources/source[@id='test']/@bypassProxy", result.output).to_s, 'Bypass Proxy did not match') - assert_match(/true/, get_xml_value("//sources/source[@id='test']/@selfService", result.output).to_s, 'Self Service did not match') - assert_match(/true/, get_xml_value("//sources/source[@id='test']/@adminOnly", result.output).to_s, 'Admin Only did not match') + it 'has the correct properties' do + on(agent, config_content_command) do |result| + assert_match(%r{c:\\packages}, get_xml_value("//sources/source[@id='test']/@value", result.output).to_s, 'Location did not match') + assert_match(%r{2}, get_xml_value("//sources/source[@id='test']/@priority", result.output).to_s, 'Priority did not match') + assert_match(%r{bob}, get_xml_value("//sources/source[@id='test']/@user", result.output).to_s, 'User did not match') + assert_match(%r{.+}, get_xml_value("//sources/source[@id='test']/@password", result.output).to_s, 'Password was not saved') + assert_match(%r{false}, get_xml_value("//sources/source[@id='test']/@disabled", result.output).to_s, 'Disabled did not match') + assert_match(%r{true}, get_xml_value("//sources/source[@id='test']/@bypassProxy", result.output).to_s, 'Bypass Proxy did not match') + assert_match(%r{true}, get_xml_value("//sources/source[@id='test']/@selfService", result.output).to_s, 'Self Service did not match') + assert_match(%r{true}, get_xml_value("//sources/source[@id='test']/@adminOnly", result.output).to_s, 'Admin Only did not match') end end end end context 'MODULES-3037 - Add Source Minimal' do - before(:all) do backup_config end @@ -183,28 +172,27 @@ reset_config end - windows_agents.each do | agent | - it 'Should Apply the Manifest' do + windows_agents.each do |agent| + it 'Applies the Manifest' do chocolatey_src = <<-PP chocolateysource {'test': location => 'c:\\packages', } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the results' do + it 'verifies the results' do on(agent, config_content_command) do |result| - assert_match(/c:\\packages/, get_xml_value("//sources/source[@id='test']/@value", result.output).to_s, 'Location did not match') - assert_match(/false/, get_xml_value("//sources/source[@id='test']/@disabled", result.output).to_s, 'Disabled did not match') + assert_match(%r{c:\\packages}, get_xml_value("//sources/source[@id='test']/@value", result.output).to_s, 'Location did not match') + assert_match(%r{false}, get_xml_value("//sources/source[@id='test']/@disabled", result.output).to_s, 'Disabled did not match') end end end end context 'MODULES-3037 - Add Source Happy Path' do - before(:all) do backup_config end @@ -213,8 +201,8 @@ reset_config end - windows_agents.each do | agent | - it 'Should Apply the manifest' do + windows_agents.each do |agent| + it 'Applies the manifest' do chocolatey_src = <<-PP chocolateysource {'test': ensure => present, @@ -222,20 +210,19 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/c:\\packages/, get_xml_value("//sources/source[@id='test']/@value", result.output).to_s, 'Location did not match') - assert_match(/false/, get_xml_value("//sources/source[@id='test']/@disabled", result.output).to_s, 'Disabled did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{c:\\packages}, get_xml_value("//sources/source[@id='test']/@value", result.output).to_s, 'Location did not match') + assert_match(%r{false}, get_xml_value("//sources/source[@id='test']/@disabled", result.output).to_s, 'Disabled did not match') end end end end context 'MODULES-3037 - Add User/Password to an Existing Source' do - before(:all) do backup_config end @@ -244,8 +231,8 @@ reset_config end - windows_agents.each do | agent | - it 'Should apply the manifest' do + windows_agents.each do |agent| + it 'applies the manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -255,31 +242,30 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the results' do + it 'verifies the results' do on(agent, config_content_command) do |result| - assert_match(/tim/, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User did not match') + assert_match(%r{tim}, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User did not match') # we are not able to verify password other than if it has a value - it will be encrypted in a non-verifyable way - assert_match(/.+/, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password was not saved') + assert_match(%r{.+}, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password was not saved') end end end end context 'MODULES-3037 - Change Existing Priority' do - before(:all) do backup_config end - + after(:all) do reset_config end - windows_agents.each do | agent | - it 'Should apply a manifest to set priority' do + windows_agents.each do |agent| + it 'applies a manifest to set priority' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -288,16 +274,16 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the setup was added' do - on(agent, config_content_command) do | result | - assert_match(/1/, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority setup did not match') + it 'verifies the setup was added' do + on(agent, config_content_command) do |result| + assert_match(%r{1}, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority setup did not match') end end - it 'Should apply a manifest to change the priority' do + it 'applies a manifest to change the priority' do chocolatey_src_change = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -306,29 +292,28 @@ } PP - execute_manifest_on(agent, chocolatey_src_change, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src_change, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/5/, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority change did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{5}, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority change did not match') end end end end context 'MODULES-4418 - Change Existing Bypass Proxy Setting' do - before(:all) do backup_config end - + after(:all) do reset_config end - windows_agents.each do | agent | - it 'Should apply a manifest to set bypass_proxy' do + windows_agents.each do |agent| + it 'applies a manifest to set bypass_proxy' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -337,16 +322,16 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the setup was added' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy setup did not match') + it 'verifies the setup was added' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy setup did not match') end end - it 'Should apply a manifest to set bypass_proxy to false' do + it 'applies a manifest to set bypass_proxy to false' do chocolatey_src_change = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -355,29 +340,28 @@ } PP - execute_manifest_on(agent, chocolatey_src_change, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src_change, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy change did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy change did not match') end end end end context 'MODULES-5897 - Change Existing Self Service Setting' do - before(:all) do backup_config end - + after(:all) do reset_config end - windows_agents.each do | agent | - it 'Should apply a manifest to set allow_self_service' do + windows_agents.each do |agent| + it 'applies a manifest to set allow_self_service' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -386,16 +370,16 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the setup was added' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service setup did not match') + it 'verifies the setup was added' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service setup did not match') end end - it 'Should apply a manifest to set allow_self_service to false' do + it 'applies a manifest to set allow_self_service to false' do chocolatey_src_change = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -404,29 +388,28 @@ } PP - execute_manifest_on(agent, chocolatey_src_change, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src_change, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service change did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service change did not match') end end end end context 'MODULES-5898 - Change Existing Admin Only Setting' do - before(:all) do backup_config end - + after(:all) do reset_config end - windows_agents.each do | agent | - it 'Should apply a manifest to set admin_only' do + windows_agents.each do |agent| + it 'applies a manifest to set admin_only' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -435,16 +418,16 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the setup was added' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only setup did not match') + it 'verifies the setup was added' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only setup did not match') end end - it 'Should apply a manifest to set admin_only to false' do + it 'applies a manifest to set admin_only to false' do chocolatey_src_change = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -453,19 +436,18 @@ } PP - execute_manifest_on(agent, chocolatey_src_change, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src_change, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only change did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only change did not match') end end end end context 'MODULES-3037 - Change Source Location for an Existing Source' do - before(:all) do backup_config end @@ -474,8 +456,8 @@ reset_config end - windows_agents.each do | agent | - it 'Should Apply a manifest' do + windows_agents.each do |agent| + it 'Applies a manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -483,19 +465,18 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the results' do - on(agent, config_content_command) do | result | - assert_match(/c:\\packages/, get_xml_value("//sources/source[@id='chocolatey']/@value", result.output).to_s, 'Location did not match') + it 'verifies the results' do + on(agent, config_content_command) do |result| + assert_match(%r{c:\\packages}, get_xml_value("//sources/source[@id='chocolatey']/@value", result.output).to_s, 'Location did not match') end end end end context 'MODULES-3037 - Change User/Password in an existing source.' do - before(:all) do backup_config end @@ -504,8 +485,8 @@ reset_config end - windows_agents.each do | agent | - it 'Should apply a manifest to create a username/pass' do + windows_agents.each do |agent| + it 'applies a manifest to create a username/pass' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -515,18 +496,18 @@ } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the results' do - on(agent, config_content_command) do | result | - assert_match(/tim/, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User setup did not match') + it 'verifies the results' do + on(agent, config_content_command) do |result| + assert_match(%r{tim}, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User setup did not match') # we are not able to verify password other than if it has a value - it will be encrypted in a non-verifyable way - assert_match(/.+/, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password was not saved') + assert_match(%r{.+}, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password was not saved') end end - it 'Should apply a manifest to change the values' do + it 'applies a manifest to change the values' do chocolatey_src_change = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -536,50 +517,48 @@ } PP - execute_manifest_on(agent, chocolatey_src_change, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src_change, catch_failures: true) end - it 'Should validate the results' do - on(agent, config_content_command) do | result | - assert_match(/bob/, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User change did not match') - assert_match(/.+/, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password no longer exists') + it 'validates the results' do + on(agent, config_content_command) do |result| + assert_match(%r{bob}, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User change did not match') + assert_match(%r{.+}, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password no longer exists') end end end end context 'MODULES-3037 - Disable an Existing resource' do - before(:all) do backup_config end - + after(:all) do reset_config end - windows_agents.each do | agent | - it 'Should apply a manifest to disable the resource' do + windows_agents.each do |agent| + it 'applies a manifest to disable the resource' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => disabled, } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) - execute_manifest_on(agent, chocolatey_src, :catch_changes => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) + execute_manifest_on(agent, chocolatey_src, catch_changes: true) end - it 'Should verify the results' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@disabled", result.output).to_s, 'Disabled did not match') + it 'verifies the results' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@disabled", result.output).to_s, 'Disabled did not match') end end end end context 'MODULES-3037 Disable an Existing Source' do - before(:all) do backup_config end @@ -588,27 +567,26 @@ reset_config end - windows_agents.each do | agent | - it 'Should Apply a manifest' do + windows_agents.each do |agent| + it 'Applies a manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => disabled, } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the results' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@disabled", result.output).to_s, 'Disabled did not match') + it 'verifies the results' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@disabled", result.output).to_s, 'Disabled did not match') end end end end context 'MODULES-3037 Add Source Sad Path: Fail to apply manifest without location' do - before(:all) do backup_config end @@ -617,23 +595,22 @@ reset_config end - windows_agents.each do | agent | - it 'Should fail to apply a bad manifest with the correct error' do + windows_agents.each do |agent| + it 'fails to apply a bad manifest with the correct error' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, } PP - execute_manifest_on(agent, chocolatey_src, :expect_failures => true) do | result | - assert_match(/Error: Validation of Chocolateysource\[chocolatey\] failed: A non-empty location/, result.stderr, "stderr did not match expected") + execute_manifest_on(agent, chocolatey_src, expect_failures: true) do |result| + assert_match(%r{Error: Validation of Chocolateysource\[chocolatey\] failed: A non-empty location}, result.stderr, 'stderr did not match expected') end end end end context 'MODULES-3037 - Add Source Sad Path: Fail to apply bad manifest' do - before(:all) do backup_config end @@ -642,8 +619,8 @@ reset_config end - windows_agents.each do | agent | - it 'Should fail to apply a manifest' do + windows_agents.each do |agent| + it 'fails to apply a manifest' do chocolatey_src = <<-PP chocolateysource {'test': ensure => sad, @@ -651,15 +628,14 @@ } PP - execute_manifest_on(agent, chocolatey_src, :expect_failures => true) do | result | - assert_match(/Error: Parameter ensure failed on Chocolateysource\[test\]: Invalid value "sad"/, result.stderr, "stderr did not match expected") + execute_manifest_on(agent, chocolatey_src, expect_failures: true) do |result| + assert_match(%r{Error: Parameter ensure failed on Chocolateysource\[test\]: Invalid value "sad"}, result.stderr, 'stderr did not match expected') end end end end context 'MODULES-3037 - Add Source Sad Path: Set password with no user' do - before(:all) do backup_config end @@ -668,8 +644,8 @@ reset_config end - windows_agents.each do | agent | - it 'Should fail to apply a manifest' do + windows_agents.each do |agent| + it 'fails to apply a manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -678,15 +654,14 @@ } PP - execute_manifest_on(agent, chocolatey_src, :expect_failures => true) do | result | - assert_match(/Error: Validation of Chocolateysource\[chocolatey\] failed: If specifying user\/password, you must specify both values/, result.stderr, "stderr did not match expected") + execute_manifest_on(agent, chocolatey_src, expect_failures: true) do |result| + assert_match(%r{Error: Validation of Chocolateysource\[chocolatey\] failed: If specifying user\/password, you must specify both values}, result.stderr, 'stderr did not match expected') end end end end context 'MODULES-3037 - Add Source Sad Path: Set user with no password' do - before(:all) do backup_config end @@ -695,8 +670,8 @@ reset_config end - windows_agents.each do | agent | - it 'Should fail to apply a manifest' do + windows_agents.each do |agent| + it 'fails to apply a manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -705,15 +680,14 @@ } PP - execute_manifest_on(agent, chocolatey_src, :expect_failures => true) do | result | - assert_match(/Error: Validation of Chocolateysource\[chocolatey\] failed: If specifying user\/password, you must specify both values/, result.stderr, "stderr did not match expected") + execute_manifest_on(agent, chocolatey_src, expect_failures: true) do |result| + assert_match(%r{Error: Validation of Chocolateysource\[chocolatey\] failed: If specifying user\/password, you must specify both values}, result.stderr, 'stderr did not match expected') end end end end context 'MODULES-3037 - Remove an Existing Source' do - before(:all) do backup_config end @@ -722,27 +696,26 @@ reset_config end - windows_agents.each do | agent | - it 'Should apply a manifest' do + windows_agents.each do |agent| + it 'applies a manifest' do chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => absent, } PP - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify the result' do - on(agent, config_content_command) do | result | - assert_not_match(/chocolatey/, get_xml_value("//sources/source[@id='chocolatey']/@id", result.output).to_s, 'Source was not removed') + it 'verifies the result' do + on(agent, config_content_command) do |result| + assert_not_match(%r{chocolatey}, get_xml_value("//sources/source[@id='chocolatey']/@id", result.output).to_s, 'Source was not removed') end end end end context 'MODULES-3037 Remove Priority from an Existing Source' do - before(:all) do backup_config end @@ -751,7 +724,7 @@ reset_config end - windows_agents.each do | agent | + windows_agents.each do |agent| chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -767,30 +740,29 @@ } PP - it 'Should apply a manifest' do - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + it 'applies a manifest' do + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify setup' do - on(agent, config_content_command) do | result | - assert_match(/1/, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority did not match') + it 'verifies setup' do + on(agent, config_content_command) do |result| + assert_match(%r{1}, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority did not match') end end - it 'Should apply remove manifest' do - execute_manifest_on(agent, chocolatey_src_remove, :catch_failures => true) + it 'applies remove manifest' do + execute_manifest_on(agent, chocolatey_src_remove, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/0/, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority change did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{0}, get_xml_value("//sources/source[@id='chocolatey']/@priority", result.output).to_s, 'Priority change did not match') end end end end context 'MODULES-4418 Remove Bypass Proxy from an Existing Source' do - before(:all) do backup_config end @@ -799,7 +771,7 @@ reset_config end - windows_agents.each do | agent | + windows_agents.each do |agent| chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -815,30 +787,29 @@ } PP - it 'Should apply a manifest' do - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + it 'applies a manifest' do + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify setup' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy did not match') + it 'verifies setup' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy did not match') end end - it 'Should apply remove manifest' do - execute_manifest_on(agent, chocolatey_src_remove, :catch_failures => true) + it 'applies remove manifest' do + execute_manifest_on(agent, chocolatey_src_remove, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy change did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//sources/source[@id='chocolatey']/@bypassProxy", result.output).to_s, 'Bypass Proxy change did not match') end end end end context 'MODULES-5897 Remove Self Service from an Existing Source' do - before(:all) do backup_config end @@ -847,7 +818,7 @@ reset_config end - windows_agents.each do | agent | + windows_agents.each do |agent| chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -863,30 +834,29 @@ } PP - it 'Should apply a manifest' do - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + it 'applies a manifest' do + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify setup' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service did not match') + it 'verifies setup' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service did not match') end end - it 'Should apply remove manifest' do - execute_manifest_on(agent, chocolatey_src_remove, :catch_failures => true) + it 'applies remove manifest' do + execute_manifest_on(agent, chocolatey_src_remove, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service change did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//sources/source[@id='chocolatey']/@selfService", result.output).to_s, 'Self Service change did not match') end end end end context 'MODULES-5898 Remove Admin Only from an Existing Source' do - before(:all) do backup_config end @@ -895,7 +865,7 @@ reset_config end - windows_agents.each do | agent | + windows_agents.each do |agent| chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -911,30 +881,29 @@ } PP - it 'Should apply a manifest' do - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + it 'applies a manifest' do + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify setup' do - on(agent, config_content_command) do | result | - assert_match(/true/, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only did not match') + it 'verifies setup' do + on(agent, config_content_command) do |result| + assert_match(%r{true}, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only did not match') end end - it 'Should apply remove manifest' do - execute_manifest_on(agent, chocolatey_src_remove, :catch_failures => true) + it 'applies remove manifest' do + execute_manifest_on(agent, chocolatey_src_remove, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_match(/false/, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only change did not match') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_match(%r{false}, get_xml_value("//sources/source[@id='chocolatey']/@adminOnly", result.output).to_s, 'Admin Only change did not match') end end end end context 'MODULES-3037 - Remove User/Password From an Existing Source' do - before(:all) do backup_config end @@ -943,7 +912,7 @@ reset_config end - windows_agents.each do | agent | + windows_agents.each do |agent| chocolatey_src = <<-PP chocolateysource {'chocolatey': ensure => present, @@ -960,29 +929,28 @@ } PP - it 'Should apply a manifest' do - execute_manifest_on(agent, chocolatey_src, :catch_failures => true) + it 'applies a manifest' do + execute_manifest_on(agent, chocolatey_src, catch_failures: true) end - it 'Should verify setup' do - on(agent, config_content_command) do | result | - assert_match(/tim/, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User setup did not match') + it 'verifies setup' do + on(agent, config_content_command) do |result| + assert_match(%r{tim}, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User setup did not match') # we are not able to verify password other than if it has a value - it will be encrypted in a non-verifyable way - assert_match(/.+/, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password was not saved') + assert_match(%r{.+}, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password was not saved') end end - it 'Should apply remove manifest' do - execute_manifest_on(agent, chocolatey_src_remove, :catch_failures => true) + it 'applies remove manifest' do + execute_manifest_on(agent, chocolatey_src_remove, catch_failures: true) end - it 'Should verify results' do - on(agent, config_content_command) do | result | - assert_not_match(/.+/, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User was not removed') - assert_not_match(/.+/, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password was not removed') + it 'verifies results' do + on(agent, config_content_command) do |result| + assert_not_match(%r{.+}, get_xml_value("//sources/source[@id='chocolatey']/@user", result.output).to_s, 'User was not removed') + assert_not_match(%r{.+}, get_xml_value("//sources/source[@id='chocolatey']/@password", result.output).to_s, 'Password was not removed') end end end end end - diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index c0ef0629..14805d2b 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,26 +1,25 @@ require 'spec_helper' RSpec.describe 'chocolatey' do - let(:facts) { + let(:facts) do { - :path => 'C:\something', + path: 'C:\something', } - } + end + context 'contains config.pp' do context 'with older choco installed' do - let(:facts) { - super().merge({ - :chocolateyversion => '0.9.8.33', - :choco_install_path => 'C:\ProgramData\chocolatey', - }) - } + let(:facts) do + super().merge(chocolateyversion: '0.9.8.33', + choco_install_path: 'C:\ProgramData\chocolatey') + end [true, false].each do |param_value| feature_enable = 'enable' - feature_enable = 'disable' if !param_value + feature_enable = 'disable' unless param_value context "enable_autouninstaller => #{param_value}" do - let(:params) {{ :enable_autouninstaller => param_value }} + let(:params) { { enable_autouninstaller: param_value } } it { is_expected.not_to contain_exec("chocolatey_autouninstaller_#{feature_enable}") } @@ -32,19 +31,17 @@ end context 'without choco installed' do - let(:facts) { - super().merge({ - :chocolateyversion => '0', - :choco_install_path => 'C:\ProgramData\chocolatey', - }) - } + let(:facts) do + super().merge(chocolateyversion: '0', + choco_install_path: 'C:\ProgramData\chocolatey') + end [true, false].each do |param_value| feature_enable = 'enable' - feature_enable = 'disable' if !param_value + feature_enable = 'disable' unless param_value context "enable_autouninstaller => #{param_value}" do - let(:params) {{ :enable_autouninstaller => param_value }} + let(:params) { { enable_autouninstaller: param_value } } it { is_expected.not_to contain_exec("chocolatey_autouninstaller_#{feature_enable}") } @@ -56,19 +53,17 @@ end context 'with choco.exe installed' do - let(:facts) { - super().merge({ - :chocolateyversion => '0.9.9.8', - :choco_install_path => 'C:\ProgramData\chocolatey', - }) - } + let(:facts) do + super().merge(chocolateyversion: '0.9.9.8', + choco_install_path: 'C:\ProgramData\chocolatey') + end [true, false].each do |param_value| feature_enable = 'enable' - feature_enable = 'disable' if !param_value + feature_enable = 'disable' unless param_value context "enable_autouninstaller => #{param_value}" do - let(:params) {{ :enable_autouninstaller => param_value }} + let(:params) { { enable_autouninstaller: param_value } } it { is_expected.to contain_exec("chocolatey_autouninstaller_#{feature_enable}") } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 807bc758..f2aafa9b 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,24 +1,24 @@ require 'spec_helper' describe 'chocolatey' do - let(:facts) { + let(:facts) do { - :chocolateyversion => '0.9.9.8', - :choco_install_path => 'C:\ProgramData\chocolatey', - :path => 'C:\something', + chocolateyversion: '0.9.9.8', + choco_install_path: 'C:\ProgramData\chocolatey', + path: 'C:\something', } - } + end [{}].each do |params| - context "#{params}" do + context params.to_s do let(:params) { params } - it 'should compile successfully' do + it 'compiles successfully' do catalogue end - #it { is_expected.to compile } - #it { is_expected.to compile.with_all_deps } + # it { is_expected.to compile } + # it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('chocolatey') } it { is_expected.to contain_class('chocolatey::params') } it { is_expected.to contain_class('chocolatey::install') } @@ -26,44 +26,51 @@ end end - context "accepts install_proxy parameter" do - let(:params) {{ - :install_proxy => 'http://proxy.megacorp.com:3128', - }} + context 'accepts install_proxy parameter' do + let(:params) do + { + install_proxy: 'http://proxy.megacorp.com:3128', + } + end - it 'should compile successfully' do + it 'compiles successfully' do catalogue end end - context "chocolatey_download_url =>" do - ['https://chocolatey.org/api/v2/package/chocolatey/','http://location','file:///c:/somwhere/chocolatey.nupkg'].each do |param_value| - context "#{param_value}" do - let (:params) {{ - :chocolatey_download_url => param_value - }} + context 'chocolatey_download_url =>' do + ['https://chocolatey.org/api/v2/package/chocolatey/', 'http://location', 'file:///c:/somwhere/chocolatey.nupkg'].each do |param_value| + context param_value.to_s do + let(:params) do + { + chocolatey_download_url: param_value, + } + end - it 'should compile successfully' do + it 'compiles successfully' do catalogue end end end if Puppet.version < '4.0.0' - invalid_url_values = ['\\\\ciflocation\\share','bob',"4",'',3] + invalid_url_values = ['\\\\ciflocation\\share', 'bob', '4', '', 3] not_a_string_values = [false] else - invalid_url_values = ['\\\\ciflocation\\share','bob',"4",''] + invalid_url_values = ['\\\\ciflocation\\share', 'bob', '4', ''] not_a_string_values = [false, 3] end invalid_url_values.each do |param_value| context "#{param_value} (invalid scenario)" do - let (:params) {{ - :chocolatey_download_url => param_value - }} + let(:params) do + { + chocolatey_download_url: param_value, + } + end + + let(:error_message) { %r{use a Http\/Https\/File Url that downloads} } - let(:error_message) { /use a Http\/Https\/File Url that downloads/ } it { expect { catalogue }.to raise_error(Puppet::Error, error_message) } @@ -72,11 +79,14 @@ not_a_string_values.each do |param_value| context "#{param_value} (invalid scenario)" do - let (:params) {{ - :chocolatey_download_url => param_value - }} + let(:params) do + { + chocolatey_download_url: param_value, + } + end + + let(:error_message) { %r{is not a string} } - let(:error_message) { /is not a string/ } it { expect { catalogue }.to raise_error(Puppet::Error, error_message) } @@ -84,14 +94,16 @@ end end - context "choco_install_location =>" do - ['C:\\ProgramData\\chocolatey','D:\\somewhere'].each do |param_value| - context "#{param_value}" do - let (:params) {{ - :choco_install_location => param_value - }} + context 'choco_install_location =>' do + ['C:\\ProgramData\\chocolatey', 'D:\\somewhere'].each do |param_value| + context param_value.to_s do + let(:params) do + { + choco_install_location: param_value, + } + end - it 'should compile successfully' do + it 'compiles successfully' do catalogue end end @@ -100,51 +112,63 @@ if Puppet.version < '4.0.0' [false].each do |param_value| context "#{param_value} (invalid scenario)" do - let (:params) {{ - :choco_install_location => param_value - }} + let(:params) do + { + choco_install_location: param_value, + } + end + + let(:error_message) { %r{is not a string} } - let(:error_message) { /is not a string/ } it { expect { catalogue }.to raise_error(Puppet::Error, error_message) } end end - #1 is actually a string before v4. - [1,'https://somewhere','\\\\overhere',''].each do |param_value| + # 1 is actually a string before v4. + [1, 'https://somewhere', '\\\\overhere', ''].each do |param_value| context "#{param_value} (invalid scenario)" do - let (:params) {{ - :choco_install_location => param_value - }} + let(:params) do + { + choco_install_location: param_value, + } + end + + let(:error_message) { %r{Please use a full path for choco_install_location} } - let(:error_message) { /Please use a full path for choco_install_location/ } it { expect { catalogue }.to raise_error(Puppet::Error, error_message) } end end else - [1,false].each do |param_value| + [1, false].each do |param_value| context "#{param_value} (invalid scenario)" do - let (:params) {{ - :choco_install_location => param_value - }} + let(:params) do + { + choco_install_location: param_value, + } + end + + let(:error_message) { %r{is not a string} } - let(:error_message) { /is not a string/ } it { expect { catalogue }.to raise_error(Puppet::Error, error_message) } end end - ['https://somewhere','\\\\overhere',''].each do |param_value| + ['https://somewhere', '\\\\overhere', ''].each do |param_value| context "#{param_value} (invalid scenario)" do - let (:params) {{ - :choco_install_location => param_value - }} + let(:params) do + { + choco_install_location: param_value, + } + end + + let(:error_message) { %r{Please use a full path for choco_install_location} } - let(:error_message) { /Please use a full path for choco_install_location/ } it { expect { catalogue }.to raise_error(Puppet::Error, error_message) } @@ -153,26 +177,31 @@ end end - context "choco_install_timeout_seconds =>" do - [1500,8000,"1",'30'].each do |param_value| - context "#{param_value}" do - let (:params) {{ - :choco_install_timeout_seconds => param_value - }} + context 'choco_install_timeout_seconds =>' do + [1500, 8000, '1', '30'].each do |param_value| + context param_value.to_s do + let(:params) do + { + choco_install_timeout_seconds: param_value, + } + end - it 'should compile successfully' do + it 'compiles successfully' do catalogue end end end - ['string',false,''].each do |param_value| + ['string', false, ''].each do |param_value| context "#{param_value} (invalid scenario)" do - let (:params) {{ - :choco_install_timeout_seconds => param_value - }} + let(:params) do + { + choco_install_timeout_seconds: param_value, + } + end + + let(:error_message) { %r{Expected first argument to be an Integer} } - let(:error_message) { /Expected first argument to be an Integer/ } it { expect { catalogue }.to raise_error(Puppet::Error, error_message) } @@ -180,27 +209,32 @@ end end - ['use_7zip','enable_autouninstaller'].each do |boolean_param| + ['use_7zip', 'enable_autouninstaller'].each do |boolean_param| context "#{boolean_param} =>" do [true, false].each do |param_value| - context "#{param_value}" do - let (:params) {{ - boolean_param.to_sym => param_value - }} + context param_value.to_s do + let(:params) do + { + boolean_param.to_sym => param_value, + } + end - it 'should compile successfully' do + it 'compiles successfully' do catalogue end end end - ['true','false','bob',3,"4",''].each do |param_value| + ['true', 'false', 'bob', 3, '4', ''].each do |param_value| context "#{param_value} (invalid scenario)" do - let (:params) {{ - boolean_param.to_sym => param_value - }} + let(:params) do + { + boolean_param.to_sym => param_value, + } + end + + let(:error_message) { %r{is not a boolean.} } - let(:error_message) { /is not a boolean./ } it { expect { catalogue }.to raise_error(Puppet::Error, error_message) } diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index 248e4143..3617bedc 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -1,52 +1,55 @@ require 'spec_helper' RSpec.describe 'chocolatey' do - - let(:facts) { + let(:facts) do { - :chocolateyversion => '0.9.9.8', - :choco_install_path => 'C:\ProgramData\chocolatey', - :choco_temp_dir => 'C:\Temp', - :path => 'C:\something', + chocolateyversion: '0.9.9.8', + choco_install_path: 'C:\ProgramData\chocolatey', + choco_temp_dir: 'C:\Temp', + path: 'C:\something', } - } + end context 'contains install.pp' do - ['c:\local_folder', "C:\\ProgramData\\chocolatey"].each do |param_value| - context "choco_install_location => #{param_value}" do - let(:params) {{ :choco_install_location => param_value }} + ['c:\local_folder', 'C:\\ProgramData\\chocolatey'].each do |param_value| + context "choco_install_location => #{param_value}" do + let(:params) { { choco_install_location: param_value } } it { is_expected.to contain_exec('install_chocolatey_official').with_creates("#{param_value}\\bin\\choco.exe") } end end - [1500, 35].each do |param_value| context "choco_install_timeout_seconds => #{param_value}" do - let(:params) {{ :choco_install_timeout_seconds => param_value }} + let(:params) { { choco_install_timeout_seconds: param_value } } - it { is_expected.to contain_exec('install_chocolatey_official').with_timeout("#{param_value}") } + it { is_expected.to contain_exec('install_chocolatey_official').with_timeout(param_value.to_s) } end end - context "use_7zip => false" do - let(:params) {{ :use_7zip => false }} - it { + context 'use_7zip => false' do + let(:params) { { use_7zip: false } } + + it { is_expected.not_to contain_file('C:\Temp\7za.exe') } end - context "use_7zip => true" do - context "seven_zip_download_url default" do - let(:params) {{ :use_7zip => true }} - it { is_expected.to contain_file('C:\Temp\7za.exe').with_source('https://chocolatey.org/7za.exe')} + context 'use_7zip => true' do + context 'seven_zip_download_url default' do + let(:params) { { use_7zip: true } } + + it { is_expected.to contain_file('C:\Temp\7za.exe').with_source('https://chocolatey.org/7za.exe') } end context "seven_zip_download_url => 'https://packages.organization.net/7za.exe'" do - let(:params) {{ - :use_7zip => true, - :seven_zip_download_url => 'https://packages.organization.net/7za.exe' - }} - it { is_expected.to contain_file('C:\Temp\7za.exe').with_source('https://packages.organization.net/7za.exe')} + let(:params) do + { + use_7zip: true, + seven_zip_download_url: 'https://packages.organization.net/7za.exe', + } + end + + it { is_expected.to contain_file('C:\Temp\7za.exe').with_source('https://packages.organization.net/7za.exe') } end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0d5efc0b..3ac4f0da 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,7 +19,7 @@ next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin - default_facts.merge!(YAML.safe_load(File.read(f))) + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) rescue => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end @@ -37,6 +37,8 @@ end end +# Ensures that a module is defined +# @param module_name Name of the module def ensure_module_defined(module_name) module_name.split('::').reduce(Object) do |last_module, next_module| last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 06b2f35e..3da77e11 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -7,7 +7,7 @@ require 'beaker/ca_cert_helper' require 'beaker/testmode_switcher/dsl' -Dir["./spec/support/**/*.rb"].sort.each { |f| require f } +Dir['./spec/support/**/*.rb'].sort.each { |f| require f } run_puppet_install_helper configure_type_defaults_on(hosts) @@ -18,6 +18,6 @@ install_module_on(host) end -windows_agents.each do |agent| +windows_agents.each do |_agent| # rubocop:disable RSpec/IteratedExpectation install_chocolatey end diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index 28b71494..dd3762a2 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -3,22 +3,24 @@ # require 'rake' # require 'fileutils' -RSpec.configure do |c| +RSpec.configure do |_c| # set the environment variable before files are loaded, otherwise it is too late ENV['ChocolateyInstall'] = 'c:\blah' begin + # rubocop:disable RSpec/AnyInstance Win32::Registry.any_instance.stubs(:[]).with('Bind') Win32::Registry.any_instance.stubs(:[]).with('Domain') Win32::Registry.any_instance.stubs(:[]).with('ChocolateyInstall').raises(Win32::Registry::Error.new(2), 'file not found yo') - rescue - # we don't care + # rubocop:enable RSpec/AnyInstance + rescue # rubocop:disable Lint/HandleExceptions: + # ignore errors thrown while setting up mocks end end # We need this because the RAL uses 'should' as a method. This # allows us the same behaviour but with a different method name. class Object - alias :must :should - alias :must_not :should_not + alias must should + alias must_not should_not end diff --git a/spec/support/examples/failing_manifest.rb b/spec/support/examples/failing_manifest.rb index 375970f1..ac699ea2 100644 --- a/spec/support/examples/failing_manifest.rb +++ b/spec/support/examples/failing_manifest.rb @@ -1,12 +1,9 @@ shared_examples 'a failing manifest' do |manifest, expected_error| - windows_agents.each do |agent| - - it 'Should fail to apply a bad manifest' do - execute_manifest_on(agent, manifest, :expect_failures => true) do - assert_match(expected_error, stderr, "stderr did not match expected error") + it 'fails to apply a bad manifest' do + execute_manifest_on(agent, manifest, expect_failures: true) do + assert_match(expected_error, stderr, 'stderr did not match expected error') end end end end - diff --git a/spec/support/examples/manifest_removes_value.rb b/spec/support/examples/manifest_removes_value.rb index 24a97907..a49f9904 100644 --- a/spec/support/examples/manifest_removes_value.rb +++ b/spec/support/examples/manifest_removes_value.rb @@ -1,15 +1,13 @@ shared_examples 'a manifest that removes a config value' do |manifest, key| - windows_agents.each do |agent| - it 'should apply the manifest that removes the value' do - execute_manifest_on(agent, manifest, :catch_failures => true) + it 'applies the manifest that removes the value' do + execute_manifest_on(agent, manifest, catch_failures: true) end - it 'should validate the key has been removed' do + it 'validates the key has been removed' do on(agent, config_content_command) do |result| - assert_not_match(/.+/, get_xml_value("//config/add[@key='#{key}']/@value", result.output).to_s, 'Value should have been removed') + assert_not_match(%r{.+}, get_xml_value("//config/add[@key='#{key}']/@value", result.output).to_s, 'Value should have been removed') end end end end - diff --git a/spec/support/examples/password_value_should_be.rb b/spec/support/examples/password_value_should_be.rb index 70c83828..42aaf8f8 100644 --- a/spec/support/examples/password_value_should_be.rb +++ b/spec/support/examples/password_value_should_be.rb @@ -1,21 +1,20 @@ shared_examples 'a password that doesn\'t change' do |manifest, modify_manfiest, key| - password = '' - + windows_agents.each do |agent| # Should apply the password here. # 'password' variable is set to the password hash value. - it 'Should apply the manifest to set the password' do - execute_manifest_on(agent, manifest, :catch_failures => true) + it 'applies the manifest to set the password' do + execute_manifest_on(agent, manifest, catch_failures: true) on(agent, config_content_command) do |result| password = get_xml_value("//config/add[@key='#{key}']/@value", result.output).to_s - assert_match(/.+/, password, 'Value did not match') + assert_match(%r{.+}, password, 'Value did not match') end end - it 'should validate the value' do + it 'validates the value' do # Apply a manifest with a modified password value - execute_manifest_on(agent, modify_manfiest, :catch_failures => true) + execute_manifest_on(agent, modify_manfiest, catch_failures: true) on(agent, config_content_command) do |result| # Verify here that the hash value in the config did not change. assert_match(password, get_xml_value("//config/add[@key='#{key}']/@value", result.output).to_s, 'Value should not have changed') @@ -23,4 +22,3 @@ end end end - diff --git a/spec/support/examples/successful_config_change.rb b/spec/support/examples/successful_config_change.rb index 9380ce3d..2692e72b 100644 --- a/spec/support/examples/successful_config_change.rb +++ b/spec/support/examples/successful_config_change.rb @@ -1,16 +1,13 @@ shared_examples 'a successful config change' do |manifest, key, expected_value| - windows_agents.each do |agent| - - it 'Should apply the config manifest' do - execute_manifest_on(agent, manifest, :catch_failures => true) + it 'applies the config manifest' do + execute_manifest_on(agent, manifest, catch_failures: true) end - it 'should validate the value' do + it 'validates the value' do on(agent, config_content_command) do |result| assert_match(expected_value, get_xml_value("//config/add[@key='#{key}']/@value", result.output).to_s, 'Value did not match') end end end end - diff --git a/spec/support/utilities/helpers.rb b/spec/support/utilities/helpers.rb index f705fb64..c382406f 100644 --- a/spec/support/utilities/helpers.rb +++ b/spec/support/utilities/helpers.rb @@ -1,6 +1,6 @@ -CHOCOLATEY_LATEST_INFO_URL = "https://artifactory.delivery.puppetlabs.net/artifactory/api/nuget/choco-pipeline-tests/Packages()?$filter=((Id%20eq%20%27chocolatey%27)%20and%20(not%20IsPrerelease))%20and%20IsLatestVersion" +CHOCOLATEY_LATEST_INFO_URL = 'https://artifactory.delivery.puppetlabs.net/artifactory/api/nuget/choco-pipeline-tests/Packages()?$filter=((Id%20eq%20%27chocolatey%27)%20and%20(not%20IsPrerelease))%20and%20IsLatestVersion'.freeze -def get_latest_chocholatey_download_url +def latest_chocholatey_download_url uri = URI.parse(CHOCOLATEY_LATEST_INFO_URL) response = Net::HTTP.get_response(uri) @@ -8,7 +8,7 @@ def get_latest_chocholatey_download_url src_url = xml_str.css('//feed//content').attr('src') - return src_url + src_url end def install_chocolatey @@ -19,26 +19,25 @@ class {'chocolatey': } MANIFEST - chocoVersion = /[0-9]+[\d'.']*/ + choco_version = %r{[0-9]+[\d'.']*} windows_agents.each do |agent| opts = { - :acceptable_exit_codes => [0, 2] + acceptable_exit_codes: [0, 2], } - curl_on(agent, "--cacert 'C:/Program Files/Puppet Labs/Puppet/puppet/ssl/cert.pem' #{get_latest_chocholatey_download_url} > C:/chocolatey.nupkg") + curl_on(agent, "--cacert 'C:/Program Files/Puppet Labs/Puppet/puppet/ssl/cert.pem' #{latest_chocholatey_download_url} > C:/chocolatey.nupkg") execute_manifest_on(agent, chocolatey_pp, opts) do |result| - assert_no_match(/Error:/, result.stderr, 'Unexpected error was detected!') + assert_no_match(%r{Error:}, result.stderr, 'Unexpected error was detected!') end - on(agent, 'C:/ProgramData/chocolatey/bin/choco.exe -v', :acceptable_exit_codes => 0) do |result| - assert_match(chocoVersion, result.stdout, 'Expected: ' + chocoVersion.to_s + ' but got ' + result.stdout) + on(agent, 'C:/ProgramData/chocolatey/bin/choco.exe -v', acceptable_exit_codes: 0) do |result| + assert_match(choco_version, result.stdout, 'Expected: ' + choco_version.to_s + ' but got ' + result.stdout) end end end - def windows_agents agents.select { |agent| agent['platform'].include?('windows') } end @@ -55,7 +54,7 @@ def backup_config } COMMAND - execute_powershell_script_on(agent, backup_command, :catch_failures => true) + execute_powershell_script_on(agent, backup_command, catch_failures: true) end end @@ -67,7 +66,7 @@ def reset_config } COMMAND - execute_powershell_script_on(agent, backup_command, :catch_failures => true) + execute_powershell_script_on(agent, backup_command, catch_failures: true) end end @@ -80,4 +79,3 @@ def get_xml_value(xpath, file_text) def config_content_command "cmd.exe /c \"type #{config_file_location}\"" end - diff --git a/spec/unit/facter/choco_install_path_spec.rb b/spec/unit/facter/choco_install_path_spec.rb index 8d5a24e1..1927aa5b 100644 --- a/spec/unit/facter/choco_install_path_spec.rb +++ b/spec/unit/facter/choco_install_path_spec.rb @@ -5,24 +5,26 @@ describe 'choco_install_path fact' do subject(:fact) { Facter.fact(:choco_install_path) } + let(:fact_value) { subject.value } + before :each do - skip ('Not on Windows platform') unless Puppet::Util::Platform.windows? + skip 'Not on Windows platform' unless Puppet::Util::Platform.windows? Facter.clear Facter.clear_messages end - context "on Windows" do - it "should return the output of PuppetX::Chocolatey::ChocolateyInstall.install_path" do + context 'on Windows' do + it 'returns the output of PuppetX::Chocolatey::ChocolateyInstall.install_path' do expected_value = 'C:\somewhere' PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns(expected_value) - subject.value.must == expected_value + fact_value.must == expected_value end - it "should return the default path when PuppetX::Chocolatey::ChocolateyInstall.install_path is nil" do + it 'returns the default path when PuppetX::Chocolatey::ChocolateyInstall.install_path is nil' do PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns(nil) - subject.value.must == 'C:\ProgramData\chocolatey' + fact_value.must == 'C:\ProgramData\chocolatey' end end diff --git a/spec/unit/facter/choco_temp_dir.rb b/spec/unit/facter/choco_temp_dir.rb index f7c3ae57..289e788b 100644 --- a/spec/unit/facter/choco_temp_dir.rb +++ b/spec/unit/facter/choco_temp_dir.rb @@ -5,25 +5,26 @@ describe 'choco_temp_dir fact' do subject(:fact) { Facter.fact(:choco_temp_dir) } + let(:fact_value) { subject.value } + before :each do - skip ('Not on Windows platform') unless Puppet::Util::Platform.windows? + skip 'Not on Windows platform' unless Puppet::Util::Platform.windows? Facter.clear Facter.clear_messages end - it "should return the TEMP directory" do + it 'returns the TEMP directory' do expected_value = 'waffles' PuppetX::Chocolatey::ChocolateyInstall.expects(:temp_dir).returns(expected_value) - subject.value.must == expected_value + fact_value.must == expected_value end - it "should return the default path when PuppetX::Chocolatey::ChocolateyInstall.install_path is nil" do + it 'returns the default path when PuppetX::Chocolatey::ChocolateyInstall.install_path is nil' do PuppetX::Chocolatey::ChocolateyInstall.expects(:temp_dir).returns(nil) - subject.value.must == ENV['TEMP'] + fact_value.must == ENV['TEMP'] end - after :each do Facter.clear Facter.clear_messages diff --git a/spec/unit/facter/chocolateyversion_spec.rb b/spec/unit/facter/chocolateyversion_spec.rb index 29e07ebe..4f3ea749 100644 --- a/spec/unit/facter/chocolateyversion_spec.rb +++ b/spec/unit/facter/chocolateyversion_spec.rb @@ -5,25 +5,26 @@ describe 'chocolateyversion fact' do subject(:fact) { Facter.fact(:chocolateyversion) } + let(:fact_value) { subject.value } + before :each do - skip ('Not on Windows platform') unless Puppet::Util::Platform.windows? + skip 'Not on Windows platform' unless Puppet::Util::Platform.windows? Facter.clear Facter.clear_messages end - context "on Windows" do - - it "should return the output of PuppetX::Chocolatey::ChocolateyVersion.version" do + context 'on Windows' do + it 'returns the output of PuppetX::Chocolatey::ChocolateyVersion.version' do expected_value = '1.2.3' PuppetX::Chocolatey::ChocolateyVersion.expects(:version).returns(expected_value) - subject.value.must == expected_value + fact_value.must == expected_value end - it "should return the default of 0 when PuppetX::Chocolatey::ChocolateyVersion.version is nil" do + it 'returns the default of 0 when PuppetX::Chocolatey::ChocolateyVersion.version is nil' do PuppetX::Chocolatey::ChocolateyVersion.expects(:version).returns(nil) - subject.value.must == '0' + fact_value.must == '0' end end diff --git a/spec/unit/puppet/provider/chocolateyconfig/windows_spec.rb b/spec/unit/puppet/provider/chocolateyconfig/windows_spec.rb index 74dabc00..46ffeba2 100644 --- a/spec/unit/puppet/provider/chocolateyconfig/windows_spec.rb +++ b/spec/unit/puppet/provider/chocolateyconfig/windows_spec.rb @@ -6,11 +6,12 @@ provider = Puppet::Type.type(:chocolateyconfig).provider(:windows) describe provider do - let (:name) { 'configItem' } - let (:resource) { Puppet::Type.type(:chocolateyconfig).new(:provider => :windows, :name => name, :value => "yes") } - let (:choco_config) { 'c:\choco.config' } - let (:choco_install_path) { 'c:\dude\bin\choco.exe' } - let (:choco_config_contents) { <<-'EOT' + let(:name) { 'configItem' } + let(:resource) { Puppet::Type.type(:chocolateyconfig).new(provider: :windows, name: name, value: 'yes') } + let(:choco_config) { 'c:\choco.config' } + let(:choco_install_path) { 'c:\dude\bin\choco.exe' } + let(:choco_config_contents) do + <<-EOT @@ -52,92 +53,93 @@ EOT - } - + end - let (:minimum_supported_version) {'0.9.10.0'} - let (:last_unsupported_version) {'0.9.9.12'} + let(:minimum_supported_version) { '0.9.10.0' } + let(:last_unsupported_version) { '0.9.9.12' } + let(:provider_class) { subject.class } + let(:provider) { subject.class.new(resource) } before :each do PuppetX::Chocolatey::ChocolateyInstall.stubs(:install_path).returns('c:\dude') PuppetX::Chocolatey::ChocolateyCommon.stubs(:choco_version).returns(minimum_supported_version) - @provider = provider.new(resource) - resource.provider = @provider + provider = provider_class.new(resource) + resource.provider = provider # Stub all file and config tests - provider.stubs(:healthcheck) + provider_class.stubs(:healthcheck) end - context "verify provider" do - it "should be an instance of Puppet::Type::Chocolateyconfig::ProviderWindows" do - @provider.must be_an_instance_of Puppet::Type::Chocolateyconfig::ProviderWindows + context 'verify provider' do + it 'is an instance of Puppet::Type::Chocolateyconfig::ProviderWindows' do + provider.must be_an_instance_of Puppet::Type::Chocolateyconfig::ProviderWindows end - it "should have a create method" do - @provider.should respond_to(:create) + it 'has a create method' do + provider.should respond_to(:create) end - it "should have an exists? method" do - @provider.should respond_to(:exists?) + it 'has an exists? method' do + provider.should respond_to(:exists?) end - it "should have a destroy method" do - @provider.should respond_to(:destroy) + it 'has a destroy method' do + provider.should respond_to(:destroy) end - it "should have a properties method" do - @provider.should respond_to(:properties) + it 'has a properties method' do + provider.should respond_to(:properties) end - it "should have a query method" do - @provider.should respond_to(:query) + it 'has a query method' do + provider.should respond_to(:query) end end - context "properties" do - context ":value" do - #it "should default to nil" do + context 'properties' do + context ':value' do + # it "should default to nil" do # resource[:value].should be_nil - #end + # end - it "should accept c:\\cache" do + it 'accepts c:\\cache' do resource[:value] = 'c:\cache' end - it "should accept 2700" do + it 'accepts 2700' do resource[:value] = '2700' end - it "should accept 'value with spaces'" do + it "accepts 'value with spaces'" do resource[:value] = 'value with spaces' end end end - context "self.get_configs" do + context 'self.read_configs' do before :each do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) end - it "should error when the config file location is null" do + it 'errors when the config file location is null' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(nil) expect { - provider.get_configs - }.to raise_error(Puppet::ResourceError, /Config file not found for Chocolatey/) + provider_class.read_configs + }.to raise_error(Puppet::ResourceError, %r{Config file not found for Chocolatey}) end - it "should error when the config file is not found" do + it 'errors when the config file is not found' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(false) expect { - provider.get_configs - }.to raise_error(Puppet::ResourceError, /was unable to locate config file at/) + provider_class.read_configs + }.to raise_error(Puppet::ResourceError, %r{was unable to locate config file at}) end - context "when getting configs from the config file" do + context 'when getting configs from the config file' do configs = [] before :each do @@ -145,39 +147,38 @@ PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents - configs = provider.get_configs + configs = provider_class.read_configs end - it "should match the count of configs in the config" do + it 'matches the count of configs in the config' do configs.count.must eq 11 - end - it "should contain xml elements" do + it 'contains xml elements' do configs[0].must be_an_instance_of REXML::Element end end end - context "self.get_config" do - let (:element) { REXML::Element.new('add') } - element_key = "cacheLocation" - element_value= "c:\\cache" - element_description = "Cache location if not TEMP folder." + context 'self.get_config' do + let(:element) { REXML::Element.new('add') } + + element_key = 'cacheLocation' + element_value = 'c:\\cache' + element_description = 'Cache location if not TEMP folder.' before :each do - element.add_attributes( { "key" => element_key, - "value" => element_value, - "description" => element_description, - } ) + element.add_attributes('key' => element_key, + 'value' => element_value, + 'description' => element_description) end - it "should return nil config when element is nil" do - provider.get_config(nil).must be == {} + it 'returns nil config when element is nil' do + provider_class.get_config(nil).must be == {} end - it "should convert an element to a config" do - config = provider.get_config(element) + it 'converts an element to a config' do + config = provider_class.get_config(element) config[:name].must eq element_key config[:value].must eq element_value @@ -186,8 +187,8 @@ end end - context ".validation" do - it "should not error when Chocolatey is not installed" do + context '.validation' do + it 'does not error when Chocolatey is not installed' do PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).returns(false).at_least(0) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_install_path).returns(false).at_least(0) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns('') @@ -195,7 +196,7 @@ resource.provider.validate end - it "should not error when the minimum version is met" do + it 'does not error when the minimum version is met' do PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).returns(false).at_least(0) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_install_path).returns(true).at_least(0) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version) @@ -203,43 +204,43 @@ resource.provider.validate end - it "should error when the minimum version is not met" do + it 'errors when the minimum version is not met' do PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).returns(true).at_least(0) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version) expect { resource.provider.validate - }.to raise_error(Puppet::ResourceError, /Chocolatey version must be '0.9.10.0' to manage configuration values. Detected '#{last_unsupported_version}'/) + }.to raise_error(Puppet::ResourceError, %r{Chocolatey version must be '0.9.10.0' to manage configuration values. Detected '#{last_unsupported_version}'}) end - it "should error when the property_hash is empty, :ensure is :present, and no :value is supplied" do + it 'errors when the property_hash is empty, :ensure is :present, and no :value is supplied' do resource.delete(:value) expect { resource.provider.validate - }.to raise_error(ArgumentError, "Unless ensure => absent, value is required.") + }.to raise_error(ArgumentError, 'Unless ensure => absent, value is required.') end - it "should not error when the property_hash is defined, even if :ensure is :present and no :value is supplied" do + it 'does not error when the property_hash is defined, even if :ensure is :present and no :value is supplied' do resource.delete(:value) - resource.provider.instance_variable_set("@property_hash", {:value => "something"}) + resource.provider.instance_variable_set('@property_hash', value: 'something') resource.provider.validate end - it "should not error when the property_hash is empty, :ensure is :present and a :value is supplied" do + it 'does not error when the property_hash is empty, :ensure is :present and a :value is supplied' do resource.provider.validate end - it "should not error when the property_hash is empty, :ensure is :absent and no :value is supplied" do + it 'does not error when the property_hash is empty, :ensure is :absent and no :value is supplied' do resource[:ensure] = :absent resource.delete(:value) resource.provider.validate end end - context ".flush" do - resource_name = "yup" - resource_value = "this" + context '.flush' do + resource_name = 'yup' + resource_value = 'this' resource_ensure = :present before :each do @@ -253,40 +254,35 @@ resource[:ensure] = resource_ensure end - it "should ensure a config setting is set" do - PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + it 'ensures a config setting is set' do + # PuppetX::Chocolatey::ChocolateyCommon.allow(:choco_version).returns(minimum_supported_version) + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'config', 'set', '--name', resource_name, - '--value', resource_value - ]) + '--value', resource_value]) resource.flush end - it "should ensure a config setting is removed" do + it 'ensures a config setting is removed' do resource.provider.destroy - PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + # PuppetX::Chocolatey::ChocolateyCommon.allow(:choco_version).returns(minimum_supported_version) + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'config', 'unset', - '--name', resource_name - ]) + '--name', resource_name]) resource.flush end - it "should provide an error message when choco execution fails" do - PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + it 'provides an error message when choco execution fails' do + # PuppetX::Chocolatey::ChocolateyCommon.allow(:choco_version).returns(minimum_supported_version) + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'config', 'set', '--name', resource_name, - '--value', resource_value - ]).raises(Puppet::ExecutionFailure, "Nooooo") + '--value', resource_value]).raises(Puppet::ExecutionFailure, 'Nooooo') - expect { resource.flush }.to raise_error(Puppet::Error, /Unable to set Chocolateyconfig/) + expect { resource.flush }.to raise_error(Puppet::Error, %r{Unable to set Chocolateyconfig}) end - - end end diff --git a/spec/unit/puppet/provider/chocolateyfeature/windows_spec.rb b/spec/unit/puppet/provider/chocolateyfeature/windows_spec.rb index 88577ee2..e0f4e1c5 100644 --- a/spec/unit/puppet/provider/chocolateyfeature/windows_spec.rb +++ b/spec/unit/puppet/provider/chocolateyfeature/windows_spec.rb @@ -6,11 +6,12 @@ provider = Puppet::Type.type(:chocolateyfeature).provider(:windows) describe provider do - let (:name) { 'allowglobalconfirmation' } - let (:resource) { Puppet::Type.type(:chocolateyfeature).new(:provider => :windows, :name => name, :ensure => 'enabled' ) } - let (:choco_config) { 'c:\choco.config' } - let (:choco_install_path) { 'c:\dude\bin\choco.exe' } - let (:choco_config_contents) { <<-'EOT' + let(:name) { 'allowglobalconfirmation' } + let(:resource) { Puppet::Type.type(:chocolateyfeature).new(provider: :windows, name: name, ensure: 'enabled') } + let(:choco_config) { 'c:\choco.config' } + let(:choco_install_path) { 'c:\dude\bin\choco.exe' } + let(:choco_config_contents) do + <<-'EOT' @@ -52,80 +53,80 @@ EOT - } + end - let (:minimum_supported_version) {'0.9.9.0'} + let(:minimum_supported_version) { '0.9.9.0' } + let(:provider_class) { subject.class } + let(:provider) { subject.class.new(resource) } before :each do PuppetX::Chocolatey::ChocolateyInstall.stubs(:install_path).returns('c:\dude') PuppetX::Chocolatey::ChocolateyCommon.stubs(:choco_version).returns(minimum_supported_version) - @provider = provider.new(resource) - resource.provider = @provider + provider = provider_class.new(resource) + resource.provider = provider # Stub all file and config tests - provider.stubs(:healthcheck) + provider_class.stubs(:healthcheck) end - context "verify provider" do - it "should be an instance of Puppet::Type::Chocolateyfeature::ProviderWindows" do - - @provider.must be_an_instance_of Puppet::Type::Chocolateyfeature::ProviderWindows + context 'verify provider' do + it 'is an instance of Puppet::Type::Chocolateyfeature::ProviderWindows' do + provider.must be_an_instance_of Puppet::Type::Chocolateyfeature::ProviderWindows end - it "should have a enable method" do - @provider.should respond_to(:enable) + it 'has a enable method' do + provider.should respond_to(:enable) end - it "should have an exists? method" do - @provider.should respond_to(:exists?) + it 'has an exists? method' do + provider.should respond_to(:exists?) end - it "should have a disable method" do - @provider.should respond_to(:disable) + it 'has a disable method' do + provider.should respond_to(:disable) end - it "should have a properties method" do - @provider.should respond_to(:properties) + it 'has a properties method' do + provider.should respond_to(:properties) end - it "should have a query method" do - @provider.should respond_to(:query) + it 'has a query method' do + provider.should respond_to(:query) end - it "should have the standard feautures method" do - @provider.should respond_to(:features) + it 'has the standard feautures method' do + provider.should respond_to(:features) end - it "should return nil feature when element is nil" do + it 'returns nil feature when element is nil' do provider.features.must be == [] end - end - context "self.get_choco_features" do + context 'self.read_choco_features' do before :each do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) end - it "should error when the config file location is null" do + it 'errors when the config file location is null' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(nil) expect { - provider.get_choco_features - }.to raise_error(Puppet::ResourceError, /Config file not found for Chocolatey/) + provider_class.read_choco_features + }.to raise_error(Puppet::ResourceError, %r{Config file not found for Chocolatey}) end - it "should error when the config file is not found" do + it 'errors when the config file is not found' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(false) expect { - provider.get_choco_features - }.to raise_error(Puppet::ResourceError, /was unable to locate config file at/) + provider_class.read_choco_features + }.to raise_error(Puppet::ResourceError, %r{was unable to locate config file at}) end - context "when getting features from the config file" do + context 'when getting features from the config file' do features = [] before :each do @@ -133,47 +134,46 @@ PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents - features = provider.get_choco_features + features = provider_class.read_choco_features end - it "should match the count of features in the config" do + it 'matches the count of features in the config' do features.count.must eq 14 - end - it "should contain xml elements" do + it 'contains xml elements' do features[0].must be_an_instance_of REXML::Element end end end - context "self.get_choco_feature" do - let (:element) { REXML::Element.new('feature') } - element_name = "default" + context 'self.get_choco_feature' do + let(:element) { REXML::Element.new('feature') } + + element_name = 'default' element_enabled = 'true' before :each do - element.add_attributes( { "name" => element_name, "enabled" => element_enabled, } ) + element.add_attributes('name' => element_name, 'enabled' => element_enabled) end - it "should return nil feature when element is nil" do - provider.get_choco_feature(nil).must be == {} + it 'returns nil feature when element is nil' do + provider_class.get_choco_feature(nil).must be == {} end - it "should convert an element to a feature" do - feature = provider.get_choco_feature(element) + it 'converts an element to a feature' do + feature = provider_class.get_choco_feature(element) feature[:name].must eq element_name feature[:ensure].must eq :enabled end - it "when feature is disabled" do + it 'when feature is disabled' do element.delete_attribute('enabled') element.add_attribute('enabled', 'false') - feature = provider.get_choco_feature(element) + feature = provider_class.get_choco_feature(element) feature[:ensure].must eq :disabled end end - end diff --git a/spec/unit/puppet/provider/chocolateysource/windows_spec.rb b/spec/unit/puppet/provider/chocolateysource/windows_spec.rb index 36b23fe5..8bd1583a 100644 --- a/spec/unit/puppet/provider/chocolateysource/windows_spec.rb +++ b/spec/unit/puppet/provider/chocolateysource/windows_spec.rb @@ -6,12 +6,13 @@ provider = Puppet::Type.type(:chocolateysource).provider(:windows) describe provider do - let (:name) { 'sourcename' } - let (:location) { 'c:\packages' } - let (:resource) { Puppet::Type.type(:chocolateysource).new(:provider => :windows, :name => name, :location => location) } - let (:choco_config) { 'c:\choco.config' } - let (:choco_install_path) { 'c:\dude\bin\choco.exe' } - let (:choco_config_contents) { <<-'EOT' + let(:name) { 'sourcename' } + let(:location) { 'c:\packages' } + let(:resource) { Puppet::Type.type(:chocolateysource).new(provider: :windows, name: name, location: location) } + let(:choco_config) { 'c:\choco.config' } + let(:choco_install_path) { 'c:\dude\bin\choco.exe' } + let(:choco_config_contents) do + <<-'EOT' @@ -53,153 +54,153 @@ EOT - } - - let (:newer_choco_version) {'0.10.9'} - let (:minimum_supported_version_priority) {'0.9.9.9'} - let (:last_unsupported_version_priority) {'0.9.9.8'} - let (:minimum_supported_version_bypass_proxy) {'0.10.4'} - let (:last_unsupported_version_bypass_proxy) {'0.10.3'} - let (:minimum_supported_version_allow_self_service) {'0.10.4'} - let (:last_unsupported_version_allow_self_service) {'0.10.3'} - let (:minimum_supported_version_admin_only) {'0.10.8'} - let (:last_unsupported_version_admin_only) {'0.10.7'} - let (:minimum_supported_version) {'0.9.9.0'} - let (:last_unsupported_version) {'0.9.8.33'} + end + + let(:newer_choco_version) { '0.10.9' } + let(:minimum_supported_version_priority) { '0.9.9.9' } + let(:last_unsupported_version_priority) { '0.9.9.8' } + let(:minimum_supported_version_bypass_proxy) { '0.10.4' } + let(:last_unsupported_version_bypass_proxy) { '0.10.3' } + let(:minimum_supported_version_allow_self_service) { '0.10.4' } + let(:last_unsupported_version_allow_self_service) { '0.10.3' } + let(:minimum_supported_version_admin_only) { '0.10.8' } + let(:last_unsupported_version_admin_only) { '0.10.7' } + let(:minimum_supported_version) { '0.9.9.0' } + let(:last_unsupported_version) { '0.9.8.33' } + let(:provider_class) { subject.class } + let(:provider) { subject.class.new(resource) } before :each do PuppetX::Chocolatey::ChocolateyInstall.stubs(:install_path).returns('c:\dude') PuppetX::Chocolatey::ChocolateyCommon.stubs(:choco_version).returns(minimum_supported_version) - @provider = provider.new(resource) - resource.provider = @provider + provider = provider_class.new(resource) + resource.provider = provider # Stub all file and config tests - provider.stubs(:healthcheck) + provider_class.stubs(:healthcheck) end - context "verify provider" do - it "should be an instance of Puppet::Type::Chocolateysource::ProviderWindows" do - - @provider.must be_an_instance_of Puppet::Type::Chocolateysource::ProviderWindows + context 'verify provider' do + it 'is an instance of Puppet::Type::Chocolateysource::ProviderWindows' do + provider.must be_an_instance_of Puppet::Type::Chocolateysource::ProviderWindows end - it "should have a create method" do - @provider.should respond_to(:create) + it 'has a create method' do + provider.should respond_to(:create) end - it "should have an exists? method" do - @provider.should respond_to(:exists?) + it 'has an exists? method' do + provider.should respond_to(:exists?) end - it "should have a disable method" do - @provider.should respond_to(:disable) + it 'has a disable method' do + provider.should respond_to(:disable) end - it "should have a destroy method" do - @provider.should respond_to(:destroy) + it 'has a destroy method' do + provider.should respond_to(:destroy) end - it "should have a properties method" do - @provider.should respond_to(:properties) + it 'has a properties method' do + provider.should respond_to(:properties) end - it "should have a query method" do - @provider.should respond_to(:query) + it 'has a query method' do + provider.should respond_to(:query) end end - context "properties" do - - context ":location" do - it "should accept c:\\packages" do + context 'properties' do + context ':location' do + it 'accepts c:\\packages' do resource[:location] = 'c:\packages' end - it "should accept http://somelocation/packages" do + it 'accepts http://somelocation/packages' do resource[:location] = 'http://somelocation/packages' end - it "should accept \\\\unc\\share\\packages" do + it 'accepts \\\\unc\\share\\packages' do resource[:location] = '\\unc\share\packages' end end - context ":user" do - it "should accept 'bob'" do + context ':user' do + it "accepts 'bob'" do resource[:user] = 'bob' end - it "should accept 'domain\\bob'" do + it "accepts 'domain\\bob'" do resource[:user] = 'domain\bob' end - it "should accept api keys like 'api123-456-243 d123'" do + it "accepts api keys like 'api123-456-243 d123'" do resource[:user] = 'api123-456-243 d123' end end - context ":password" do - it "should accept 'bob'" do + context ':password' do + it "accepts 'bob'" do resource[:password] = 'bob' end - it "should accept api keys like 'api123-456-243 d123'" do + it "accepts api keys like 'api123-456-243 d123'" do resource[:password] = 'api123-456-243 d123' end end - context ":bypass_proxy" do - it "should accept 'true' as a string" do + context ':bypass_proxy' do + it "accepts 'true' as a string" do resource[:bypass_proxy] = 'true' end - it "should accept 'true as a boolean'" do + it "accepts 'true as a boolean'" do resource[:bypass_proxy] = true end end - context ":allow_self_service" do - it "should accept 'true' as a string" do + context ':allow_self_service' do + it "accepts 'true' as a string" do resource[:allow_self_service] = 'true' end - it "should accept 'true as a boolean'" do + it "accepts 'true as a boolean'" do resource[:allow_self_service] = true end end - context ":admin_only" do - it "should accept 'true' as a string" do + context ':admin_only' do + it "accepts 'true' as a string" do resource[:admin_only] = 'true' end - it "should accept 'true as a boolean'" do + it "accepts 'true as a boolean'" do resource[:admin_only] = true end end end - context "self.get_sources" do + context 'self.read_sources' do before :each do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) end - it "should error when the config file location is null" do + it 'errors when the config file location is null' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(nil) expect { - provider.get_sources - }.to raise_error(Puppet::ResourceError, /Config file not found for Chocolatey/) + provider_class.read_sources + }.to raise_error(Puppet::ResourceError, %r{Config file not found for Chocolatey}) end - it "should error when the config file is not found" do + it 'errors when the config file is not found' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(false) expect { - provider.get_sources - }.to raise_error(Puppet::ResourceError, /was unable to locate config file at/) + provider_class.read_sources + }.to raise_error(Puppet::ResourceError, %r{was unable to locate config file at}) end - context "when getting sources from the config file" do + context 'when getting sources from the config file' do sources = [] before :each do @@ -207,51 +208,50 @@ PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents - sources = provider.get_sources + sources = provider_class.read_sources end - it "should match the count of sources in the config" do + it 'matches the count of sources in the config' do sources.count.must eq 3 - end - it "should contain xml elements" do + it 'contains xml elements' do sources[0].must be_an_instance_of REXML::Element end end end - context "self.get_source" do - let (:element) { REXML::Element.new('source') } - element_id = "default" - element_value= "c:\\packages" - element_disabled = "false" - element_priority = "10" - element_user = "thisguy" - element_password = "super/encrypted+value==" - element_bypass_proxy = "true" - element_allow_self_service = "true" - element_admin_only = "true" + context 'self.get_source' do + let(:element) { REXML::Element.new('source') } + + element_id = 'default' + element_value = 'c:\\packages' + element_disabled = 'false' + element_priority = '10' + element_user = 'thisguy' + element_password = 'super/encrypted+value==' + element_bypass_proxy = 'true' + element_allow_self_service = 'true' + element_admin_only = 'true' before :each do - element.add_attributes( { "id" => element_id, - "value" => element_value, - "disabled" => element_disabled, - "priority" => element_priority, - "user" => element_user, - "password" => element_password, - "bypassProxy" => element_bypass_proxy, - "selfService" => element_allow_self_service, - "adminOnly" => element_admin_only, - } ) + element.add_attributes('id' => element_id, + 'value' => element_value, + 'disabled' => element_disabled, + 'priority' => element_priority, + 'user' => element_user, + 'password' => element_password, + 'bypassProxy' => element_bypass_proxy, + 'selfService' => element_allow_self_service, + 'adminOnly' => element_admin_only) end - it "should return nil source when element it nil" do - provider.get_source(nil).must be == {} + it 'returns nil source when element it nil' do + provider_class.get_source(nil).must be == {} end - it "should convert an element to a source" do - source = provider.get_source(element) + it 'converts an element to a source' do + source = provider_class.get_source(element) source[:name].must eq element_id source[:location].must eq element_value @@ -263,7 +263,7 @@ source[:admin_only].must eq element_admin_only end - it "should convert a bare bones element to a source" do + it 'converts a bare bones element to a source' do element.delete_attribute('disabled') element.delete_attribute('priority') element.delete_attribute('user') @@ -272,29 +272,29 @@ element.delete_attribute('selfService') element.delete_attribute('adminOnly') - source = provider.get_source(element) + source = provider_class.get_source(element) source[:name].must eq element_id source[:location].must eq element_value source[:ensure].must eq :present end - it "when source is disabled" do + it 'when source is disabled' do element.delete_attribute('disabled') element.add_attribute('disabled', 'true') - source = provider.get_source(element) + source = provider_class.get_source(element) source[:ensure].must eq :disabled end end - context ".validation" do + context '.validation' do before :each do PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).returns(true).at_least(0) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_install_path).returns(true).at_least(0) end - it "should not warn when both user/password are empty" do + it 'does not warn when both user/password are empty' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version) Puppet.expects(:warning).never Puppet.expects(:debug).never @@ -302,26 +302,27 @@ resource.provider.validate end - it "should throw when choco version is less than the minimum supported version" do + it 'throws when choco version is less than the minimum supported version' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version) expect { resource.provider.validate - }.to raise_error(Puppet::Error, /Chocolatey version must be '0.9.9.0' to manage configuration values with Puppet/) + }.to raise_error(Puppet::Error, %r{Chocolatey version must be '0.9.9.0' to manage configuration values with Puppet}) end - it "should write a debug message on password when password is not empty" do + it 'writes a debug message on password when password is not empty' do resource[:user] = 'tim' resource[:password] = 'tim' PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) Puppet.expects(:warning).never - Puppet.expects(:debug).with("The password is not ensurable, so Puppet is unable to change the value using chocolateysource resource. As a workaround, a password change can be in the form of an exec. Reference Chocolateysource[#{name}]") + Puppet.expects(:debug).with('The password is not ensurable, so Puppet is unable to change the value using chocolateysource resource. '\ + "As a workaround, a password change can be in the form of an exec. Reference Chocolateysource[#{name}]") resource.provider.validate end - it "should not warn on user/password on newer choco versions" do + it 'does not warn on user/password on newer choco versions' do resource[:user] = 'tim' resource[:password] = 'tim' @@ -331,7 +332,7 @@ resource.provider.validate end - it "should not warn on user/password when choco version is the minimum supported version" do + it 'does not warn on user/password when choco version is the minimum supported version' do resource[:user] = 'tim' resource[:password] = 'tim' @@ -341,7 +342,7 @@ resource.provider.validate end - it "should not warn on bypass_proxy when choco version is newer than the minimum supported version" do + it 'does not warn on bypass_proxy when choco version is newer than the minimum supported version' do resource[:bypass_proxy] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) @@ -350,7 +351,7 @@ resource.provider.validate end - it "should not warn on bypass_proxy when choco version is the minimum supported version" do + it 'does not warn on bypass_proxy when choco version is the minimum supported version' do resource[:bypass_proxy] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version_bypass_proxy) @@ -359,16 +360,16 @@ resource.provider.validate end - it "should warn on bypass_proxy when choco version is less than the minimum supported version" do + it 'warns on bypass_proxy when choco version is less than the minimum supported version' do resource[:bypass_proxy] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_bypass_proxy) - Puppet.expects(:warning).with("Chocolatey is unable to specify bypassing system proxy for sources when version is less than 0.10.4. The value you set will be ignored.") + Puppet.expects(:warning).with('Chocolatey is unable to specify bypassing system proxy for sources when version is less than 0.10.4. The value you set will be ignored.') resource.provider.validate end - it "should not warn on allow_self_service when choco version is newer than the minimum supported version" do + it 'does not warn on allow_self_service when choco version is newer than the minimum supported version' do resource[:allow_self_service] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) @@ -377,7 +378,7 @@ resource.provider.validate end - it "should not warn on allow_self_service when choco version is the minimum supported version" do + it 'does not warn on allow_self_service when choco version is the minimum supported version' do resource[:allow_self_service] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version_allow_self_service) @@ -386,16 +387,16 @@ resource.provider.validate end - it "should warn on allow_self_service when choco version is less than the minimum supported version" do + it 'warns on allow_self_service when choco version is less than the minimum supported version' do resource[:allow_self_service] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_allow_self_service) - Puppet.expects(:warning).with("Chocolatey is unable to specify self-service for sources when version is less than 0.10.4. The value you set will be ignored.") + Puppet.expects(:warning).with('Chocolatey is unable to specify self-service for sources when version is less than 0.10.4. The value you set will be ignored.') resource.provider.validate end - it "should not warn on admin_only when choco version is newer than the minimum supported version" do + it 'does not warn on admin_only when choco version is newer than the minimum supported version' do resource[:admin_only] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) @@ -404,7 +405,7 @@ resource.provider.validate end - it "should not warn on admin_only when choco version is the minimum supported version" do + it 'does not warn on admin_only when choco version is the minimum supported version' do resource[:admin_only] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version_admin_only) @@ -413,30 +414,30 @@ resource.provider.validate end - it "should warn on admin_only when choco version is less than the minimum supported version" do + it 'warns on admin_only when choco version is less than the minimum supported version' do resource[:admin_only] = true PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_admin_only) - Puppet.expects(:warning).with("Chocolatey is unable to specify administrator only visibility for sources when version is less than 0.10.8. The value you set will be ignored.") + Puppet.expects(:warning).with('Chocolatey is unable to specify administrator only visibility for sources when version is less than 0.10.8. The value you set will be ignored.') resource.provider.validate end - it "should not warn if priority is not set" do + it 'does not warn if priority is not set' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) Puppet.expects(:warning).never resource.provider.validate end - it "should not warn if priority is not set on older unsupported versions" do + it 'does not warn if priority is not set on older unsupported versions' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_priority) Puppet.expects(:warning).never resource.provider.validate end - it "should not warn if priority is 0 on unsupported versions" do + it 'does not warn if priority is 0 on unsupported versions' do resource[:priority] = 0 PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_priority) @@ -445,7 +446,7 @@ resource.provider.validate end - it "should not warn on priority when choco version is newer than the minimum supported version" do + it 'does not warn on priority when choco version is newer than the minimum supported version' do resource[:priority] = 10 PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) @@ -454,7 +455,7 @@ resource.provider.validate end - it "should not warn on priority when choco version is the minimum supported version" do + it 'does not warn on priority when choco version is the minimum supported version' do resource[:priority] = 10 PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version_priority) @@ -463,42 +464,42 @@ resource.provider.validate end - it "should warn on priority when choco version is less than the minimum supported version" do + it 'warns on priority when choco version is less than the minimum supported version' do resource[:priority] = 10 PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_priority) - Puppet.expects(:warning).with("Chocolatey is unable to manage priority for sources when version is less than 0.9.9.9. The value you set will be ignored.") + Puppet.expects(:warning).with('Chocolatey is unable to manage priority for sources when version is less than 0.9.9.9. The value you set will be ignored.') resource.provider.validate end - it "should pass when ensure is not present and location is empty" do - no_location_resource = Puppet::Type.type(:chocolateysource).new(:name => 'source', :ensure => :disabled ) - no_location_resource.provider = provider.new(no_location_resource) + it 'passes when ensure is not present and location is empty' do + no_location_resource = Puppet::Type.type(:chocolateysource).new(name: 'source', ensure: :disabled) + no_location_resource.provider = provider_class.new(no_location_resource) no_location_resource.provider.validate end - it "should fail when ensure => present and location is empty" do + it 'fails when ensure => present and location is empty' do expect { - no_location_resource = Puppet::Type.type(:chocolateysource).new(:name => 'source') - no_location_resource.provider = provider.new(no_location_resource) + no_location_resource = Puppet::Type.type(:chocolateysource).new(name: 'source') + no_location_resource.provider = provider_class.new(no_location_resource) no_location_resource.provider.validate - }.to raise_error(Exception, /non-empty location/) + }.to raise_error(Exception, %r{non-empty location}) # check for just an exception here # In some versions of Puppet, this comes back as ArgumentError # In other versions of Puppet, this comes back as Puppet::Error end end - context ".flush" do - resource_name = "yup" - resource_location = "loc" + context '.flush' do + resource_name = 'yup' + resource_location = 'loc' resource_ensure = :present resource_priority = 10 - resource_user = "thatguy" - resource_password = "secrets!" + resource_user = 'thatguy' + resource_password = 'secrets!' resource_bypass_proxy = :true resource_allow_self_service = :true resource_admin_only = :true @@ -514,24 +515,22 @@ resource[:ensure] = resource_ensure end - it "should ensure a source is present with minimal values set" do + it 'ensures a source is present with minimal values set' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', 'yup' - ]) + '--name', 'yup']) resource.flush end - it "should ensure a source is present with all values set" do + it 'ensures a source is present with all values set' do resource[:priority] = resource_priority resource[:user] = resource_user resource[:password] = resource_password @@ -540,7 +539,7 @@ resource[:admin_only] = resource_admin_only PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, @@ -549,430 +548,295 @@ '--bypass-proxy', '--allow-self-service', '--admin-only', - '--priority', resource_priority, - ]) + '--priority', resource_priority]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name - ]) + '--name', resource_name]) resource.flush end - it "should set priority when present" do + it 'sets priority when present' do resource[:priority] = resource_priority PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, - '--priority', resource_priority, - ]) + '--priority', resource_priority]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name - ]) + '--name', resource_name]) resource.flush end - it "should set bypass_proxy when present" do + it 'sets bypass_proxy when present' do resource[:bypass_proxy] = resource_bypass_proxy PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, '--bypass-proxy', - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name - ]) + '--name', resource_name]) resource.flush end - it "should set allow_self_service when present" do + it 'sets allow_self_service when present' do resource[:allow_self_service] = resource_allow_self_service PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, '--allow-self-service', - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name - ]) + '--name', resource_name]) resource.flush end - it "should set admin_only when present" do + it 'sets admin_only when present' do resource[:admin_only] = resource_admin_only PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, '--admin-only', - '--priority', 0, - ]) - - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'enable', - '--name', resource_name - ]) - - resource.flush - end + '--priority', 0]) - it "should set user and password when user is present" do - resource[:user] = resource_user - resource[:password] = resource_password - - PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'add', - '--name', resource_name, - '--source', resource_location, - '--user', resource_user, - '--password', resource_password, - '--priority', 0, - ]) - - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name - ]) + '--name', resource_name]) resource.flush end - it "should set user and password when choco version is newer than the minimum supported version" do + it 'sets user and password when user is present' do resource[:user] = resource_user resource[:password] = resource_password PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, '--user', resource_user, '--password', resource_password, - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name - ]) + '--name', resource_name]) resource.flush end - it "should set user and password when choco version is the minimum supported version" do + it 'sets user and password when choco version is the minimum supported version' do resource[:user] = resource_user resource[:password] = resource_password PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, '--user', resource_user, - '--password', resource_password, - ]) + '--password', resource_password]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name - ]) + '--name', resource_name]) resource.flush end - it "should not set bypass_proxy when choco version is less than the minimum supported version" do + it 'does not set bypass_proxy when choco version is less than the minimum supported version' do resource[:bypass_proxy] = resource_bypass_proxy PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_bypass_proxy) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name, - ]) - - resource.flush - end - - it "should set bypass_proxy when choco version is newer than the minimum supported version" do - resource[:bypass_proxy] = resource_bypass_proxy - - PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'add', - '--name', resource_name, - '--source', resource_location, - '--bypass-proxy', - '--priority', 0, - ]) - - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'enable', - '--name', resource_name, - ]) + '--name', resource_name]) resource.flush end - it "should set bypass_proxy when choco version is the minimum supported version" do + it 'sets bypass_proxy when choco version is the minimum supported version' do resource[:bypass_proxy] = resource_bypass_proxy PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version_bypass_proxy) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, '--bypass-proxy', - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name, - ]) + '--name', resource_name]) resource.flush end - it "should not set allow_self_service when choco version is less than the minimum supported version" do + it 'does not set allow_self_service when choco version is less than the minimum supported version' do resource[:allow_self_service] = resource_allow_self_service PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_allow_self_service) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name, - ]) + '--name', resource_name]) resource.flush end - it "should set allow_self_service when choco version is newer than the minimum supported version" do - resource[:allow_self_service] = resource_allow_self_service - - PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'add', - '--name', resource_name, - '--source', resource_location, - '--allow-self-service', - '--priority', 0, - ]) - - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'enable', - '--name', resource_name, - ]) - - resource.flush - end - - it "should set allow_self_service when choco version is the minimum supported version" do + it 'sets allow_self_service when choco version is the minimum supported version' do resource[:allow_self_service] = resource_allow_self_service PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version_allow_self_service) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, '--allow-self-service', - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name, - ]) + '--name', resource_name]) resource.flush end - it "should not set admin_only when choco version is less than the minimum supported version" do - resource[:admin_only] = resource_admin_only - - PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_admin_only) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'add', - '--name', resource_name, - '--source', resource_location, - '--priority', 0, - ]) - - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'enable', - '--name', resource_name, - ]) - - resource.flush - end - - it "should set admin_only when choco version is newer than the minimum supported version" do - resource[:admin_only] = resource_admin_only - - PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'add', - '--name', resource_name, - '--source', resource_location, - '--admin-only', - '--priority', 0, - ]) - - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), - 'source', 'enable', - '--name', resource_name, - ]) - - resource.flush - end - - it "should set admin_only when choco version is the minimum supported version" do + it 'sets admin_only when choco version is the minimum supported version' do resource[:admin_only] = resource_admin_only PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version_admin_only) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, '--admin-only', - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name, - ]) + '--name', resource_name]) resource.flush end - it "should set priority when choco version is newer than the minimum supported version" do + it 'sets priority when choco version is newer than the minimum supported version' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name, - ]) + '--name', resource_name]) resource.flush end - it "should set priority when choco version is the minimum supported version" do + it 'sets priority when choco version is the minimum supported version' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_version_priority) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, - '--priority', 0, - ]) + '--priority', 0]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name, - ]) + '--name', resource_name]) resource.flush end - it "should not set priority when choco version is less than the minimum supported version" do + it 'does not set priority when choco version is less than the minimum supported version' do resource[:priority] = resource_priority PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(last_unsupported_version_priority) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, - '--source', resource_location, - ]) + '--source', resource_location]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', resource_name, - ]) + '--name', resource_name]) resource.flush end - it "should disable a source when ensure => disabled" do + it 'disables a source when ensure => disabled' do resource[:ensure] = :disabled resource[:name] = 'chocolatey' resource.provider.disable - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'disable', - '--name', 'chocolatey' - ]) + '--name', 'chocolatey']) resource.flush end - it "should remove a source when ensure => absent" do + it 'removes a source when ensure => absent' do resource[:ensure] = :absent resource.provider.destroy PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).never - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'remove', - '--name', resource_name, - ]) + '--name', resource_name]) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'enable', - '--name', 'yup' - ]).never + '--name', 'yup']).never resource.flush end - it "should provide an error message when choco execution fails" do + it 'provides an error message when choco execution fails' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(newer_choco_version) - Puppet::Util::Execution.expects(:execute).with([provider.command(:chocolatey), + Puppet::Util::Execution.expects(:execute).with([provider_class.command(:chocolatey), 'source', 'add', '--name', resource_name, '--source', resource_location, - '--priority', 0, - ]).raises(Puppet::ExecutionFailure, "Nooooo") + '--priority', 0]).raises(Puppet::ExecutionFailure, 'Nooooo') - expect { resource.flush }.to raise_error(Puppet::Error, /Unable to set Chocolatey source/) + expect { resource.flush }.to raise_error(Puppet::Error, %r{Unable to set Chocolatey source}) end end end diff --git a/spec/unit/puppet/provider/package/chocolatey_spec.rb b/spec/unit/puppet/provider/package/chocolatey_spec.rb index 0b3c2eec..5967f0ab 100644 --- a/spec/unit/puppet/provider/package/chocolatey_spec.rb +++ b/spec/unit/puppet/provider/package/chocolatey_spec.rb @@ -4,21 +4,20 @@ require 'puppet/provider/package/chocolatey' require 'rexml/document' -provider = Puppet::Type.type(:package).provider(:chocolatey) - -describe provider do - let (:resource) { Puppet::Type.type(:package).new(:provider => :chocolatey, :name => "chocolatey", :package_settings => {}) } - let (:first_compiled_choco_version) {'0.9.9.0'} - let (:newer_choco_version) {'0.9.10.0'} - let (:last_posh_choco_version) {'0.9.8.33'} - let (:minimum_supported_choco_uninstall_source) {'0.9.10.0'} - let (:minimum_supported_choco_exit_codes) {'0.9.10.0'} - let (:minimum_supported_choco_no_progress) {'0.10.4.0'} - let (:choco_zero_ten_zero) {'0.10.0'} - let (:choco_zero_eleven_zero) {'0.11.0'} - let (:choco_config) { 'c:\choco.config' } - let (:choco_install_path) { 'c:\dude\bin\choco.exe' } - let (:choco_config_contents) { <<-'EOT' +describe Puppet::Type.type(:package).provider(:chocolatey) do + let(:resource) { Puppet::Type.type(:package).new(provider: :chocolatey, name: 'chocolatey', package_settings: {}) } + let(:first_compiled_choco_version) { '0.9.9.0' } + let(:newer_choco_version) { '0.9.10.0' } + let(:last_posh_choco_version) { '0.9.8.33' } + let(:minimum_supported_choco_uninstall_source) { '0.9.10.0' } + let(:minimum_supported_choco_exit_codes) { '0.9.10.0' } + let(:minimum_supported_choco_no_progress) { '0.10.4.0' } + let(:choco_zero_ten_zero) { '0.10.0' } + let(:choco_zero_eleven_zero) { '0.11.0' } + let(:choco_config) { 'c:\choco.config' } + let(:choco_install_path) { 'c:\dude\bin\choco.exe' } + let(:choco_config_contents) do + <<-'EOT' @@ -60,8 +59,9 @@ EOT - } - let (:choco_config_contents_upec) { <<-'EOT' + end + let(:choco_config_contents_upec) do + <<-'EOT' @@ -69,78 +69,82 @@ EOT - } + end + let(:provider_class) { subject.class } + let(:provider) { subject.class.new(resource) } before :each do - @provider = provider.new(resource) - resource.provider = @provider + resource.provider = provider # Stub all file and config tests - provider.stubs(:healthcheck) + provider_class.stubs(:healthcheck) Puppet::Util::Execution.stubs(:execute) end - it "should be an instance of Puppet::Type::Package::ProviderChocolatey" do - @provider.must be_an_instance_of Puppet::Type::Package::ProviderChocolatey + it 'is an instance of Puppet::Type::Package::ProviderChocolatey' do + expect(provider).to be_an_instance_of Puppet::Type::Package::ProviderChocolatey end - it "should have an install method" do - @provider.should respond_to(:install) + it 'has an install method' do + expect(provider).to respond_to(:install) end - it "should have a latest method" do - @provider.should respond_to(:uninstall) + it 'has an uninstall method' do + expect(provider).to respond_to(:uninstall) end - it "should have an update method" do - @provider.should respond_to(:update) + it 'has an update method' do + expect(provider).to respond_to(:update) end - it "should have a latest method" do - @provider.should respond_to(:latest) + it 'has a latest method' do + expect(provider).to respond_to(:latest) end - context "parameter :source" do - it "should default to nil" do - resource[:source].should be_nil + context 'parameter :source' do + it 'defaults to nil' do + expect(resource[:source]).to be_nil end - it "should accept c:\\packages" do + it 'accepts c:\\packages' do resource[:source] = 'c:\packages' + expect(resource[:source]).to eq('c:\packages') end - it "should accept http://somelocation/packages" do + it 'accepts http://somelocation/packages' do resource[:source] = 'http://somelocation/packages' + expect(resource[:source]).to eq('http://somelocation/packages') end - it "should accept \\\\unc\\share\\packages" do + it 'accepts \\\\unc\\share\\packages' do resource[:source] = '\\unc\share\packages' + expect(resource[:source]).to eq('\\unc\share\packages') end end - context "self.get_choco_features" do + context 'self.read_choco_features' do before :each do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) end - it "should error when the config file location is null" do + it 'errors when the config file location is null' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(nil) expect { - @provider.get_choco_features - }.to raise_error(Puppet::ResourceError, /Config file not found for Chocolatey/) + provider.read_choco_features + }.to raise_error(Puppet::ResourceError, %r{Config file not found for Chocolatey}) end - it "should error when the config file is not found" do + it 'errors when the config file is not found' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(false) expect { - @provider.get_choco_features - }.to raise_error(Puppet::ResourceError, /was unable to locate config file at/) + provider.read_choco_features + }.to raise_error(Puppet::ResourceError, %r{was unable to locate config file at}) end - context "when getting sources from the config file" do + context 'when getting sources from the config file' do choco_features = [] before :each do @@ -148,214 +152,212 @@ PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents - choco_features = @provider.get_choco_features + choco_features = provider.read_choco_features end - it "should match the count of sources in the config" do - choco_features.count.must eq 14 + it 'matches the count of sources in the config' do + expect(choco_features.count).to eq 14 end - it "should contain xml elements" do - choco_features[0].must be_an_instance_of REXML::Element + it 'contains xml elements' do + expect(choco_features[0]).to be_an_instance_of REXML::Element end end end - context "self.get_choco_feature" do - let (:element) { REXML::Element.new('source') } - element_name = "default" - element_enabled = "true" - element_set_explicitly = "false" - element_description = "10" + context 'self.get_choco_feature' do + let(:element) { REXML::Element.new('source') } + + element_name = 'default' + element_enabled = 'true' + element_set_explicitly = 'false' + element_description = '10' before :each do - element.add_attributes( { "name" => element_name, - "enabled" => element_enabled, - "setExplicitly" => element_set_explicitly, - "description" => element_description, - } ) + element.add_attributes('name' => element_name, + 'enabled' => element_enabled, + 'setExplicitly' => element_set_explicitly, + 'description' => element_description) end - it "should return nil source when element is nil" do - @provider.get_choco_feature(nil).must be == {} + it 'returns nil source when element is nil' do + provider.get_choco_feature(nil).must be == {} end - it "should convert an element to a source" do - choco_feature = @provider.get_choco_feature(element) + it 'converts an element to a source' do + choco_feature = provider.get_choco_feature(element) - choco_feature[:name].must eq element_name - choco_feature[:enabled].must eq element_enabled - choco_feature[:set_explicitly].must eq element_set_explicitly - choco_feature[:description].must eq element_description + expect(choco_feature[:name]).to eq element_name + expect(choco_feature[:enabled]).to eq element_enabled + expect(choco_feature[:set_explicitly]).to eq element_set_explicitly + expect(choco_feature[:description]).to eq element_description end end - context "self.choco_features" do + context 'self.choco_features' do before :each do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents - herp = @provider.choco_features end - it "should return an array of hashes" do - @provider.choco_features.count.must eq 14 - @provider.choco_features[0].kind_of?(Hash) + it 'returns an array of hashes' do + expect(provider.choco_features.count).to eq 14 + provider.choco_features[0].is_a?(Hash) end end - context "when installing" do - context "with compiled choco client" do + context 'when installing' do + context 'with compiled choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(true) + provider.class.stubs(:compiled_choco?).returns(true) PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) PuppetX::Chocolatey::ChocolateyCommon.stubs(:file_exists?).with('c:\dude\config\chocolatey.config').returns(true) PuppetX::Chocolatey::ChocolateyCommon.stubs(:file_exists?).with('c:\dude\bin\choco.exe').returns(true) - 'c:\dude\config\chocolatey.config' PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(first_compiled_choco_version) # unhold is called in installs on compiled choco Puppet::Util::Execution.stubs(:execute) end - it "should use install command without versioned package" do + it 'uses install command without versioned package' do resource[:ensure] = :present - @provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil) + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil) - @provider.install + provider.install end - it "should call with ignore package exit codes when = 0.9.10 and not explicitly configured to use them" do + it 'calls with ignore package exit codes when = 0.9.10 and not explicitly configured to use them' do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_exit_codes).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil, '--ignore-package-exit-codes') - @provider.install + provider.install end - it "should call with ignore package exit codes when > 0.9.10 and not explicitly configured to use them" do + it 'calls with ignore package exit codes when > 0.9.10 and not explicitly configured to use them' do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_ten_zero).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil, '--ignore-package-exit-codes') - @provider.install + provider.install end - it "should not ignore package exit codes when = 0.9.10 and explicitly configured to use them" do + it 'does not ignore package exit codes when = 0.9.10 and explicitly configured to use them' do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents_upec PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_ten_zero).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil) + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil) - @provider.install + provider.install end - it "should call no progress when = 0.10.4 and not using verbose package options" do + it 'calls no progress when = 0.10.4 and not using verbose package options' do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_no_progress).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil, '--ignore-package-exit-codes', '--no-progress') + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil, '--ignore-package-exit-codes', '--no-progress') - @provider.install + provider.install end - it "should call no progress when > 0.10.4 and not using verbose package options" do + it 'calls no progress when > 0.10.4 and not using verbose package options' do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_eleven_zero).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil, '--ignore-package-exit-codes', '--no-progress') + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil, '--ignore-package-exit-codes', '--no-progress') - @provider.install + provider.install end - it "should call no progress when = 0.10.4 and verbose package option specified" do + it 'calls no progress when = 0.10.4 and verbose package option specified' do PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall) PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true) File.expects(:read).with(choco_config).returns choco_config_contents PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_no_progress).at_least_once resource[:ensure] = :present - resource[:package_settings] = {'verbose' => true} - @provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil, '--ignore-package-exit-codes') + resource[:package_settings] = { 'verbose' => true } + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil, '--ignore-package-exit-codes') - @provider.install + provider.install end - it "should use upgrade command with versioned package" do + it 'uses upgrade command with versioned package' do resource[:ensure] = '1.2.3' - @provider.expects(:chocolatey).with('upgrade', 'chocolatey', '--version', '1.2.3', '-y', nil) + provider.expects(:chocolatey).with('upgrade', 'chocolatey', '--version', '1.2.3', '-y', nil) - @provider.install + provider.install end - it "should call install instead of upgrade if package name ends with .config" do - resource[:name] = "packages.config" + it 'calls install instead of upgrade if package name ends with .config' do + resource[:name] = 'packages.config' resource[:ensure] = :present - @provider.expects(:chocolatey).with('install', 'packages.config','-y', nil) + provider.expects(:chocolatey).with('install', 'packages.config', '-y', nil) - @provider.install + provider.install end - it "should use source if it is specified" do + it 'uses source if it is specified' do resource[:source] = 'c:\packages' - @provider.expects(:chocolatey).with('install','chocolatey','-y', '--source', 'c:\packages', nil) + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', '--source', 'c:\packages', nil) - @provider.install + provider.install end end - context "with posh choco client" do + context 'with posh choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(false) + provider.class.stubs(:compiled_choco?).returns(false) PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns('c:\dude') PuppetX::Chocolatey::ChocolateyCommon.stubs(:file_exists?).with('c:\dude\bin\choco.exe').returns(true) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(last_posh_choco_version) end - it "should use install command without versioned package" do + it 'uses install command without versioned package' do resource[:ensure] = :present - @provider.expects(:chocolatey).with('install', 'chocolatey', nil) + provider.expects(:chocolatey).with('install', 'chocolatey', nil) - @provider.install + provider.install end - it "should use update command with versioned package" do + it 'uses update command with versioned package' do resource[:ensure] = '1.2.3' - @provider.expects(:chocolatey).with('update', 'chocolatey', '--version', '1.2.3', nil) + provider.expects(:chocolatey).with('update', 'chocolatey', '--version', '1.2.3', nil) - @provider.install + provider.install end - it "should use source if it is specified" do + it 'uses source if it is specified' do resource[:source] = 'c:\packages' - @provider.expects(:chocolatey).with('install','chocolatey', '--source', 'c:\packages', nil) + provider.expects(:chocolatey).with('install', 'chocolatey', '--source', 'c:\packages', nil) - @provider.install + provider.install end end end - context "when holding" do - context "with compiled choco client" do + context 'when holding' do + context 'with compiled choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(true) + provider.class.stubs(:compiled_choco?).returns(true) PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns('c:\dude') PuppetX::Chocolatey::ChocolateyCommon.stubs(:file_exists?).with('c:\dude\bin\choco.exe').returns(true) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(first_compiled_choco_version) @@ -363,394 +365,364 @@ Puppet::Util::Execution.stubs(:execute) end - it "should use install command with held package" do + it 'uses install command with held package' do resource[:ensure] = :held - @provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil) - @provider.expects(:chocolatey).with('pin', 'add', '-n', 'chocolatey') + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil) + provider.expects(:chocolatey).with('pin', 'add', '-n', 'chocolatey') - @provider.hold + provider.hold end end - context "with posh choco client" do + context 'with posh choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(false) + provider.class.stubs(:compiled_choco?).returns(false) end - it "should throw an argument error with held package" do + it 'throws an argument error with held package' do resource[:ensure] = :held - expect { @provider.hold }.to raise_error(ArgumentError, "Only choco v0.9.9+ can use ensure => held") + expect { provider.hold }.to raise_error(ArgumentError, 'Only choco v0.9.9+ can use ensure => held') end end end - context "when uninstalling" do - context "with compiled choco client" do + context 'when uninstalling' do + context 'with compiled choco client' do before :each do - @provider.stubs(:is_use_package_exit_codes_feature_enabled?).returns(false) - @provider.class.stubs(:is_compiled_choco?).returns(true) + provider.stubs(:use_package_exit_codes_feature_enabled?).returns(false) + provider.class.stubs(:compiled_choco?).returns(true) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(first_compiled_choco_version) # unhold is called in installs on compiled choco Puppet::Util::Execution.stubs(:execute) end - it "should call the remove operation" do - @provider.expects(:chocolatey).with('uninstall', 'chocolatey','-fy', nil) + it 'calls the remove operation' do + provider.expects(:chocolatey).with('uninstall', 'chocolatey', '-fy', nil) - @provider.uninstall + provider.uninstall end - it "should call with ignore package exit codes when = 0.9.10" do + it 'calls with ignore package exit codes when = 0.9.10' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_exit_codes).at_least_once - @provider.expects(:chocolatey).with('uninstall', 'chocolatey','-fy', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('uninstall', 'chocolatey', '-fy', nil, '--ignore-package-exit-codes') - @provider.uninstall + provider.uninstall end - it "should call with ignore package exit codes when > 0.9.10" do + it 'calls with ignore package exit codes when > 0.9.10' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_ten_zero).at_least_once - @provider.expects(:chocolatey).with('uninstall', 'chocolatey','-fy', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('uninstall', 'chocolatey', '-fy', nil, '--ignore-package-exit-codes') - @provider.uninstall + provider.uninstall end - it "should use ignore source if it is specified and the version is less than 0.9.10" do + it 'uses ignore source if it is specified and the version is less than 0.9.10' do resource[:source] = 'c:\packages' - @provider.expects(:chocolatey).with('uninstall','chocolatey','-fy', nil) + provider.expects(:chocolatey).with('uninstall', 'chocolatey', '-fy', nil) - @provider.uninstall + provider.uninstall end - it "should use source if it is specified and the version is at least 0.9.10" do + it 'uses source if it is specified and the version is at least 0.9.10' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_uninstall_source).at_least_once resource[:source] = 'c:\packages' - @provider.expects(:chocolatey).with('uninstall','chocolatey', '-fy', '--source', 'c:\packages', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('uninstall', 'chocolatey', '-fy', '--source', 'c:\packages', nil, '--ignore-package-exit-codes') - @provider.uninstall + provider.uninstall end - it "should use source if it is specified and the version is greater than 0.9.10" do + it 'uses source if it is specified and the version is greater than 0.9.10' do PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_ten_zero).at_least_once resource[:source] = 'c:\packages' - @provider.expects(:chocolatey).with('uninstall','chocolatey', '-fy', '--source', 'c:\packages', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('uninstall', 'chocolatey', '-fy', '--source', 'c:\packages', nil, '--ignore-package-exit-codes') - @provider.uninstall + provider.uninstall end end - context "with posh choco client" do + context 'with posh choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(false) + provider.class.stubs(:compiled_choco?).returns(false) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(last_posh_choco_version) end - it "should call the remove operation" do - @provider.expects(:chocolatey).with('uninstall', 'chocolatey', nil) + it 'calls the remove operation' do + provider.expects(:chocolatey).with('uninstall', 'chocolatey', nil) - @provider.uninstall + provider.uninstall end - it "should use source if it is specified" do + it 'uses source if it is specified' do resource[:source] = 'c:\packages' - @provider.expects(:chocolatey).with('uninstall','chocolatey', '--source', 'c:\packages', nil) + provider.expects(:chocolatey).with('uninstall', 'chocolatey', '--source', 'c:\packages', nil) - @provider.uninstall + provider.uninstall end end end - context "when updating" do - context "with compiled choco client" do + context 'when updating' do + context 'with compiled choco client' do before :each do - @provider.stubs(:is_use_package_exit_codes_feature_enabled?).returns(false) - @provider.class.stubs(:is_compiled_choco?).returns(true) + provider.stubs(:use_package_exit_codes_feature_enabled?).returns(false) + provider.class.stubs(:compiled_choco?).returns(true) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(first_compiled_choco_version) # unhold is called in installs on compiled choco Puppet::Util::Execution.stubs(:execute) end - it "should use `chocolatey upgrade` when ensure latest and package present" do - provider.stubs(:instances).returns [provider.new({ - :ensure => "1.2.3", - :name => "chocolatey", - :provider => :chocolatey, - })] - @provider.expects(:chocolatey).with('upgrade', 'chocolatey', '-y', nil) + it 'uses `chocolatey upgrade` when ensure latest and package present' do + provider_class.stubs(:instances).returns [provider_class.new(ensure: '1.2.3', + name: 'chocolatey', + provider: :chocolatey)] + provider.expects(:chocolatey).with('upgrade', 'chocolatey', '-y', nil) - @provider.update + provider.update end - it "should call with ignore package exit codes when = 0.9.10" do - provider.stubs(:instances).returns [provider.new({ - :ensure => "1.2.3", - :name => "chocolatey", - :provider => :chocolatey, - })] + it 'calls with ignore package exit codes when = 0.9.10' do + provider_class.stubs(:instances).returns [provider_class.new(ensure: '1.2.3', + name: 'chocolatey', + provider: :chocolatey)] PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_exit_codes).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('upgrade', 'chocolatey','-y', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('upgrade', 'chocolatey', '-y', nil, '--ignore-package-exit-codes') - @provider.update + provider.update end - it "should call with ignore package exit codes when > 0.9.10" do - provider.stubs(:instances).returns [provider.new({ - :ensure => "1.2.3", - :name => "chocolatey", - :provider => :chocolatey, - })] + it 'calls with ignore package exit codes when > 0.9.10' do + provider_class.stubs(:instances).returns [provider_class.new(ensure: '1.2.3', + name: 'chocolatey', + provider: :chocolatey)] PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_ten_zero).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('upgrade', 'chocolatey','-y', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('upgrade', 'chocolatey', '-y', nil, '--ignore-package-exit-codes') - @provider.update + provider.update end - it "should call with no-progress when = 0.10.4 and package_settings: verbose is not true" do - provider.stubs(:instances).returns [provider.new({ - :ensure => "1.2.3", - :name => "chocolatey", - :provider => :chocolatey, - })] + it 'calls with no-progress when = 0.10.4 and package_settings: verbose is not true' do + provider_class.stubs(:instances).returns [provider_class.new(ensure: '1.2.3', + name: 'chocolatey', + provider: :chocolatey)] PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_no_progress).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('upgrade', 'chocolatey','-y', nil, '--ignore-package-exit-codes', '--no-progress') + provider.expects(:chocolatey).with('upgrade', 'chocolatey', '-y', nil, '--ignore-package-exit-codes', '--no-progress') - @provider.update + provider.update end - it "should call with no-progress when > 0.10.4 and package_settings: verbose is not true" do - provider.stubs(:instances).returns [provider.new({ - :ensure => "1.2.3", - :name => "chocolatey", - :provider => :chocolatey, - })] + it 'calls with no-progress when > 0.10.4 and package_settings: verbose is not true' do + provider_class.stubs(:instances).returns [provider_class.new(ensure: '1.2.3', + name: 'chocolatey', + provider: :chocolatey)] PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_eleven_zero).at_least_once resource[:ensure] = :present - @provider.expects(:chocolatey).with('upgrade', 'chocolatey','-y', nil, '--ignore-package-exit-codes', '--no-progress') + provider.expects(:chocolatey).with('upgrade', 'chocolatey', '-y', nil, '--ignore-package-exit-codes', '--no-progress') - @provider.update + provider.update end - it "should not call with no-progress when = 0.10.4 and package_settings: verbose is true" do - provider.stubs(:instances).returns [provider.new({ - :ensure => "1.2.3", - :name => "chocolatey", - :provider => :chocolatey, - })] + it 'does not call with no-progress when = 0.10.4 and package_settings: verbose is true' do + provider_class.stubs(:instances).returns [provider_class.new(ensure: '1.2.3', + name: 'chocolatey', + provider: :chocolatey)] PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_no_progress).at_least_once resource[:package_settings] = { 'verbose' => true } resource[:ensure] = :present - @provider.expects(:chocolatey).with('upgrade', 'chocolatey','-y', nil, '--ignore-package-exit-codes') + provider.expects(:chocolatey).with('upgrade', 'chocolatey', '-y', nil, '--ignore-package-exit-codes') - @provider.update + provider.update end - it "should use `chocolatey install` when ensure latest and package absent" do - provider.stubs(:instances).returns [] - @provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil) + it 'uses `chocolatey install` when ensure latest and package absent' do + provider_class.stubs(:instances).returns [] + provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil) - @provider.update + provider.update end - it "should use source if it is specified" do - provider.expects(:instances).returns [provider.new({ - :ensure => "latest", - :name => "chocolatey", - :provider => :chocolatey, - })] + it 'uses source if it is specified' do + provider_class.expects(:instances).returns [provider_class.new(ensure: 'latest', + name: 'chocolatey', + provider: :chocolatey)] resource[:source] = 'c:\packages' - @provider.expects(:chocolatey).with('upgrade','chocolatey', '-y', '--source', 'c:\packages', nil) + provider.expects(:chocolatey).with('upgrade', 'chocolatey', '-y', '--source', 'c:\packages', nil) - @provider.update + provider.update end end - context "with posh choco client" do + context 'with posh choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(false) + provider.class.stubs(:compiled_choco?).returns(false) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(last_posh_choco_version) end - it "should use `chocolatey update` when ensure latest and package present" do - provider.stubs(:instances).returns [provider.new({ - :ensure => "1.2.3", - :name => "chocolatey", - :provider => :chocolatey, - })] - @provider.expects(:chocolatey).with('update', 'chocolatey', nil) + it 'uses `chocolatey update` when ensure latest and package present' do + provider_class.stubs(:instances).returns [provider_class.new(ensure: '1.2.3', + name: 'chocolatey', + provider: :chocolatey)] + provider.expects(:chocolatey).with('update', 'chocolatey', nil) - @provider.update + provider.update end - it "should use `chocolatey install` when ensure latest and package absent" do - provider.stubs(:instances).returns [] - @provider.expects(:chocolatey).with('install', 'chocolatey', nil) + it 'uses `chocolatey install` when ensure latest and package absent' do + provider_class.stubs(:instances).returns [] + provider.expects(:chocolatey).with('install', 'chocolatey', nil) - @provider.update + provider.update end - it "should use source if it is specified" do - provider.expects(:instances).returns [provider.new({ - :ensure => "latest", - :name => "chocolatey", - :provider => :chocolatey, - })] + it 'uses source if it is specified' do + provider_class.expects(:instances).returns [provider_class.new(ensure: 'latest', + name: 'chocolatey', + provider: :chocolatey)] resource[:source] = 'c:\packages' - @provider.expects(:chocolatey).with('update','chocolatey', '--source', 'c:\packages', nil) + provider.expects(:chocolatey).with('update', 'chocolatey', '--source', 'c:\packages', nil) - @provider.update + provider.update end end end - context "when getting latest" do - context "with compiled choco client" do + context 'when getting latest' do + context 'with compiled choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(true) + provider.class.stubs(:compiled_choco?).returns(true) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(first_compiled_choco_version) end - it "should use choco.exe arguments" do + it 'uses choco.exe arguments' do # we don't care where choco is, we are concerned with the arguments that are passed to choco. # - @provider.send(:latestcmd).drop(1).should == ['upgrade', '--noop', 'chocolatey','-r'] + provider.send(:latestcmd).drop(1).should == ['upgrade', '--noop', 'chocolatey', '-r'] end - it "should use source if it is specified" do + it 'uses source if it is specified' do resource[:source] = 'c:\packages' - @provider.send(:latestcmd).drop(1).should == ['upgrade', '--noop', 'chocolatey','-r', '--source', 'c:\packages'] - #@provider.expects(:chocolatey).with('upgrade', '--noop', 'chocolatey','-r', '--source', 'c:\packages') + provider.send(:latestcmd).drop(1).should == ['upgrade', '--noop', 'chocolatey', '-r', '--source', 'c:\packages'] + # provider.expects(:chocolatey).with('upgrade', '--noop', 'chocolatey','-r', '--source', 'c:\packages') - #@provider.latest + # provider.latest end end - context "with posh choco client" do + context 'with posh choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(false) + provider.class.stubs(:compiled_choco?).returns(false) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(last_posh_choco_version) end - it "should use posh arguments" do - @provider.send(:latestcmd).drop(1).should == ['version', 'chocolatey', '| findstr /R "latest" | findstr /V "latestCompare"'] + it 'uses posh arguments' do + provider.send(:latestcmd).drop(1).should == ['version', 'chocolatey', '| findstr /R "latest" | findstr /V "latestCompare"'] end - it "should use source if it is specified" do + it 'uses source if it is specified' do resource[:source] = 'c:\packages' - @provider.send(:latestcmd).drop(1).should == ['version', 'chocolatey', '--source', 'c:\packages', '| findstr /R "latest" | findstr /V "latestCompare"'] - #@provider.expects(:chocolatey).with('version', 'chocolatey', '--source', 'c:\packages', '| findstr /R "latest" | findstr /V "latestCompare"') + provider.send(:latestcmd).drop(1).should == ['version', 'chocolatey', '--source', 'c:\packages', '| findstr /R "latest" | findstr /V "latestCompare"'] + # provider.expects(:chocolatey).with('version', 'chocolatey', '--source', 'c:\packages', '| findstr /R "latest" | findstr /V "latestCompare"') - #@provider.latest + # provider.latest end end end - context "query" do - it "should return a hash when chocolatey and the package are present" do - provider.expects(:instances).returns [provider.new({ - :ensure => "1.2.5", - :name => "chocolatey", - :provider => :chocolatey, - })] - - @provider.query.should == { - :ensure => "1.2.5", - :name => "chocolatey", - :provider => :chocolatey, - } + context 'query' do + it 'returns a hash when chocolatey and the package are present' do + provider_class.expects(:instances).returns [provider_class.new(ensure: '1.2.5', + name: 'chocolatey', + provider: :chocolatey)] + + expect(provider.query).to eq(ensure: '1.2.5', + name: 'chocolatey', + provider: :chocolatey) end - it "should return nil when the package is missing" do - provider.expects(:instances).returns [] + it 'returns nil when the package is missing' do + provider_class.expects(:instances).returns [] - @provider.query.should == nil + expect(provider.query).to be_nil end end - context "when fetching a package list" do - it "should invoke provider listcmd" do - provider.expects(:listcmd) + context 'when fetching a package list' do + it 'invokes provider listcmd' do + provider_class.expects(:listcmd) - provider.instances + provider_class.instances end - it "should query chocolatey" do - provider.expects(:execpipe).with() do |args| - args[1] =~ /list/ - args[2] =~ /-lo/ + it 'queries chocolatey' do + provider_class.expects(:execpipe).with do |args| + args[1] =~ %r{list} + args[2] =~ %r{-lo} end - provider.instances + provider_class.instances end - context "self.instances" do - it "should return nil on error" do - provider.expects(:execpipe).raises(Puppet::ExecutionFailure.new("ERROR!")) + context 'self.instances' do + it 'returns nil on error' do + provider_class.expects(:execpipe).raises(Puppet::ExecutionFailure.new('ERROR!')) - provider.instances.should be_nil + expect(provider_class.instances).to be_nil end - context "with compiled choco client" do + context 'with compiled choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(true) + provider.class.stubs(:compiled_choco?).returns(true) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(first_compiled_choco_version) end - it "should return installed packages with their versions" do - provider.expects(:execpipe).yields(StringIO.new(%Q(package1|1.23\n\package2|2.00\n))) + it 'returns installed packages with their versions' do + provider_class.expects(:execpipe).yields(StringIO.new(%(package1|1.23\n\package2|2.00\n))) - packages = (provider.instances) + packages = provider_class.instances - packages.length.should == 2 + expect(packages.length).to eq(2) - packages[0].properties.should == { - :provider => :chocolatey, - :ensure => "1.23", - :name => 'package1' - } + expect(packages[0].properties).to eq(provider: :chocolatey, + ensure: '1.23', + name: 'package1') - packages[1].properties.should == { - :provider => :chocolatey, - :ensure => "2.00", - :name => 'package2' - } + expect(packages[1].properties).to eq(provider: :chocolatey, + ensure: '2.00', + name: 'package2') end - it "should return nil on error" do - provider.expects(:execpipe).yields(StringIO.new(%Q(Unable to search for packages when there are no soures enabled for packages and none were passed as arguments.\n))) + it 'returns nil on error' do + provider_class.expects(:execpipe).yields(StringIO.new(%(Unable to search for packages when there are no soures enabled for packages and none were passed as arguments.\n))) expect { - provider.instances - }.to raise_error(Puppet::Error, /At least one source must be enabled./) + provider_class.instances + }.to raise_error(Puppet::Error, %r{At least one source must be enabled.}) end end - context "with posh choco client" do + context 'with posh choco client' do before :each do - @provider.class.stubs(:is_compiled_choco?).returns(false) + provider.class.stubs(:compiled_choco?).returns(false) PuppetX::Chocolatey::ChocolateyVersion.stubs(:version).returns(last_posh_choco_version) end - it "should return installed packages with their versions" do - provider.expects(:execpipe).yields(StringIO.new(%Q(package1 1.23\n\package2 2.00\n))) + it 'returns installed packages with their versions' do + provider_class.expects(:execpipe).yields(StringIO.new(%(package1 1.23\n\package2 2.00\n))) - packages = (provider.instances) + packages = provider_class.instances - packages.length.should == 2 + expect(packages.length).to eq(2) - packages[0].properties.should == { - :provider => :chocolatey, - :ensure => "1.23", - :name => 'package1' - } + expect(packages[0].properties).to eq(provider: :chocolatey, + ensure: '1.23', + name: 'package1') - packages[1].properties.should == { - :provider => :chocolatey, - :ensure => "2.00", - :name => 'package2' - } + expect(packages[1].properties).to eq(provider: :chocolatey, + ensure: '2.00', + name: 'package2') end end end diff --git a/spec/unit/puppet/type/chocolateyconfig_spec.rb b/spec/unit/puppet/type/chocolateyconfig_spec.rb index db5c24ea..f25dc462 100644 --- a/spec/unit/puppet/type/chocolateyconfig_spec.rb +++ b/spec/unit/puppet/type/chocolateyconfig_spec.rb @@ -2,10 +2,10 @@ require 'puppet/type/chocolateyconfig' describe Puppet::Type.type(:chocolateyconfig) do - let(:resource) { Puppet::Type.type(:chocolateyconfig).new(:name => "config", :ensure => :absent) } + let(:resource) { Puppet::Type.type(:chocolateyconfig).new(name: 'config', ensure: :absent) } let(:provider) { Puppet::Provider.new(resource) } let(:catalog) { Puppet::Resource::Catalog.new } - let (:minimum_supported_version) {'0.9.10.0'} + let(:minimum_supported_version) { '0.9.10.0' } before :each do PuppetX::Chocolatey::ChocolateyCommon.stubs(:choco_version).returns(minimum_supported_version) @@ -13,68 +13,67 @@ resource.provider = provider end - it "should be an instance of Puppet::Type::Chocolateyconfig" do + it 'is an instance of Puppet::Type::Chocolateyconfig' do resource.must be_an_instance_of Puppet::Type::Chocolateyconfig end - it "parameter :name should be the name var" do + it 'parameter :name should be the name var' do resource.parameters[:name].isnamevar?.should be_truthy end - #string values - ['name','value'].each do |param| + # string values + ['name', 'value'].each do |param| context "parameter :#{param}" do - let (:param_symbol) { param.to_sym } + let(:param_symbol) { param.to_sym } - it "should not allow nil" do + it 'does not allow nil' do expect { resource[param_symbol] = nil - }.to raise_error(Puppet::Error, /Got nil value for #{param}/) + }.to raise_error(Puppet::Error, %r{Got nil value for #{param}}) end - it "should not allow empty" do + it 'does not allow empty' do expect { resource[param_symbol] = '' - }.to raise_error(Puppet::Error, /A non-empty #{param} must/) + }.to raise_error(Puppet::Error, %r{A non-empty #{param} must}) end - it "should accept any string value" do + it 'accepts any string value' do resource[param_symbol] = 'value' - resource[param_symbol] = "c:/thisstring-location/value/somefile.txt" - resource[param_symbol] = "c:\\thisstring-location\\value\\somefile.txt" + resource[param_symbol] = 'c:/thisstring-location/value/somefile.txt' + resource[param_symbol] = 'c:\\thisstring-location\\value\\somefile.txt' end end end - context "param :ensure" do - it "should accept 'present'" do + context 'param :ensure' do + it "accepts 'present'" do resource[:ensure] = 'present' end - it "should accept present" do + it 'accepts present' do resource[:ensure] = :present end - it "should accept absent" do + it 'accepts absent' do resource[:ensure] = :absent end - it "should reject any other value" do + it 'rejects any other value' do expect { resource[:ensure] = :whenever - }.to raise_error(Puppet::Error, /Invalid value :whenever. Valid values are/) + }.to raise_error(Puppet::Error, %r{Invalid value :whenever. Valid values are}) end end - it "should autorequire Exec[install_chocolatey_official] when in the catalog" do - exec = Puppet::Type.type(:exec).new(:name => "install_chocolatey_official", :path => "nope") + it 'autorequires Exec[install_chocolatey_official] when in the catalog' do + exec = Puppet::Type.type(:exec).new(name: 'install_chocolatey_official', path: 'nope') catalog.add_resource resource catalog.add_resource exec reqs = resource.autorequire - reqs.count.must == 1 - reqs[0].source.must == exec - reqs[0].target.must == resource + expect(reqs.count).to eq(1) + expect(reqs[0].source).to eq(exec) + expect(reqs[0].target).to eq(resource) end - end diff --git a/spec/unit/puppet/type/chocolateyfeature_spec.rb b/spec/unit/puppet/type/chocolateyfeature_spec.rb index caac211e..edc34b83 100644 --- a/spec/unit/puppet/type/chocolateyfeature_spec.rb +++ b/spec/unit/puppet/type/chocolateyfeature_spec.rb @@ -2,10 +2,10 @@ require 'puppet/type/chocolateyfeature' describe Puppet::Type.type(:chocolateyfeature) do - let(:resource) { Puppet::Type.type(:chocolateyfeature).new(:name => "chocolateyfeature", :ensure => "enabled" ) } + let(:resource) { Puppet::Type.type(:chocolateyfeature).new(name: 'chocolateyfeature', ensure: 'enabled') } let(:provider) { Puppet::Provider.new(resource) } let(:catalog) { Puppet::Resource::Catalog.new } - let (:minimum_supported_version) {'0.9.9.0'} + let(:minimum_supported_version) { '0.9.9.0' } before :each do PuppetX::Chocolatey::ChocolateyCommon.stubs(:choco_version).returns(minimum_supported_version) @@ -14,45 +14,45 @@ resource[:ensure] = 'enabled' end - it "should be an instance of Puppet::Type::Chocolateyfeature" do + it 'is an instance of Puppet::Type::Chocolateyfeature' do resource.must be_an_instance_of Puppet::Type::Chocolateyfeature end - it "parameter :name should be the name var" do + it 'parameter :name should be the name var' do resource.parameters[:name].isnamevar?.should be_truthy end - context "parameter :name" do - let (:param_symbol) { :name } + context 'parameter :name' do + let(:param_symbol) { :name } - it "should accept any string value" do + it 'accepts any string value' do resource[param_symbol] = 'value' - resource[param_symbol] = "c:/thisstring-location/value/somefile.txt" - resource[param_symbol] = "c:\\thisstring-location\\value\\somefile.txt" + resource[param_symbol] = 'c:/thisstring-location/value/somefile.txt' + resource[param_symbol] = 'c:\\thisstring-location\\value\\somefile.txt' end end - context "param :ensure" do - it "should accept 'enabled'" do + context 'param :ensure' do + it "accepts 'enabled'" do resource[:ensure] = 'enabled' end - it "should accept enabled" do + it 'accepts enabled' do resource[:ensure] = :enabled end - it "should accept 'disabled'" do + it "accepts 'disabled'" do resource[:ensure] = 'disabled' end - it "should accept :disabled" do + it 'accepts :disabled' do resource[:ensure] = :disabled end - it "should reject any other value" do + it 'rejects any other value' do expect { resource[:ensure] = :whenever - }.to raise_error(Puppet::Error, /Invalid value :whenever. Valid values are/) + }.to raise_error(Puppet::Error, %r{Invalid value :whenever. Valid values are}) end end end diff --git a/spec/unit/puppet/type/chocolateysource_spec.rb b/spec/unit/puppet/type/chocolateysource_spec.rb index 43530a56..1cce5e94 100644 --- a/spec/unit/puppet/type/chocolateysource_spec.rb +++ b/spec/unit/puppet/type/chocolateysource_spec.rb @@ -2,10 +2,10 @@ require 'puppet/type/chocolateysource' describe Puppet::Type.type(:chocolateysource) do - let(:resource) { Puppet::Type.type(:chocolateysource).new(:name => 'source', :location => 'c:\packages') } + let(:resource) { Puppet::Type.type(:chocolateysource).new(name: 'source', location: 'c:\packages') } let(:provider) { Puppet::Provider.new(resource) } let(:catalog) { Puppet::Resource::Catalog.new } - let (:minimum_supported_version) {'0.9.9.0'} + let(:minimum_supported_version) { '0.9.9.0' } before :each do PuppetX::Chocolatey::ChocolateyCommon.stubs(:choco_version).returns(minimum_supported_version) @@ -13,33 +13,33 @@ resource.provider = provider end - it "should be an instance of Puppet::Type::Chocolateysource" do + it 'is an instance of Puppet::Type::Chocolateysource' do resource.must be_an_instance_of Puppet::Type::Chocolateysource end - it "parameter :name should be the name var" do + it 'parameter :name should be the name var' do resource.parameters[:name].isnamevar?.should be_truthy end - #string values - ['name','location','user','password'].each do |param| + # string values + ['name', 'location', 'user', 'password'].each do |param| context "parameter :#{param}" do - let (:param_symbol) { param.to_sym } + let(:param_symbol) { param.to_sym } - it "should accept any string value" do + it 'accepts any string value' do resource[param_symbol] = 'value' - resource[param_symbol] = "c:/thisstring-location/value/somefile.txt" - resource[param_symbol] = "c:\\thisstring-location\\value\\somefile.txt" + resource[param_symbol] = 'c:/thisstring-location/value/somefile.txt' + resource[param_symbol] = 'c:\\thisstring-location\\value\\somefile.txt' end end end - #boolean values - ['bypass_proxy','admin_only','allow_self_service'].each do |param| + # boolean values + ['bypass_proxy', 'admin_only', 'allow_self_service'].each do |param| context "parameter :#{param}" do - let (:param_symbol) { param.to_sym } + let(:param_symbol) { param.to_sym } - it "should accept any valid boolean value" do + it 'accepts any valid boolean value' do resource[param_symbol] = true resource[param_symbol] = 'true' resource[param_symbol] = false @@ -48,96 +48,96 @@ end end - #numeric values + # numeric values ['priority'].each do |param| context "parameter :#{param}" do - let (:param_symbol) { param.to_sym } + let(:param_symbol) { param.to_sym } - it "should accept any numeric value" do + it 'accepts any numeric value' do resource[param_symbol] = 0 resource[param_symbol] = 10 end - it "should accept any string that represents a numeric value" do + it 'accepts any string that represents a numeric value' do resource[param_symbol] = '1' resource[param_symbol] = '0' end - it "should not accept other string values" do + it 'does not accept other string values' do expect { resource[param_symbol] = 'value' - }.to raise_error(Puppet::Error, /An integer is necessary for #{param}/) + }.to raise_error(Puppet::Error, %r{An integer is necessary for #{param}}) end - it "should not accept symbol values" do + it 'does not accept symbol values' do expect { resource[param_symbol] = :whenever - }.to raise_error(Puppet::Error, /An integer is necessary for #{param}/) + }.to raise_error(Puppet::Error, %r{An integer is necessary for #{param}}) end end end - context "param :ensure" do - it "should accept 'present'" do + context 'param :ensure' do + it "accepts 'present'" do resource[:ensure] = 'present' end - it "should accept present" do + it 'accepts present' do resource[:ensure] = :present end - it "should accept :disabled" do + it 'accepts :disabled' do resource[:ensure] = :disabled end - it "should accept absent" do + it 'accepts absent' do resource[:ensure] = :absent end - it "should reject any other value" do + it 'rejects any other value' do expect { resource[:ensure] = :whenever - }.to raise_error(Puppet::Error, /Invalid value :whenever. Valid values are/) + }.to raise_error(Puppet::Error, %r{Invalid value :whenever. Valid values are}) end end - it "should autorequire Exec[install_chocolatey_official] when in the catalog" do - exec = Puppet::Type.type(:exec).new(:name => "install_chocolatey_official", :path => "nope") + it 'autorequires Exec[install_chocolatey_official] when in the catalog' do + exec = Puppet::Type.type(:exec).new(name: 'install_chocolatey_official', path: 'nope') catalog.add_resource resource catalog.add_resource exec reqs = resource.autorequire - reqs.count.must == 1 - reqs[0].source.must == exec - reqs[0].target.must == resource + expect(reqs.count.must).to eq(1) + expect(reqs[0].source).to eq(exec) + expect(reqs[0].target).to eq(resource) end - context ".validate" do - it "should pass when both user/password are empty" do + context '.validate' do + it 'passes when both user/password are empty' do resource.validate end - it "should pass when both user/password have a value" do + it 'passes when both user/password have a value' do resource[:user] = 'tim' resource[:password] = 'tim' resource.validate end - it "should fail when user has a value but password does not" do + it 'fails when user has a value but password does not' do resource[:user] = 'tim' expect { resource.validate - }.to raise_error(ArgumentError, /you must specify both values/) + }.to raise_error(ArgumentError, %r{you must specify both values}) end - it "should fail when password has a value but user does not" do + it 'fails when password has a value but user does not' do resource[:password] = 'tim' expect { resource.validate - }.to raise_error(ArgumentError, /you must specify both values/) + }.to raise_error(ArgumentError, %r{you must specify both values}) end end end diff --git a/spec/unit/puppet_x/chocolatey/chocolatey_common_spec.rb b/spec/unit/puppet_x/chocolatey/chocolatey_common_spec.rb index a070cddf..cd27a41e 100644 --- a/spec/unit/puppet_x/chocolatey/chocolatey_common_spec.rb +++ b/spec/unit/puppet_x/chocolatey/chocolatey_common_spec.rb @@ -3,29 +3,27 @@ require 'puppet_x/chocolatey/chocolatey_common' describe 'Chocolatey Common' do - - let (:first_compiled_choco_version) {'0.9.9.0'} - let (:newer_choco_version) {'0.9.10.0'} - let (:last_posh_choco_version) {'0.9.8.33'} + let(:first_compiled_choco_version) { '0.9.9.0' } + let(:newer_choco_version) { '0.9.10.0' } + let(:last_posh_choco_version) { '0.9.8.33' } before :each do PuppetX::Chocolatey::ChocolateyCommon.stubs(:set_env_chocolateyinstall) end - context ".chocolatey_command" do - + context '.chocolatey_command' do before :each do - skip ('Not on Windows platform') unless Puppet.features.microsoft_windows? + skip 'Not on Windows platform' unless Puppet.features.microsoft_windows? end - it "should find chocolatey install location based on PuppetX::Chocolatey::ChocolateyInstall" do + it 'finds chocolatey install location based on PuppetX::Chocolatey::ChocolateyInstall' do PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns('c:\dude') PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with('c:\dude\choco.exe').returns(true) PuppetX::Chocolatey::ChocolateyCommon.chocolatey_command.should == 'c:\dude\choco.exe' end - it "should find chocolatey install location based on default location" do + it 'finds chocolatey install location based on default location' do PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns('c:\dude') PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with('c:\dude\choco.exe').returns(false) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with('C:\ProgramData\chocolatey\choco.exe').returns(false) @@ -35,8 +33,8 @@ end end - context ".choco_version" do - it "should return PuppetX::Chocolatey::ChocolateyVersion.version" do + context '.choco_version' do + it 'returns PuppetX::Chocolatey::ChocolateyVersion.version' do expected = '0.9.9.0.1' PuppetX::Chocolatey::ChocolateyVersion.expects(:version).returns(expected) PuppetX::Chocolatey::ChocolateyCommon.clear_cached_values @@ -45,10 +43,10 @@ end end - context ".choco_config_file" do - let (:choco_install_loc) { 'c:\dude' } + context '.choco_config_file' do + let(:choco_install_loc) { 'c:\dude' } - it "should return the normal config file location when found" do + it 'returns the normal config file location when found' do expected = 'c:\dude\config\chocolatey.config' PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns(choco_install_loc) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(expected).returns(true) @@ -56,7 +54,7 @@ PuppetX::Chocolatey::ChocolateyCommon.choco_config_file.must eq expected end - it "should return the old config file location for older installs" do + it 'returns the old config file location for older installs' do expected = 'c:\dude\chocolateyinstall\chocolatey.config' PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns(choco_install_loc) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with('c:\dude\config\chocolatey.config').returns(false) @@ -65,7 +63,7 @@ PuppetX::Chocolatey::ChocolateyCommon.choco_config_file.must eq expected end - it "should return nil when the config cannot be found" do + it 'returns nil when the config cannot be found' do PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns(choco_install_loc) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with('c:\dude\config\chocolatey.config').returns(false) PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with('c:\dude\chocolateyinstall\chocolatey.config').returns(false) diff --git a/spec/unit/puppet_x/chocolatey/chocolatey_install_spec.rb b/spec/unit/puppet_x/chocolatey/chocolatey_install_spec.rb index fc1fea9b..ca245187 100644 --- a/spec/unit/puppet_x/chocolatey/chocolatey_install_spec.rb +++ b/spec/unit/puppet_x/chocolatey/chocolatey_install_spec.rb @@ -1,78 +1,81 @@ +# rubocop:disable RSpec/AnyInstance + require 'spec_helper' require 'puppet_x/chocolatey/chocolatey_install' describe 'Chocolatey Install Location' do + context 'using normal install path' do + context 'on Windows' do + before :each do + skip 'Not on Windows platform' unless Puppet::Util::Platform.windows? + end - context 'on Windows' do + it 'returns install path from registry if it exists' do + expected_value = 'C:\somewhere' + Win32::Registry.any_instance.expects(:[]).with('ChocolateyInstall').returns(expected_value) - before :each do - skip ('Not on Windows platform') unless Puppet::Util::Platform.windows? - end + PuppetX::Chocolatey::ChocolateyInstall.install_path.must == expected_value + end - it "should return install path from registry if it exists" do - expected_value = 'C:\somewhere' - Win32::Registry.any_instance.expects(:[]).with('ChocolateyInstall').returns(expected_value) + it 'returns the environment variable ChocolateyInstall if it exists' do + Win32::Registry.any_instance.expects(:[]).with('ChocolateyInstall').raises(Win32::Registry::Error.new(2), 'file not found yo') - PuppetX::Chocolatey::ChocolateyInstall.install_path.must == expected_value - end + # this is a placeholder, it is already set in spec_helper + ENV['ChocolateyInstall'] = 'c:\blah' - it "should return the environment variable ChocolateyInstall if it exists" do - Win32::Registry.any_instance.expects(:[]).with('ChocolateyInstall').raises(Win32::Registry::Error.new(2), 'file not found yo') + PuppetX::Chocolatey::ChocolateyInstall.install_path.must == 'c:\blah' + end - # this is a placeholder, it is already set in spec_helper - ENV['ChocolateyInstall'] = 'c:\blah' + it 'returns nil if the environment variable does not exist' do + Win32::Registry.any_instance.expects(:[]).with('ChocolateyInstall').raises(Win32::Registry::Error.new(2), 'file not found yo') + ENV['ChocolateyInstall'] = nil - PuppetX::Chocolatey::ChocolateyInstall.install_path.must == 'c:\blah' + PuppetX::Chocolatey::ChocolateyInstall.install_path.must be_nil + end end - it "should return nil if the environment variable does not exist" do - Win32::Registry.any_instance.expects(:[]).with('ChocolateyInstall').raises(Win32::Registry::Error.new(2), 'file not found yo') - ENV['ChocolateyInstall'] = nil + context 'on Linux' do + before :each do + skip 'Not on Linux platform' unless Puppet.features.posix? + end - PuppetX::Chocolatey::ChocolateyInstall.install_path.must be_nil - end - end - - context 'on Linux' do - before :each do - skip ('Not on Linux platform') unless Puppet.features.posix? - end - - it "should return the environment variable ChocolateyInstall if it exists" do - # this is a placeholder, it is already set in spec_helper - ENV['ChocolateyInstall'] = 'c:\blah' + it 'returns the environment variable ChocolateyInstall if it exists' do + # this is a placeholder, it is already set in spec_helper + ENV['ChocolateyInstall'] = 'c:\blah' - PuppetX::Chocolatey::ChocolateyInstall.install_path.must == 'c:\blah' - end + PuppetX::Chocolatey::ChocolateyInstall.install_path.must == 'c:\blah' + end - it "should return nil if the ChocolateyInstall variable does not exist" do - ENV['ChocolateyInstall'] = nil + it 'returns nil if the ChocolateyInstall variable does not exist' do + ENV['ChocolateyInstall'] = nil - PuppetX::Chocolatey::ChocolateyInstall.install_path.must be_nil + PuppetX::Chocolatey::ChocolateyInstall.install_path.must be_nil + end end - end - after :each do - # setting the values back - ENV['ChocolateyInstall'] = 'c:\blah' + after :each do + # setting the values back + ENV['ChocolateyInstall'] = 'c:\blah' + end end -end - -describe 'Chocolatey Temp Directory' do - before :each do - skip ('Not on Windows platform') unless Puppet::Util::Platform.windows? - end + context 'using temp directory' do + before :each do + skip 'Not on Windows platform' unless Puppet::Util::Platform.windows? + end - it "should return the TEMP path from registry if it exists" do - expected_value = 'C:\somewhere' - Win32::Registry.any_instance.expects(:[]).with('TEMP').returns(expected_value) + it 'returns the TEMP path from registry if it exists' do + expected_value = 'C:\somewhere' + Win32::Registry.any_instance.expects(:[]).with('TEMP').returns(expected_value) - PuppetX::Chocolatey::ChocolateyInstall.temp_dir.must == expected_value - end - it "should return nil path from registry if it does not exist" do - Win32::Registry.any_instance.expects(:[]).with('TEMP').raises(Win32::Registry::Error.new(2), 'file not found yo').twice + PuppetX::Chocolatey::ChocolateyInstall.temp_dir.must == expected_value + end + it 'returns nil path from registry if it does not exist' do + Win32::Registry.any_instance.expects(:[]).with('TEMP').raises(Win32::Registry::Error.new(2), 'file not found yo').twice - PuppetX::Chocolatey::ChocolateyInstall.temp_dir.must be_nil + PuppetX::Chocolatey::ChocolateyInstall.temp_dir.must be_nil + end end end + +# rubocop:enable RSpec/AnyInstance diff --git a/spec/unit/puppet_x/chocolatey/chocolatey_version_spec.rb b/spec/unit/puppet_x/chocolatey/chocolatey_version_spec.rb index 11bfd1a7..7231cebb 100644 --- a/spec/unit/puppet_x/chocolatey/chocolatey_version_spec.rb +++ b/spec/unit/puppet_x/chocolatey/chocolatey_version_spec.rb @@ -2,54 +2,53 @@ require 'puppet_x/chocolatey/chocolatey_version' describe 'Chocolatey Version' do - context 'on Windows' do before :each do - skip ('Not on Windows platform') unless Puppet::Util::Platform.windows? + skip 'Not on Windows platform' unless Puppet::Util::Platform.windows? end - context "when Chocolatey is installed" do + context 'when Chocolatey is installed' do before :each do PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns('c:\dude') File.expects(:exist?).with('c:\dude\choco.exe').returns(true) end - it "should return the value from running choco -v" do + it 'returns the value from running choco -v' do expected_value = '1.2.3' Puppet::Util::Execution.expects(:execute).returns(expected_value) PuppetX::Chocolatey::ChocolateyVersion.version.must == expected_value end - it "should handle cleaning up spaces" do + it 'handles cleaning up spaces' do expected_value = '1.2.3' Puppet::Util::Execution.expects(:execute).returns(' ' + expected_value + ' ') PuppetX::Chocolatey::ChocolateyVersion.version.must == expected_value end - it "should handle older versions of choco" do + it 'handles older versions of choco' do expected_value = '1.2.3' Puppet::Util::Execution.expects(:execute).returns('Please run chocolatey /? or chocolatey help - chocolatey v' + expected_value) PuppetX::Chocolatey::ChocolateyVersion.version.must == expected_value end - it "should handle other messages that return with version call" do + it 'handles other messages that return with version call' do expected_value = '1.2.3' Puppet::Util::Execution.expects(:execute).returns("Error setting some value.\nPlease set this value yourself\r\nsound good?\r" + expected_value) PuppetX::Chocolatey::ChocolateyVersion.version.must == expected_value end - it "should handle a trailing line break" do + it 'handles a trailing line break' do expected_value = '1.2.3' Puppet::Util::Execution.expects(:execute).returns(expected_value + "\r\n") PuppetX::Chocolatey::ChocolateyVersion.version.must == expected_value end - it "should handle 0.9.8.33 of choco" do + it 'handles 0.9.8.33 of choco' do expected_value = '1.2.3' Puppet::Util::Execution.expects(:execute).returns('!!ATTENTION!! The next version of Chocolatey (v0.9.9) will require -y to perform @@ -63,22 +62,21 @@ end end - context "When Chocolatey is not installed" do + context 'When Chocolatey is not installed' do before :each do PuppetX::Chocolatey::ChocolateyInstall.expects(:install_path).returns(nil) File.expects(:exist?).with('\choco.exe').returns(false) end - it "should return nil" do + it 'returns nil' do PuppetX::Chocolatey::ChocolateyVersion.version.must be_nil end end - end context 'on Linux' do - it "should return nil on a non-windows system" do - skip ('Not on Linux platform') unless Puppet.features.posix? + it 'returns nil on a non-windows system' do + skip 'Not on Linux platform' unless Puppet.features.posix? PuppetX::Chocolatey::ChocolateyVersion.version.must be_nil end end