From c7013c082891edae1543c6244f1f0719dae98d13 Mon Sep 17 00:00:00 2001 From: tphoney Date: Tue, 26 Sep 2017 10:57:25 +0100 Subject: [PATCH] Cleanup via rubocop of ruby code --- .rubocop.yml | 586 +++--------------- .rubocop_todo.yml | 110 ++++ .sync.yml | 3 + .travis.yml | 2 + lib/facter/apt_reboot_required.rb | 2 +- lib/facter/apt_update_last_success.rb | 14 +- lib/facter/apt_updates.rb | 51 +- lib/puppet/provider/apt_key/apt_key.rb | 153 +++-- lib/puppet/type/apt_key.rb | 29 +- lib/puppet_x/apt_key/patch_openuri.rb | 63 -- spec/acceptance/apt_key_provider_spec.rb | 178 +++--- spec/acceptance/apt_spec.rb | 14 +- spec/acceptance/class_spec.rb | 7 +- spec/classes/apt_backports_spec.rb | 221 +++---- spec/classes/apt_spec.rb | 433 ++++++------- spec/classes/apt_update_spec.rb | 185 +++--- spec/defines/conf_spec.rb | 76 +-- spec/defines/key_compat_spec.rb | 305 ++++----- spec/defines/key_spec.rb | 315 +++++----- spec/defines/pin_spec.rb | 62 +- spec/defines/ppa_spec.rb | 349 ++++++----- spec/defines/setting_spec.rb | 106 ++-- spec/defines/source_compat_spec.rb | 98 +-- spec/defines/source_spec.rb | 420 ++++++------- spec/spec_helper.rb | 2 +- spec/spec_helper_acceptance.rb | 4 +- spec/unit/facter/apt_has_updates_spec.rb | 26 +- .../apt_package_security_updates_spec.rb | 32 +- spec/unit/facter/apt_package_updates_spec.rb | 23 +- spec/unit/facter/apt_reboot_required_spec.rb | 10 +- spec/unit/facter/apt_security_updates_spec.rb | 30 +- .../facter/apt_update_last_success_spec.rb | 14 +- spec/unit/facter/apt_updates_spec.rb | 22 +- spec/unit/puppet/type/apt_key_spec.rb | 200 +++--- 34 files changed, 1962 insertions(+), 2183 deletions(-) create mode 100644 .rubocop_todo.yml delete mode 100644 lib/puppet_x/apt_key/patch_openuri.rb diff --git a/.rubocop.yml b/.rubocop.yml index 5aadd1b..515ef63 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,508 +1,98 @@ -require: rubocop-rspec +--- +require: + - rubocop-rspec AllCops: - TargetRubyVersion: 1.9 + TargetRubyVersion: '2.1' Include: - - ./**/*.rb + - "./**/*.rb" Exclude: - - vendor/**/* - - .vendor/**/* - - pkg/**/* - - spec/fixtures/**/* -Lint/ConditionPosition: - Enabled: True - -Lint/ElseLayout: - Enabled: True - -Lint/UnreachableCode: - Enabled: True - -Lint/UselessComparison: - Enabled: True - -Lint/EnsureReturn: - Enabled: True - -Lint/HandleExceptions: - Enabled: True - -Lint/LiteralInCondition: - Enabled: True - -Lint/ShadowingOuterLocalVariable: - Enabled: True - -Lint/LiteralInInterpolation: - Enabled: True - -Style/HashSyntax: - Enabled: True - -Style/RedundantReturn: - Enabled: True - -Lint/AmbiguousOperator: - Enabled: True - -Lint/AssignmentInCondition: - Enabled: True - -Style/SpaceBeforeComment: - Enabled: True - -Style/AndOr: - Enabled: True - -Style/RedundantSelf: - Enabled: True - -# Method length is not necessarily an indicator of code quality -Metrics/MethodLength: - Enabled: False - -# Module length is not necessarily an indicator of code quality -Metrics/ModuleLength: - Enabled: False - -Style/WhileUntilModifier: - Enabled: True - -Lint/AmbiguousRegexpLiteral: - Enabled: True - -Lint/Eval: - Enabled: True - -Lint/BlockAlignment: - Enabled: True - -Lint/DefEndAlignment: - Enabled: True - -Lint/EndAlignment: - Enabled: True - -Lint/DeprecatedClassMethods: - Enabled: True - -Lint/Loop: - Enabled: True - -Lint/ParenthesesAsGroupedExpression: - Enabled: True - -Lint/RescueException: - Enabled: True - -Lint/StringConversionInInterpolation: - Enabled: True - -Lint/UnusedBlockArgument: - Enabled: True - -Lint/UnusedMethodArgument: - Enabled: True - -Lint/UselessAccessModifier: - Enabled: True - -Lint/UselessAssignment: - Enabled: True - -Lint/Void: - Enabled: True - -Style/AccessModifierIndentation: - Enabled: True - -Style/AccessorMethodName: - Enabled: True - -Style/Alias: - Enabled: True - -Style/AlignArray: - Enabled: True - -Style/AlignHash: - Enabled: True - -Style/AlignParameters: - Enabled: True - -Metrics/BlockNesting: - Enabled: True - -Style/AsciiComments: - Enabled: True - -Style/Attr: - Enabled: True - -Style/BracesAroundHashParameters: - Enabled: True - -Style/CaseEquality: - Enabled: True - -Style/CaseIndentation: - Enabled: True - -Style/CharacterLiteral: - Enabled: True - -Style/ClassAndModuleCamelCase: - Enabled: True - -Style/ClassAndModuleChildren: - Enabled: False - -Style/ClassCheck: - Enabled: True - -# Class length is not necessarily an indicator of code quality -Metrics/ClassLength: - Enabled: False - -Style/ClassMethods: - Enabled: True - -Style/ClassVars: - Enabled: True - -Style/WhenThen: - Enabled: True - -Style/WordArray: - Enabled: True - -Style/UnneededPercentQ: - Enabled: True - -Style/Tab: - Enabled: True - -Style/SpaceBeforeSemicolon: - Enabled: True - -Style/TrailingBlankLines: - Enabled: True - -Style/SpaceInsideBlockBraces: - Enabled: True - -Style/SpaceInsideBrackets: - Enabled: True - -Style/SpaceInsideHashLiteralBraces: - Enabled: True - -Style/SpaceInsideParens: - Enabled: True - -Style/LeadingCommentSpace: - Enabled: True - -Style/SpaceBeforeFirstArg: - Enabled: True - -Style/SpaceAfterColon: - Enabled: True - -Style/SpaceAfterComma: - Enabled: True - -Style/SpaceAfterMethodName: - Enabled: True - -Style/SpaceAfterNot: - Enabled: True - -Style/SpaceAfterSemicolon: - Enabled: True - -Style/SpaceAroundEqualsInParameterDefault: - Enabled: True - -Style/SpaceAroundOperators: - Enabled: True - -Style/SpaceBeforeBlockBraces: - Enabled: True - -Style/SpaceBeforeComma: - Enabled: True - -Style/CollectionMethods: - Enabled: True - -Style/CommentIndentation: - Enabled: True - -Style/ColonMethodCall: - Enabled: True - -Style/CommentAnnotation: - Enabled: True - -# 'Complexity' is very relative -Metrics/CyclomaticComplexity: - Enabled: False - -Style/ConstantName: - Enabled: True - -Style/Documentation: - Enabled: False - -Style/DefWithParentheses: - Enabled: True - -Style/PreferredHashMethods: - Enabled: True - -Style/DotPosition: - EnforcedStyle: trailing - -Style/DoubleNegation: - Enabled: True - -Style/EachWithObject: - Enabled: True - -Style/EmptyLineBetweenDefs: - Enabled: True - -Style/IndentArray: - Enabled: True - -Style/IndentHash: - Enabled: True - -Style/IndentationConsistency: - Enabled: True - -Style/IndentationWidth: - Enabled: True - -Style/EmptyLines: - Enabled: True - -Style/EmptyLinesAroundAccessModifier: - Enabled: True - -Style/EmptyLiteral: - Enabled: True - -# Configuration parameters: AllowURI, URISchemes. + - bin/* + - ".vendor/**/*" + - Gemfile + - Rakefile + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* +inherit_from: .rubocop_todo.yml Metrics/LineLength: - Enabled: False - -Style/MethodCallParentheses: - Enabled: True - -Style/MethodDefParentheses: - Enabled: True - -Style/LineEndConcatenation: - Enabled: True - -Style/TrailingWhitespace: - Enabled: True - -Style/StringLiterals: - Enabled: True - -Style/TrailingCommaInArguments: - Enabled: True - -Style/TrailingCommaInLiteral: - Enabled: True - -Style/GlobalVars: - Enabled: True - -Style/GuardClause: - Enabled: True - -Style/IfUnlessModifier: - Enabled: True - -Style/MultilineIfThen: - Enabled: True - -Style/NegatedIf: - Enabled: True - -Style/NegatedWhile: - Enabled: True - -Style/Next: - Enabled: True - -Style/SingleLineBlockParams: - Enabled: True - -Style/SingleLineMethods: - Enabled: True - -Style/SpecialGlobalVars: - Enabled: True - -Style/TrivialAccessors: - Enabled: True - -Style/UnlessElse: - Enabled: True - -Style/VariableInterpolation: - Enabled: True - -Style/VariableName: - Enabled: True - -Style/WhileUntilDo: - Enabled: True - -Style/EvenOdd: - Enabled: True - -Style/FileName: - Enabled: True - -Style/For: - Enabled: True - -Style/Lambda: - Enabled: True - -Style/MethodName: - Enabled: True - -Style/MultilineTernaryOperator: - Enabled: True - -Style/NestedTernaryOperator: - Enabled: True - -Style/NilComparison: - Enabled: True - + Description: People have wide screens, use them. + Max: 200 +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: - Enabled: True - -Style/MultilineBlockChain: - Enabled: True - -Style/Semicolon: - Enabled: True - -Style/SignalException: - Enabled: True - -Style/NonNilCheck: - Enabled: True - -Style/Not: - Enabled: True - -Style/NumericLiterals: - Enabled: True - -Style/OneLineConditional: - Enabled: True - -Style/OpMethod: - Enabled: True - -Style/ParenthesesAroundCondition: - Enabled: True - -Style/PercentLiteralDelimiters: - Enabled: True - -Style/PerlBackrefs: - Enabled: True - -Style/PredicateName: - Enabled: True - -Style/RedundantException: - Enabled: True - -Style/SelfAssignment: - Enabled: True - -Style/Proc: - Enabled: True - -Style/RaiseArgs: - Enabled: True - -Style/RedundantBegin: - Enabled: True - -Style/RescueModifier: - Enabled: True - -# based on https://github.com/voxpupuli/modulesync_config/issues/168 + 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 - Enabled: True - -Lint/UnderscorePrefixedVariableName: - Enabled: True - -Metrics/ParameterLists: - Enabled: False - -Lint/RequireParentheses: - Enabled: True - -Style/SpaceBeforeFirstArg: - Enabled: True - -Style/ModuleFunction: - Enabled: True - -Lint/Debugger: - Enabled: True - -Style/IfWithSemicolon: - Enabled: True - -Style/Encoding: - Enabled: True - -Style/BlockDelimiters: - Enabled: True - -Style/MultilineBlockLayout: - Enabled: True - -# 'Complexity' is very relative +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 +Style/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true Metrics/AbcSize: - Enabled: False - -# 'Complexity' is very relative + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/ModuleLength: + Enabled: false +Metrics/ParameterLists: + Enabled: false Metrics/PerceivedComplexity: - Enabled: False - -Lint/UselessAssignment: - Enabled: True - -Style/ClosingParenthesisIndentation: - Enabled: False - -# RSpec - -# We don't use rspec in this way + Enabled: false RSpec/DescribeClass: - Enabled: False - -# Example length is not necessarily an indicator of code quality -RSpec/ExampleLength: - Enabled: False - -RSpec/NamedSubject: - Enabled: False + Enabled: false +RSpec/MessageExpectation: + Enabled: false +Style/AsciiComments: + Enabled: false +Style/IfUnlessModifier: + Enabled: false +Style/SymbolProc: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..69304c9 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,110 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2017-09-26 11:49:52 +0100 using RuboCop version 0.49.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent +Layout/IndentHeredoc: + Exclude: + - 'spec/acceptance/apt_key_provider_spec.rb' + - 'spec/unit/facter/apt_has_updates_spec.rb' + - 'spec/unit/facter/apt_package_security_updates_spec.rb' + - 'spec/unit/facter/apt_package_updates_spec.rb' + - 'spec/unit/facter/apt_security_updates_spec.rb' + - 'spec/unit/facter/apt_updates_spec.rb' + +# Offense count: 1 +Lint/HandleExceptions: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 8 +Lint/ParenthesesAsGroupedExpression: + Exclude: + - 'spec/classes/apt_backports_spec.rb' + - 'spec/classes/apt_update_spec.rb' + +# Offense count: 1 +Lint/RescueException: + Exclude: + - 'spec/spec_helper_acceptance.rb' + +# Offense count: 1 +Lint/ScriptPermission: + Exclude: + - 'spec/classes/apt_update_spec.rb' + +# Offense count: 1 +Lint/UselessAssignment: + Exclude: + - 'spec/spec_helper_acceptance.rb' + +# Offense count: 1 +# Configuration parameters: CustomIncludeMethods. +RSpec/EmptyExampleGroup: + Exclude: + - 'spec/defines/ppa_spec.rb' + +# Offense count: 51 +# Configuration parameters: Max. +RSpec/ExampleLength: + Exclude: + - 'spec/acceptance/apt_key_provider_spec.rb' + - 'spec/acceptance/apt_spec.rb' + - 'spec/classes/apt_spec.rb' + - 'spec/defines/key_compat_spec.rb' + - 'spec/defines/key_spec.rb' + - 'spec/unit/puppet/type/apt_key_spec.rb' + +# Offense count: 4 +RSpec/MultipleExpectations: + Max: 2 + +# Offense count: 61 +RSpec/NamedSubject: + Exclude: + - 'spec/classes/apt_backports_spec.rb' + - 'spec/classes/apt_spec.rb' + - 'spec/defines/conf_spec.rb' + - 'spec/defines/key_compat_spec.rb' + - 'spec/defines/key_spec.rb' + - 'spec/defines/pin_spec.rb' + - 'spec/defines/ppa_spec.rb' + - 'spec/defines/setting_spec.rb' + - 'spec/defines/source_compat_spec.rb' + - 'spec/defines/source_spec.rb' + +# Offense count: 4 +# Configuration parameters: Max. +RSpec/NestedGroups: + Exclude: + - 'spec/defines/key_compat_spec.rb' + - 'spec/defines/key_spec.rb' + +# Offense count: 3 +RSpec/ScatteredLet: + Exclude: + - 'spec/defines/key_compat_spec.rb' + - 'spec/defines/key_spec.rb' + +# Offense count: 1 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'spec/spec_helper_acceptance.rb' + +# Offense count: 15 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'spec/classes/apt_spec.rb' + - 'spec/defines/source_compat_spec.rb' + - 'spec/defines/source_spec.rb' diff --git a/.sync.yml b/.sync.yml index dd59627..1f992a5 100644 --- a/.sync.yml +++ b/.sync.yml @@ -6,6 +6,9 @@ appveyor.yml: docker_sets: - set: docker/ubuntu-14.04 - set: docker/debian-8 + extras: + - rvm: 2.1.9 + script: bundle exec rake rubocop NOTICE: unmanaged: true diff --git a/.travis.yml b/.travis.yml index 9af2623..911841e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,5 +28,7 @@ matrix: - rvm: 2.1.9 bundler_args: --without system_tests env: PUPPET_GEM_VERSION="~> 4.0" + - rvm: 2.1.9 + script: bundle exec rake rubocop notifications: email: false diff --git a/lib/facter/apt_reboot_required.rb b/lib/facter/apt_reboot_required.rb index 8de904a..1e1650a 100644 --- a/lib/facter/apt_reboot_required.rb +++ b/lib/facter/apt_reboot_required.rb @@ -1,6 +1,6 @@ # apt_reboot_required.rb Facter.add(:apt_reboot_required) do - confine :osfamily => 'Debian' + confine osfamily: 'Debian' setcode do File.file?('/var/run/reboot-required') end diff --git a/lib/facter/apt_update_last_success.rb b/lib/facter/apt_update_last_success.rb index 21c33d5..9866a2b 100644 --- a/lib/facter/apt_update_last_success.rb +++ b/lib/facter/apt_update_last_success.rb @@ -1,18 +1,16 @@ require 'facter' -#This is derived from the file /var/lib/apt/periodic/update-success-stamp +# This is derived from the file /var/lib/apt/periodic/update-success-stamp # This is generated upon a successful apt-get update run natively in ubuntu. # the Puppetlabs-apt module deploys this same functionality for other debian-ish OSes Facter.add('apt_update_last_success') do - confine :osfamily => 'Debian' + confine osfamily: 'Debian' setcode do - if File.exists?('/var/lib/apt/periodic/update-success-stamp') - #get epoch time - lastsuccess = File.mtime('/var/lib/apt/periodic/update-success-stamp').to_i - lastsuccess + if File.exist?('/var/lib/apt/periodic/update-success-stamp') + # get epoch time + File.mtime('/var/lib/apt/periodic/update-success-stamp').to_i else - lastsuccess = -1 - lastsuccess + -1 end end end diff --git a/lib/facter/apt_updates.rb b/lib/facter/apt_updates.rb index a95a79b..f0fa302 100644 --- a/lib/facter/apt_updates.rb +++ b/lib/facter/apt_updates.rb @@ -1,38 +1,37 @@ apt_package_updates = nil -Facter.add("apt_has_updates") do - confine :osfamily => 'Debian' - if File.executable?("/usr/bin/apt-get") +Facter.add('apt_has_updates') do + confine osfamily: 'Debian' + if File.executable?('/usr/bin/apt-get') apt_get_result = Facter::Util::Resolution.exec('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1') - if not apt_get_result.nil? + unless apt_get_result.nil? apt_package_updates = [[], []] apt_get_result.each_line do |line| - if line =~ /^Inst\s/ - package = line.gsub(/^Inst\s([^\s]+)\s.*/, '\1').strip - apt_package_updates[0].push(package) - security_matches = [ - / Debian[^\s]+-updates[, ]/, - / Debian-Security:/, - / Ubuntu[^\s]+-security[, ]/, - / gNewSense[^\s]+-security[, ]/ - ] - re = Regexp.union(security_matches) - if line.match(re) - apt_package_updates[1].push(package) - end + next unless line =~ %r{^Inst\s} + package = line.gsub(%r{^Inst\s([^\s]+)\s.*}, '\1').strip + apt_package_updates[0].push(package) + security_matches = [ + %r{ Debian[^\s]+-updates[, ]}, + %r{ Debian-Security:}, + %r{ Ubuntu[^\s]+-security[, ]}, + %r{ gNewSense[^\s]+-security[, ]}, + ] + re = Regexp.union(security_matches) + if line.match(re) + apt_package_updates[1].push(package) end end end end setcode do - if not apt_package_updates.nil? and apt_package_updates.length == 2 + if !apt_package_updates.nil? && apt_package_updates.length == 2 apt_package_updates != [[], []] end end end -Facter.add("apt_package_updates") do - confine :apt_has_updates => true +Facter.add('apt_package_updates') do + confine apt_has_updates: true setcode do if Facter.version < '2.0.0' apt_package_updates[0].join(',') @@ -42,8 +41,8 @@ Facter.add("apt_package_updates") do end end -Facter.add("apt_package_security_updates") do - confine :apt_has_updates => true +Facter.add('apt_package_security_updates') do + confine apt_has_updates: true setcode do if Facter.version < '2.0.0' apt_package_updates[1].join(',') @@ -53,15 +52,15 @@ Facter.add("apt_package_security_updates") do end end -Facter.add("apt_updates") do - confine :apt_has_updates => true +Facter.add('apt_updates') do + confine apt_has_updates: true setcode do Integer(apt_package_updates[0].length) end end -Facter.add("apt_security_updates") do - confine :apt_has_updates => true +Facter.add('apt_security_updates') do + confine apt_has_updates: true setcode do Integer(apt_package_updates[1].length) end diff --git a/lib/puppet/provider/apt_key/apt_key.rb b/lib/puppet/provider/apt_key/apt_key.rb index 3f95c3c..49b1afd 100644 --- a/lib/puppet/provider/apt_key/apt_key.rb +++ b/lib/puppet/provider/apt_key/apt_key.rb @@ -6,46 +6,41 @@ if RUBY_VERSION == '1.8.7' # Mothers cry, puppies die and Ruby 1.8.7's open-uri needs to be # monkeypatched to support passing in :ftp_passive_mode. require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', - 'puppet_x', 'apt_key', 'patch_openuri.rb')) - OpenURI::Options.merge!({:ftp_active_mode => false,}) + 'puppet_x', 'apt_key', 'patch_openuri.rb')) + OpenURI::Options[:ftp_active_mode] = false end Puppet::Type.type(:apt_key).provide(:apt_key) do - - confine :osfamily => :debian - defaultfor :osfamily => :debian - commands :apt_key => 'apt-key' - commands :gpg => '/usr/bin/gpg' + confine osfamily: :debian + defaultfor osfamily: :debian + commands apt_key: 'apt-key' + commands gpg: '/usr/bin/gpg' def self.instances - cli_args = ['adv','--list-keys', '--with-colons', '--fingerprint', '--fixed-list-mode'] + cli_args = ['adv', '--list-keys', '--with-colons', '--fingerprint', '--fixed-list-mode'] - if RUBY_VERSION > '1.8.7' - key_output = apt_key(cli_args).encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '') - else - key_output = apt_key(cli_args) - end + key_output = apt_key(cli_args).encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') pub_line, sub_line, fpr_line = nil - key_array = key_output.split("\n").collect do |line| + key_array = key_output.split("\n").map do |line| if line.start_with?('pub') - pub_line = line - # reset fpr_line, to skip any previous subkeys which were collected - fpr_line = nil - sub_line = nil + pub_line = line + # reset fpr_line, to skip any previous subkeys which were collected + fpr_line = nil + sub_line = nil elsif line.start_with?('sub') - sub_line = line + sub_line = line elsif line.start_with?('fpr') - fpr_line = line + fpr_line = line end - if (sub_line and fpr_line) + if sub_line && fpr_line sub_line, fpr_line = nil next end - next unless (pub_line and fpr_line) + next unless pub_line && fpr_line line_hash = key_line_hash(pub_line, fpr_line) @@ -59,17 +54,17 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do end new( - :name => line_hash[:key_fingerprint], - :id => line_hash[:key_long], - :fingerprint => line_hash[:key_fingerprint], - :short => line_hash[:key_short], - :long => line_hash[:key_long], - :ensure => :present, - :expired => expired, - :expiry => line_hash[:key_expiry].nil? ? nil : line_hash[:key_expiry].strftime("%Y-%m-%d"), - :size => line_hash[:key_size], - :type => line_hash[:key_type], - :created => line_hash[:key_created].strftime("%Y-%m-%d") + name: line_hash[:key_fingerprint], + id: line_hash[:key_long], + fingerprint: line_hash[:key_fingerprint], + short: line_hash[:key_short], + long: line_hash[:key_long], + ensure: :present, + expired: expired, + expiry: line_hash[:key_expiry].nil? ? nil : line_hash[:key_expiry].strftime('%Y-%m-%d'), + size: line_hash[:key_size], + type: line_hash[:key_type], + created: line_hash[:key_created].strftime('%Y-%m-%d'), ) end key_array.compact! @@ -79,17 +74,14 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do apt_keys = instances resources.keys.each do |name| if name.length == 40 - if provider = apt_keys.find{ |key| key.fingerprint == name } - resources[name].provider = provider - end + provider = apt_keys.find { |key| key.fingerprint == name } + resources[name].provider = provider if provider elsif name.length == 16 - if provider = apt_keys.find{ |key| key.long == name } - resources[name].provider = provider - end + provider = apt_keys.find { |key| key.long == name } + resources[name].provider = provider if provider elsif name.length == 8 - if provider = apt_keys.find{ |key| key.short == name } - resources[name].provider = provider - end + provider = apt_keys.find { |key| key.short == name } + resources[name].provider = provider if provider end end end @@ -100,34 +92,34 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do fingerprint = fpr_split.last return_hash = { - :key_fingerprint => fingerprint, - :key_long => fingerprint[-16..-1], # last 16 characters of fingerprint - :key_short => fingerprint[-8..-1], # last 8 characters of fingerprint - :key_size => pub_split[2], - :key_type => nil, - :key_created => Time.at(pub_split[5].to_i), - :key_expiry => pub_split[6].empty? ? nil : Time.at(pub_split[6].to_i), + key_fingerprint: fingerprint, + key_long: fingerprint[-16..-1], # last 16 characters of fingerprint + key_short: fingerprint[-8..-1], # last 8 characters of fingerprint + key_size: pub_split[2], + key_type: nil, + key_created: Time.at(pub_split[5].to_i), + key_expiry: pub_split[6].empty? ? nil : Time.at(pub_split[6].to_i), } # set key type based on types defined in /usr/share/doc/gnupg/DETAILS.gz case pub_split[3] - when "1" + when '1' return_hash[:key_type] = :rsa - when "17" + when '17' return_hash[:key_type] = :dsa - when "18" + when '18' return_hash[:key_type] = :ecc - when "19" + when '19' return_hash[:key_type] = :ecdsa end - return return_hash + return_hash end def source_to_file(value) - parsedValue = URI::parse(value) - if parsedValue.scheme.nil? - fail("The file #{value} does not exist") unless File.exists?(value) + parsed_value = URI.parse(value) + if parsed_value.scheme.nil? + raise("The file #{value} does not exist") unless File.exist?(value) # Because the tempfile method has to return a live object to prevent GC # of the underlying file from occuring too early, we also have to return # a file object here. The caller can still call the #path method on the @@ -139,17 +131,17 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do begin # Only send basic auth if URL contains userinfo # Some webservers (e.g. Amazon S3) return code 400 if empty basic auth is sent - if parsedValue.userinfo.nil? - key = parsedValue.read + if parsed_value.userinfo.nil? + key = parsed_value.read else - user_pass = parsedValue.userinfo.split(':') - parsedValue.userinfo = '' - key = open(parsedValue, :http_basic_authentication => user_pass).read + user_pass = parsed_value.userinfo.split(':') + parsed_value.userinfo = '' + key = open(parsed_value, http_basic_authentication: user_pass).read end rescue OpenURI::HTTPError, Net::FTPPermError => e - fail("#{e.message} for #{resource[:source]}") + raise("#{e.message} for #{resource[:source]}") rescue SocketError - fail("could not resolve #{resource[:source]}") + raise("could not resolve #{resource[:source]}") else tempfile(key) end @@ -163,10 +155,10 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do file = Tempfile.new('apt_key') file.write content file.close - #confirm that the fingerprint from the file, matches the long key that is in the manifest + # confirm that the fingerprint from the file, matches the long key that is in the manifest if name.size == 40 if File.executable? command(:gpg) - extracted_key = execute(["#{command(:gpg)} --with-fingerprint --with-colons #{file.path} | awk -F: '/^fpr:/ { print $10 }'"], :failonfail => false) + extracted_key = execute(["#{command(:gpg)} --with-fingerprint --with-colons #{file.path} | awk -F: '/^fpr:/ { print $10 }'"], failonfail: false) extracted_key = extracted_key.chomp found_match = false @@ -175,8 +167,8 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do found_match = true end end - if not found_match - fail("The id in your manifest #{resource[:name]} and the fingerprint from content/source do not match. Please check there is not an error in the id or check the content/source is legitimate.") + unless found_match + raise("The id in your manifest #{resource[:name]} and the fingerprint from content/source don't match. Check for an error in the id and content/source is legitimate.") end else warning('/usr/bin/gpg cannot be found for verification of the id.') @@ -191,7 +183,7 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do def create command = [] - if resource[:source].nil? and resource[:content].nil? + if resource[:source].nil? && resource[:content].nil? # Breaking up the command like this is needed because it blows up # if --recv-keys isn't the last argument. command.push('adv', '--keyserver', resource[:server]) @@ -207,22 +199,23 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do command.push('add', key_file.path) # In case we really screwed up, better safe than sorry. else - fail("an unexpected condition occurred while trying to add the key: #{resource[:id]}") + raise("an unexpected condition occurred while trying to add the key: #{resource[:id]}") end apt_key(command) @property_hash[:ensure] = :present end def destroy - begin + loop do apt_key('del', resource.provider.short) - r = execute(["#{command(:apt_key)} list | grep '/#{resource.provider.short}\s'"], :failonfail => false) - end while r.exitstatus == 0 + r = execute(["#{command(:apt_key)} list | grep '/#{resource.provider.short}\s'"], failonfail: false) + break unless r.exitstatus.zero? + end @property_hash.clear end - def read_only(value) - fail('This is a read-only property.') + def read_only(_value) + raise('This is a read-only property.') end mk_resource_methods @@ -235,9 +228,9 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do # Alias the setters of read-only properties # to the read_only function. - alias :created= :read_only - alias :expired= :read_only - alias :expiry= :read_only - alias :size= :read_only - alias :type= :read_only + alias_method :created=, :read_only + alias_method :expired=, :read_only + alias_method :expiry=, :read_only + alias_method :size=, :read_only + alias_method :type=, :read_only end diff --git a/lib/puppet/type/apt_key.rb b/lib/puppet/type/apt_key.rb index 72f3c87..a9273e2 100644 --- a/lib/puppet/type/apt_key.rb +++ b/lib/puppet/type/apt_key.rb @@ -1,7 +1,6 @@ require 'pathname' Puppet::Type.newtype(:apt_key) do - @doc = <<-EOS This type provides Puppet with the capabilities to manage GPG keys needed by apt to perform package validation. Apt has it's own GPG keyring that can @@ -20,25 +19,25 @@ Puppet::Type.newtype(:apt_key) do ensurable validate do - if self[:content] and self[:source] - fail('The properties content and source are mutually exclusive.') + if self[:content] && self[:source] + raise('The properties content and source are mutually exclusive.') end - if self[:id].length < 40 + if self[:id].length < 40 warning('The id should be a full fingerprint (40 characters), see README.') - end + end end - newparam(:id, :namevar => true) do + newparam(:id, namevar: true) do desc 'The ID of the key you want to manage.' # GPG key ID's should be either 32-bit (short) or 64-bit (long) key ID's # and may start with the optional 0x, or they can be 40-digit key fingerprints - newvalues(/\A(0x)?[0-9a-fA-F]{8}\Z/, /\A(0x)?[0-9a-fA-F]{16}\Z/, /\A(0x)?[0-9a-fA-F]{40}\Z/) + newvalues(%r{\A(0x)?[0-9a-fA-F]{8}\Z}, %r{\A(0x)?[0-9a-fA-F]{16}\Z}, %r{\A(0x)?[0-9a-fA-F]{40}\Z}) munge do |value| - if value.start_with?('0x') - id = value.partition('0x').last.upcase - else - id = value.upcase - end + id = if value.start_with?('0x') + value.partition('0x').last.upcase + else + value.upcase + end id end end @@ -49,11 +48,11 @@ Puppet::Type.newtype(:apt_key) do newparam(:source) do desc 'Location of a GPG key file, /path/to/file, ftp://, http:// or https://' - newvalues(/\Ahttps?:\/\//, /\Aftp:\/\//, /\A\/\w+/) + newvalues(%r{\Ahttps?://}, %r{\Aftp://}, %r{\A/\w+}) end autorequire(:file) do - if self[:source] and Pathname.new(self[:source]).absolute? + if self[:source] && Pathname.new(self[:source]).absolute? self[:source] end end @@ -62,7 +61,7 @@ Puppet::Type.newtype(:apt_key) do desc 'The key server to fetch the key from based on the ID. It can either be a domain name or url.' defaultto :'keyserver.ubuntu.com' - newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/) + newvalues(%r{\A((hkp|http|https)://)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$}) end newparam(:options) do diff --git a/lib/puppet_x/apt_key/patch_openuri.rb b/lib/puppet_x/apt_key/patch_openuri.rb deleted file mode 100644 index 722c7bd..0000000 --- a/lib/puppet_x/apt_key/patch_openuri.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'uri' -require 'stringio' -require 'time' - -module URI - class FTP - def buffer_open(buf, proxy, options) # :nodoc: - if proxy - OpenURI.open_http(buf, self, proxy, options) - return - end - require 'net/ftp' - - directories = self.path.split(%r{/}, -1) - directories.shift if directories[0] == '' # strip a field before leading slash - directories.each {|d| - d.gsub!(/%([0-9A-Fa-f][0-9A-Fa-f])/) { [$1].pack("H2") } - } - unless filename = directories.pop - raise ArgumentError, "no filename: #{self.inspect}" - end - directories.each {|d| - if /[\r\n]/ =~ d - raise ArgumentError, "invalid directory: #{d.inspect}" - end - } - if /[\r\n]/ =~ filename - raise ArgumentError, "invalid filename: #{filename.inspect}" - end - typecode = self.typecode - if typecode && /\A[aid]\z/ !~ typecode - raise ArgumentError, "invalid typecode: #{typecode.inspect}" - end - - # The access sequence is defined by RFC 1738 - ftp = Net::FTP.open(self.host) - ftp.passive = true if !options[:ftp_active_mode] - # todo: extract user/passwd from .netrc. - user = 'anonymous' - passwd = nil - user, passwd = self.userinfo.split(/:/) if self.userinfo - ftp.login(user, passwd) - directories.each {|cwd| - ftp.voidcmd("CWD #{cwd}") - } - if typecode - # xxx: typecode D is not handled. - ftp.voidcmd("TYPE #{typecode.upcase}") - end - if options[:content_length_proc] - options[:content_length_proc].call(ftp.size(filename)) - end - ftp.retrbinary("RETR #{filename}", 4096) { |str| - buf << str - options[:progress_proc].call(buf.size) if options[:progress_proc] - } - ftp.close - buf.io.rewind - end - - include OpenURI::OpenRead - end -end diff --git a/spec/acceptance/apt_key_provider_spec.rb b/spec/acceptance/apt_key_provider_spec.rb index b4347e1..1ea5411 100644 --- a/spec/acceptance/apt_key_provider_spec.rb +++ b/spec/acceptance/apt_key_provider_spec.rb @@ -1,44 +1,44 @@ require 'spec_helper_acceptance' -PUPPETLABS_GPG_KEY_SHORT_ID = 'EF8D349F' -PUPPETLABS_GPG_KEY_LONG_ID = '7F438280EF8D349F' -PUPPETLABS_GPG_KEY_FINGERPRINT = '6F6B15509CF8E59E6E469F327F438280EF8D349F' -PUPPETLABS_APT_URL = 'apt.puppetlabs.com' -PUPPETLABS_GPG_KEY_FILE = 'DEB-GPG-KEY-puppet' -CENTOS_GPG_KEY_SHORT_ID = 'C105B9DE' -CENTOS_GPG_KEY_LONG_ID = '0946FCA2C105B9DE' -CENTOS_GPG_KEY_FINGERPRINT = 'C1DAC52D1664E8A4386DBA430946FCA2C105B9DE' -CENTOS_REPO_URL = 'ftp.cvut.cz/centos' -CENTOS_GPG_KEY_FILE = 'RPM-GPG-KEY-CentOS-6' - -SHOULD_NEVER_EXIST_ID = 'EF8D349F' - -KEY_CHECK_COMMAND = "apt-key adv --list-keys --with-colons --fingerprint | grep " -PUPPETLABS_KEY_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} #{PUPPETLABS_GPG_KEY_FINGERPRINT}" -CENTOS_KEY_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} #{CENTOS_GPG_KEY_FINGERPRINT}" +PUPPETLABS_GPG_KEY_SHORT_ID = 'EF8D349F'.freeze +PUPPETLABS_GPG_KEY_LONG_ID = '7F438280EF8D349F'.freeze +PUPPETLABS_GPG_KEY_FINGERPRINT = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze +PUPPETLABS_APT_URL = 'apt.puppetlabs.com'.freeze +PUPPETLABS_GPG_KEY_FILE = 'DEB-GPG-KEY-puppet'.freeze +CENTOS_GPG_KEY_SHORT_ID = 'C105B9DE'.freeze +CENTOS_GPG_KEY_LONG_ID = '0946FCA2C105B9DE'.freeze +CENTOS_GPG_KEY_FINGERPRINT = 'C1DAC52D1664E8A4386DBA430946FCA2C105B9DE'.freeze +CENTOS_REPO_URL = 'ftp.cvut.cz/centos'.freeze +CENTOS_GPG_KEY_FILE = 'RPM-GPG-KEY-CentOS-6'.freeze + +SHOULD_NEVER_EXIST_ID = 'EF8D349F'.freeze + +KEY_CHECK_COMMAND = 'apt-key adv --list-keys --with-colons --fingerprint | grep '.freeze +PUPPETLABS_KEY_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} #{PUPPETLABS_GPG_KEY_FINGERPRINT}".freeze +CENTOS_KEY_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} #{CENTOS_GPG_KEY_FINGERPRINT}".freeze MAX_TIMEOUT_RETRY = 3 TIMEOUT_RETRY_WAIT = 5 -TIMEOUT_ERROR_MATCHER = /no valid OpenPGP data found/ +TIMEOUT_ERROR_MATCHER = %r{no valid OpenPGP data found} describe 'apt_key' do before(:each) do # Delete twice to make sure everything is cleaned # up after the short key collision shell("apt-key del #{PUPPETLABS_GPG_KEY_SHORT_ID}", - :acceptable_exit_codes => [0,1,2]) + acceptable_exit_codes: [0, 1, 2]) shell("apt-key del #{PUPPETLABS_GPG_KEY_SHORT_ID}", - :acceptable_exit_codes => [0,1,2]) + acceptable_exit_codes: [0, 1, 2]) end describe 'default options' do key_versions = { - '32bit key id' => "#{PUPPETLABS_GPG_KEY_SHORT_ID}", - '64bit key id' => "#{PUPPETLABS_GPG_KEY_LONG_ID}", - '160bit key fingerprint' => "#{PUPPETLABS_GPG_KEY_FINGERPRINT}", - '32bit lowercase key id' => "#{PUPPETLABS_GPG_KEY_SHORT_ID.downcase}", - '64bit lowercase key id' => "#{PUPPETLABS_GPG_KEY_LONG_ID.downcase}", - '160bit lowercase key fingerprint' => "#{PUPPETLABS_GPG_KEY_FINGERPRINT.downcase}", + '32bit key id' => PUPPETLABS_GPG_KEY_SHORT_ID.to_s, + '64bit key id' => PUPPETLABS_GPG_KEY_LONG_ID.to_s, + '160bit key fingerprint' => PUPPETLABS_GPG_KEY_FINGERPRINT.to_s, + '32bit lowercase key id' => PUPPETLABS_GPG_KEY_SHORT_ID.downcase.to_s, + '64bit lowercase key id' => PUPPETLABS_GPG_KEY_LONG_ID.downcase.to_s, + '160bit lowercase key fingerprint' => PUPPETLABS_GPG_KEY_FINGERPRINT.downcase.to_s, '0x formatted 32bit key id' => "0x#{PUPPETLABS_GPG_KEY_SHORT_ID}", '0x formatted 64bit key id' => "0x#{PUPPETLABS_GPG_KEY_LONG_ID}", '0x formatted 160bit key fingerprint' => "0x#{PUPPETLABS_GPG_KEY_FINGERPRINT}", @@ -48,7 +48,7 @@ describe 'apt_key' do } key_versions.each do |key, value| - context "#{key}" do + context key.to_s do it 'works' do pp = <<-EOS apt_key { 'puppetlabs': @@ -57,8 +57,8 @@ describe 'apt_key' do } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end end @@ -72,8 +72,8 @@ describe 'apt_key' do } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/Valid values match/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{Valid values match}) end end end @@ -97,11 +97,11 @@ describe 'apt_key' do shell(CENTOS_KEY_CHECK_COMMAND) # Time to remove it using Puppet - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(CENTOS_KEY_CHECK_COMMAND, - :acceptable_exit_codes => [1]) + acceptable_exit_codes: [1]) # Re-Install the key (retry because key pool may timeout) retry_on_error_matching(MAX_TIMEOUT_RETRY, TIMEOUT_RETRY_WAIT, TIMEOUT_ERROR_MATCHER) do @@ -111,7 +111,7 @@ describe 'apt_key' do end end - context 'absent, added with long key', :unless => (fact('operatingsystem') == 'Debian' and fact('operatingsystemmajrelease') == '6') do + context 'absent, added with long key', unless: (fact('operatingsystem') == 'Debian' && fact('operatingsystemmajrelease') == '6') do it 'is removed' do pp = <<-EOS apt_key { 'puppetlabs': @@ -129,11 +129,11 @@ describe 'apt_key' do shell(PUPPETLABS_KEY_CHECK_COMMAND) # Time to remove it using Puppet - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND, - :acceptable_exit_codes => [1]) + acceptable_exit_codes: [1]) end end end @@ -200,17 +200,16 @@ zGioYMWgVePywFGaTV51/0uF9ymHHC7BDIcLgUWHdg/1B67jR5YQfzPJUqLhnylt } EOS - #Apply the manifest (Retry if timeout error is received from key pool) + # Apply the manifest (Retry if timeout error is received from key pool) retry_on_error_matching(MAX_TIMEOUT_RETRY, TIMEOUT_RETRY_WAIT, TIMEOUT_ERROR_MATCHER) do - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end end - context 'multiple keys' do it 'runs without errors' do pp = <<-EOS @@ -466,8 +465,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end end @@ -482,8 +481,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/no valid OpenPGP data found/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{no valid OpenPGP data found}) end end end @@ -500,12 +499,12 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - #Apply the manifest (Retry if timeout error is received from key pool) + # Apply the manifest (Retry if timeout error is received from key pool) retry_on_error_matching(MAX_TIMEOUT_RETRY, TIMEOUT_RETRY_WAIT, TIMEOUT_ERROR_MATCHER) do - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end end @@ -521,10 +520,10 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= EOS retry_on_error_matching(MAX_TIMEOUT_RETRY, TIMEOUT_RETRY_WAIT, TIMEOUT_ERROR_MATCHER) do - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end end @@ -539,8 +538,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/(Host not found|Couldn't resolve host)/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{(Host not found|Couldn't resolve host)}) end end end @@ -555,8 +554,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/Invalid value \".pgp.key.server\"/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{Invalid value \".pgp.key.server\"}) end end end @@ -573,8 +572,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end @@ -587,8 +586,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end @@ -601,8 +600,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/404 Not Found/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{404 Not Found}) end end @@ -615,8 +614,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/could not resolve/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{could not resolve}) end end end @@ -624,7 +623,7 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= context 'ftp://' do before(:each) do shell("apt-key del #{CENTOS_GPG_KEY_LONG_ID}", - :acceptable_exit_codes => [0,1,2]) + acceptable_exit_codes: [0, 1, 2]) end it 'works' do @@ -636,8 +635,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(CENTOS_KEY_CHECK_COMMAND) end @@ -650,8 +649,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/550 Failed to open/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{550 Failed to open}) end end @@ -664,8 +663,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/could not resolve/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{could not resolve}) end end end @@ -680,8 +679,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end @@ -694,8 +693,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end @@ -708,8 +707,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/404 Not Found/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{404 Not Found}) end end @@ -722,8 +721,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/could not resolve/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{could not resolve}) end end end @@ -747,8 +746,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end end @@ -763,8 +762,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/does not exist/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{does not exist}) end end end @@ -786,8 +785,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/no valid OpenPGP data found/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{no valid OpenPGP data found}) end end end @@ -804,8 +803,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) shell(PUPPETLABS_KEY_CHECK_COMMAND) end end @@ -822,8 +821,8 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end end @@ -837,11 +836,10 @@ FPfZDNCu/TXoqyJk7434jJrcHgPryzrHFBLfEmc= } EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/do not match/) + apply_manifest(pp, expect_failures: true) do |r| + expect(r.stderr).to match(%r{don't match}) end end end end - end diff --git a/spec/acceptance/apt_spec.rb b/spec/acceptance/apt_spec.rb index df312a7..e8950d1 100644 --- a/spec/acceptance/apt_spec.rb +++ b/spec/acceptance/apt_spec.rb @@ -2,10 +2,9 @@ require 'spec_helper_acceptance' MAX_TIMEOUT_RETRY = 3 TIMEOUT_RETRY_WAIT = 5 -TIMEOUT_ERROR_MATCHER = /no valid OpenPGP data found/ +TIMEOUT_ERROR_MATCHER = %r{no valid OpenPGP data found} describe 'apt class' do - context 'reset' do it 'fixes the sources.list' do shell('cp /etc/apt/sources.list /tmp') @@ -13,7 +12,7 @@ describe 'apt class' do end context 'all the things' do - it 'should work with no errors' do + it 'works with no errors' do pp = <<-EOS if $::lsbdistcodename == 'lucid' { $sources = undef @@ -46,14 +45,14 @@ describe 'apt class' do } EOS - #Apply the manifest (Retry if timeout error is received from key pool) + # Apply the manifest (Retry if timeout error is received from key pool) retry_on_error_matching(MAX_TIMEOUT_RETRY, TIMEOUT_RETRY_WAIT, TIMEOUT_ERROR_MATCHER) do - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end - it 'should still work' do + it 'stills work' do shell('apt-get update') shell('apt-get -y --force-yes upgrade') end @@ -64,5 +63,4 @@ describe 'apt class' do shell('cp /tmp/sources.list /etc/apt') end end - end diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 1539a0d..d970794 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,17 +1,16 @@ require 'spec_helper_acceptance' describe 'apt class' do - context 'default parameters' do # Using puppet_apply as a helper - it 'should work with no errors' do + it 'works with no errors' do pp = <<-EOS class { 'apt': } EOS # Run it twice and test for idempotency - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end end end diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb index f2172d9..0528831 100644 --- a/spec/classes/apt_backports_spec.rb +++ b/spec/classes/apt_backports_spec.rb @@ -1,259 +1,270 @@ -#!/usr/bin/env rspec require 'spec_helper' -describe 'apt::backports', :type => :class do +describe 'apt::backports', type: :class do let (:pre_condition) { "class{ '::apt': }" } + describe 'debian/ubuntu tests' do context 'defaults on deb' do let(:facts) do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, } end - it { is_expected.to contain_apt__source('backports').with({ - :location => 'http://deb.debian.org/debian', - :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - :repos => 'main contrib non-free', - :release => 'wheezy-backports', - :pin => { 'priority' => 200, 'release' => 'wheezy-backports' }, - }) + + it { + is_expected.to contain_apt__source('backports').with(location: 'http://deb.debian.org/debian', + key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + repos: 'main contrib non-free', + release: 'wheezy-backports', + pin: { 'priority' => 200, 'release' => 'wheezy-backports' }) } end context 'defaults on ubuntu' do let(:facts) do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistcodename => 'trusty', - :lsbdistrelease => '14.04', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + lsbdistcodename: 'trusty', + lsbdistrelease: '14.04', + puppetversion: Puppet.version, } end - it { is_expected.to contain_apt__source('backports').with({ - :location => 'http://archive.ubuntu.com/ubuntu', - :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', - :repos => 'main universe multiverse restricted', - :release => 'trusty-backports', - :pin => { 'priority' => 200, 'release' => 'trusty-backports' }, - }) + + it { + is_expected.to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5', + repos: 'main universe multiverse restricted', + release: 'trusty-backports', + pin: { 'priority' => 200, 'release' => 'trusty-backports' }) } end context 'set everything' do let(:facts) do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistcodename => 'trusty', - :lsbdistrelease => '14.04', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + lsbdistcodename: 'trusty', + lsbdistrelease: '14.04', + puppetversion: Puppet.version, } end let(:params) do { - :location => 'http://archive.ubuntu.com/ubuntu-test', - :release => 'vivid', - :repos => 'main', - :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - :pin => '90', + location: 'http://archive.ubuntu.com/ubuntu-test', + release: 'vivid', + repos: 'main', + key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + pin: '90', } end - it { is_expected.to contain_apt__source('backports').with({ - :location => 'http://archive.ubuntu.com/ubuntu-test', - :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - :repos => 'main', - :release => 'vivid', - :pin => { 'priority' => 90, 'release' => 'vivid' }, - }) + + it { + is_expected.to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu-test', + key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + repos: 'main', + release: 'vivid', + pin: { 'priority' => 90, 'release' => 'vivid' }) } end context 'set things with hashes' do let(:facts) do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistcodename => 'trusty', - :lsbdistrelease => '14.04', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + lsbdistcodename: 'trusty', + lsbdistrelease: '14.04', + puppetversion: Puppet.version, } end let(:params) do { - :key => { + key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', }, - :pin => { + pin: { 'priority' => '90', }, } end - it { is_expected.to contain_apt__source('backports').with({ - :key => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' }, - :pin => { 'priority' => '90' }, - }) + + it { + is_expected.to contain_apt__source('backports').with(key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' }, + pin: { 'priority' => '90' }) } end end describe 'mint tests' do let(:facts) do { - :os => { :family => 'Debian', :name => 'Linuxmint', :release => { :major => '17', :full => '17' }}, - :lsbdistid => 'linuxmint', - :osfamily => 'Debian', - :lsbdistcodename => 'qiana', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Linuxmint', release: { major: '17', full: '17' } }, + lsbdistid: 'linuxmint', + osfamily: 'Debian', + lsbdistcodename: 'qiana', + puppetversion: Puppet.version, } end + context 'sets all the needed things' do let(:params) do { - :location => 'http://archive.ubuntu.com/ubuntu', - :release => 'trusty-backports', - :repos => 'main universe multiverse restricted', - :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + location: 'http://archive.ubuntu.com/ubuntu', + release: 'trusty-backports', + repos: 'main universe multiverse restricted', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5', } end - it { is_expected.to contain_apt__source('backports').with({ - :location => 'http://archive.ubuntu.com/ubuntu', - :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', - :repos => 'main universe multiverse restricted', - :release => 'trusty-backports', - :pin => { 'priority' => 200, 'release' => 'trusty-backports' }, - }) + + it { + is_expected.to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5', + repos: 'main universe multiverse restricted', + release: 'trusty-backports', + pin: { 'priority' => 200, 'release' => 'trusty-backports' }) } end context 'missing location' do let(:params) do { - :release => 'trusty-backports', - :repos => 'main universe multiverse restricted', - :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + release: 'trusty-backports', + repos: 'main universe multiverse restricted', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/) + }.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) end end context 'missing release' do let(:params) do { - :location => 'http://archive.ubuntu.com/ubuntu', - :repos => 'main universe multiverse restricted', - :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + location: 'http://archive.ubuntu.com/ubuntu', + repos: 'main universe multiverse restricted', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/) + }.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) end end context 'missing repos' do let(:params) do { - :location => 'http://archive.ubuntu.com/ubuntu', - :release => 'trusty-backports', - :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + location: 'http://archive.ubuntu.com/ubuntu', + release: 'trusty-backports', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/) + }.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) end end context 'missing key' do let(:params) do { - :location => 'http://archive.ubuntu.com/ubuntu', - :release => 'trusty-backports', - :repos => 'main universe multiverse restricted', + location: 'http://archive.ubuntu.com/ubuntu', + release: 'trusty-backports', + repos: 'main universe multiverse restricted', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/) + }.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) end end end describe 'validation' do let(:facts) do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistcodename => 'trusty', - :lsbdistrelease => '14.04', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + lsbdistcodename: 'trusty', + lsbdistrelease: '14.04', + puppetversion: Puppet.version, } end + context 'invalid location' do let(:params) do { - :location => true + location: true, } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /expects a/) + }.to raise_error(Puppet::Error, %r{expects a}) end end context 'invalid release' do let(:params) do { - :release => true + release: true, } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /expects a/) + }.to raise_error(Puppet::Error, %r{expects a}) end end context 'invalid repos' do let(:params) do { - :repos => true + repos: true, } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /expects a/) + }.to raise_error(Puppet::Error, %r{expects a}) end end context 'invalid key' do let(:params) do { - :key => true + key: true, } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /expects a/) + }.to raise_error(Puppet::Error, %r{expects a}) end end context 'invalid pin' do let(:params) do { - :pin => true + pin: true, } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /expects a/) + }.to raise_error(Puppet::Error, %r{expects a}) end end end diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index cd3a6ec..e743a0d 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -1,186 +1,185 @@ require 'spec_helper' describe 'apt' do let(:facts) do - { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } end + context 'defaults' do - it { is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with({ - :ensure => 'file', - :path => '/etc/apt/sources.list', - :owner => 'root', - :group => 'root', - :mode => '0644', - :notify => 'Class[Apt::Update]', - })} - - it { is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with({ - :ensure => 'directory', - :path => '/etc/apt/sources.list.d', - :owner => 'root', - :group => 'root', - :mode => '0644', - :purge => false, - :recurse => false, - :notify => 'Class[Apt::Update]', - })} - - it { is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with({ - :ensure => 'file', - :path => '/etc/apt/preferences', - :owner => 'root', - :group => 'root', - :mode => '0644', - :notify => 'Class[Apt::Update]', - })} - - it { is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with({ - :ensure => 'directory', - :path => '/etc/apt/preferences.d', - :owner => 'root', - :group => 'root', - :mode => '0644', - :purge => false, - :recurse => false, - :notify => 'Class[Apt::Update]', - })} - - it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do - is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with({ - :group => 'root', - :mode => '0644', - :owner => 'root', - }).with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/) + it { + is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(ensure: 'file', + path: '/etc/apt/sources.list', + owner: 'root', + group: 'root', + mode: '0644', + notify: 'Class[Apt::Update]') + } + + it { + is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(ensure: 'directory', + path: '/etc/apt/sources.list.d', + owner: 'root', + group: 'root', + mode: '0644', + purge: false, + recurse: false, + notify: 'Class[Apt::Update]') + } + + it { + is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(ensure: 'file', + path: '/etc/apt/preferences', + owner: 'root', + group: 'root', + mode: '0644', + notify: 'Class[Apt::Update]') + } + + it { + is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(ensure: 'directory', + path: '/etc/apt/preferences.d', + owner: 'root', + group: 'root', + mode: '0644', + purge: false, + recurse: false, + notify: 'Class[Apt::Update]') + } + + it 'lays down /etc/apt/apt.conf.d/15update-stamp' do + is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root', + mode: '0644', + owner: 'root').with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/) # rubocop:disable Metrics/LineLength end - it { is_expected.to contain_exec('apt_update').with({ - :refreshonly => 'true', - })} + it { + is_expected.to contain_exec('apt_update').with(refreshonly: 'true') + } it { is_expected.not_to contain_apt__setting('conf-proxy') } end describe 'proxy=' do context 'host=localhost' do - let(:params) { { :proxy => { 'host' => 'localhost'} } } - it { is_expected.to contain_apt__setting('conf-proxy').with({ - :priority => '01', - }).with_content( - /Acquire::http::proxy "http:\/\/localhost:8080\/";/ - ).without_content( - /Acquire::https::proxy/ - )} + let(:params) { { proxy: { 'host' => 'localhost' } } } + + it { + is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + /Acquire::http::proxy "http:\/\/localhost:8080\/";/, + ).without_content( + %r{Acquire::https::proxy}, + ) + } end context 'host=localhost and port=8180' do - let(:params) { { :proxy => { 'host' => 'localhost', 'port' => 8180} } } - it { is_expected.to contain_apt__setting('conf-proxy').with({ - :priority => '01', - }).with_content( - /Acquire::http::proxy "http:\/\/localhost:8180\/";/ - ).without_content( - /Acquire::https::proxy/ - )} + let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } } + + it { + is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + /Acquire::http::proxy "http:\/\/localhost:8180\/";/, + ).without_content( + %r{Acquire::https::proxy}, + ) + } end context 'host=localhost and https=true' do - let(:params) { { :proxy => { 'host' => 'localhost', 'https' => true} } } - it { is_expected.to contain_apt__setting('conf-proxy').with({ - :priority => '01', - }).with_content( - /Acquire::http::proxy "http:\/\/localhost:8080\/";/ - ).with_content( - /Acquire::https::proxy "https:\/\/localhost:8080\/";/ - )} + let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } } + + it { + is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + /Acquire::http::proxy "http:\/\/localhost:8080\/";/, + ).with_content( + /Acquire::https::proxy "https:\/\/localhost:8080\/";/, + ) + } end context 'ensure=absent' do - let(:params) { { :proxy => { 'ensure' => 'absent'} } } - it { is_expected.to contain_apt__setting('conf-proxy').with({ - :ensure => 'absent', - :priority => '01', - })} + let(:params) { { proxy: { 'ensure' => 'absent' } } } + + it { + is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent', + priority: '01') + } end end context 'lots of non-defaults' do let :params do { - :update => { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 }, - :purge => { 'sources.list' => false, 'sources.list.d' => false, - 'preferences' => false, 'preferences.d' => false, }, + update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 }, + purge: { 'sources.list' => false, 'sources.list.d' => false, + 'preferences' => false, 'preferences.d' => false }, } end - it { is_expected.to contain_file('sources.list').with({ - :content => nil, - })} - - it { is_expected.to contain_file('sources.list.d').with({ - :purge => false, - :recurse => false, - })} + it { + is_expected.to contain_file('sources.list').with(content: nil) + } - it { is_expected.to contain_file('preferences').with({ - :ensure => 'file', - })} + it { + is_expected.to contain_file('sources.list.d').with(purge: false, + recurse: false) + } - it { is_expected.to contain_file('preferences.d').with({ - :purge => false, - :recurse => false, - })} + it { + is_expected.to contain_file('preferences').with(ensure: 'file') + } - it { is_expected.to contain_exec('apt_update').with({ - :refreshonly => false, - :timeout => 1, - :tries => 3, - })} + it { + is_expected.to contain_file('preferences.d').with(purge: false, + recurse: false) + } + it { + is_expected.to contain_exec('apt_update').with(refreshonly: false, + timeout: 1, + tries: 3) + } end context 'with sources defined on valid osfamily' do let :facts do - { :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '12', :full => '12.04' }}, - :osfamily => 'Debian', - :lsbdistcodename => 'precise', - :lsbdistid => 'Ubuntu', - :lsbdistrelease => '12.04', - :puppetversion => Puppet.version, - } + { os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04' } }, + osfamily: 'Debian', + lsbdistcodename: 'precise', + lsbdistid: 'Ubuntu', + lsbdistrelease: '12.04', + puppetversion: Puppet.version } + end + let(:params) do + { sources: { + 'debian_unstable' => { + 'location' => 'http://debian.mirror.iweb.ca/debian/', + 'release' => 'unstable', + 'repos' => 'main contrib non-free', + 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' }, + 'pin' => '-10', + 'include' => { 'src' => true }, + }, + 'puppetlabs' => { + 'location' => 'http://apt.puppetlabs.com', + 'repos' => 'main', + 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' }, + }, + } } end - let(:params) { { :sources => { - 'debian_unstable' => { - 'location' => 'http://debian.mirror.iweb.ca/debian/', - 'release' => 'unstable', - 'repos' => 'main contrib non-free', - 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' }, - 'pin' => '-10', - 'include' => {'src' => true,}, - }, - 'puppetlabs' => { - 'location' => 'http://apt.puppetlabs.com', - 'repos' => 'main', - 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' }, - } - } } } it { - is_expected.to contain_apt__setting('list-debian_unstable').with({ - :ensure => 'present', - }) + is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present') } it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } it { - is_expected.to contain_apt__setting('list-puppetlabs').with({ - :ensure => 'present', - }) + is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present') } it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } @@ -189,112 +188,122 @@ describe 'apt' do context 'with confs defined on valid osfamily' do let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '12', :full => '12.04.5' }}, - :osfamily => 'Debian', - :lsbdistcodename => 'precise', - :lsbdistid => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } }, + osfamily: 'Debian', + lsbdistcodename: 'precise', + lsbdistid: 'Debian', + puppetversion: Puppet.version, } end - let(:params) { { :confs => { - 'foo' => { - 'content' => 'foo', - }, - 'bar' => { - 'content' => 'bar', - } - } } } + let(:params) do + { confs: { + 'foo' => { + 'content' => 'foo', + }, + 'bar' => { + 'content' => 'bar', + }, + } } + end - it { is_expected.to contain_apt__conf('foo').with({ - :content => 'foo', - })} + it { + is_expected.to contain_apt__conf('foo').with(content: 'foo') + } - it { is_expected.to contain_apt__conf('bar').with({ - :content => 'bar', - })} + it { + is_expected.to contain_apt__conf('bar').with(content: 'bar') + } end context 'with keys defined on valid osfamily' do let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '12', :full => '12.04.5' }}, - :osfamily => 'Debian', - :lsbdistcodename => 'precise', - :lsbdistid => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } }, + osfamily: 'Debian', + lsbdistcodename: 'precise', + lsbdistid: 'Debian', + puppetversion: Puppet.version, } end - let(:params) { { :keys => { - '55BE302B' => { - 'server' => 'subkeys.pgp.net', - }, - 'EF8D349F' => { - 'server' => 'pgp.mit.edu', - } - } } } + let(:params) do + { keys: { + '55BE302B' => { + 'server' => 'subkeys.pgp.net', + }, + 'EF8D349F' => { + 'server' => 'pgp.mit.edu', + }, + } } + end - it { is_expected.to contain_apt__key('55BE302B').with({ - :server => 'subkeys.pgp.net', - })} + it { + is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net') + } - it { is_expected.to contain_apt__key('EF8D349F').with({ - :server => 'pgp.mit.edu', - })} + it { + is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu') + } end context 'with ppas defined on valid osfamily' do let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '12', :full => '12.04.5' }}, - :osfamily => 'Debian', - :lsbdistcodename => 'precise', - :lsbdistid => 'ubuntu', - :lsbdistrelease => '12.04', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } }, + osfamily: 'Debian', + lsbdistcodename: 'precise', + lsbdistid: 'ubuntu', + lsbdistrelease: '12.04', + puppetversion: Puppet.version, } end - let(:params) { { :ppas => { - 'ppa:drizzle-developers/ppa' => {}, - 'ppa:nginx/stable' => {}, - } } } + let(:params) do + { ppas: { + 'ppa:drizzle-developers/ppa' => {}, + 'ppa:nginx/stable' => {}, + } } + end - it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa')} - it { is_expected.to contain_apt__ppa('ppa:nginx/stable')} + it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') } + it { is_expected.to contain_apt__ppa('ppa:nginx/stable') } end context 'with settings defined on valid osfamily' do let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '12', :full => '12.04.5' }}, - :osfamily => 'Debian', - :lsbdistcodename => 'precise', - :lsbdistid => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } }, + osfamily: 'Debian', + lsbdistcodename: 'precise', + lsbdistid: 'Debian', + puppetversion: Puppet.version, } end - let(:params) { { :settings => { - 'conf-banana' => { 'content' => 'banana' }, - 'pref-banana' => { 'content' => 'banana' }, - } } } + let(:params) do + { settings: { + 'conf-banana' => { 'content' => 'banana' }, + 'pref-banana' => { 'content' => 'banana' }, + } } + end - it { is_expected.to contain_apt__setting('conf-banana')} - it { is_expected.to contain_apt__setting('pref-banana')} + it { is_expected.to contain_apt__setting('conf-banana') } + it { is_expected.to contain_apt__setting('pref-banana') } end context 'with pins defined on valid osfamily' do let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '12', :full => '12.04.5' }}, - :osfamily => 'Debian', - :lsbdistcodename => 'precise', - :lsbdistid => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '12', full: '12.04.5' } }, + osfamily: 'Debian', + lsbdistcodename: 'precise', + lsbdistid: 'Debian', + puppetversion: Puppet.version, } end - let(:params) { { :pins => { - 'stable' => { 'priority' => 600, 'order' => 50 }, - 'testing' => { 'priority' => 700, 'order' => 100 }, - } } } + let(:params) do + { pins: { + 'stable' => { 'priority' => 600, 'order' => 50 }, + 'testing' => { 'priority' => 700, 'order' => 100 }, + } } + end it { is_expected.to contain_apt__pin('stable') } it { is_expected.to contain_apt__pin('testing') } @@ -302,7 +311,8 @@ describe 'apt' do describe 'failing tests' do context "purge['sources.list']=>'banana'" do - let(:params) { { :purge => { 'sources.list' => 'banana' }, } } + let(:params) { { purge: { 'sources.list' => 'banana' } } } + it do expect { subject.call @@ -311,7 +321,8 @@ describe 'apt' do end context "purge['sources.list.d']=>'banana'" do - let(:params) { { :purge => { 'sources.list.d' => 'banana' }, } } + let(:params) { { purge: { 'sources.list.d' => 'banana' } } } + it do expect { subject.call @@ -320,7 +331,8 @@ describe 'apt' do end context "purge['preferences']=>'banana'" do - let(:params) { { :purge => { 'preferences' => 'banana' }, } } + let(:params) { { purge: { 'preferences' => 'banana' } } } + it do expect { subject.call @@ -329,7 +341,8 @@ describe 'apt' do end context "purge['preferences.d']=>'banana'" do - let(:params) { { :purge => { 'preferences.d' => 'banana' }, } } + let(:params) { { purge: { 'preferences.d' => 'banana' } } } + it do expect { subject.call diff --git a/spec/classes/apt_update_spec.rb b/spec/classes/apt_update_spec.rb index bc199f8..e178d40 100644 --- a/spec/classes/apt_update_spec.rb +++ b/spec/classes/apt_update_spec.rb @@ -1,130 +1,151 @@ #!/usr/bin/env rspec require 'spec_helper' -describe 'apt::update', :type => :class do +describe 'apt::update', type: :class do context "and apt::update['frequency']='always'" do { 'a recent run' => Time.now.to_i, - 'we are due for a run' => 1406660561, + 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1, }.each_pair do |desc, factval| context "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :apt_update_last_success => factval, - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } - let (:pre_condition) { + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + apt_update_last_success: factval, + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end + let (:pre_condition) do "class{'::apt': update => {'frequency' => 'always' },}" - } - it 'should trigger an apt-get update run' do - #set the apt_update exec's refreshonly attribute to false - is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) + end + + it 'triggers an apt-get update run' do + # set the apt_update exec's refreshonly attribute to false + is_expected.to contain_exec('apt_update').with('refreshonly' => false) end end end context 'when $::apt_update_last_success is nil' do - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" } - it 'should trigger an apt-get update run' do - #set the apt_update exec\'s refreshonly attribute to false - is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) + + it 'triggers an apt-get update run' do + # set the apt_update exec\'s refreshonly attribute to false + is_expected.to contain_exec('apt_update').with('refreshonly' => false) end end end context "and apt::update['frequency']='reluctantly'" do { 'a recent run' => Time.now.to_i, - 'we are due for a run' => 1406660561, + 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1, }.each_pair do |desc, factval| context "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :apt_update_last_success => factval, - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + apt_update_last_success: factval, + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" } - it 'should not trigger an apt-get update run' do - #don't change the apt_update exec's refreshonly attribute. (it should be true) - is_expected.to contain_exec('apt_update').with({'refreshonly' => true}) + + it 'does not trigger an apt-get update run' do + # don't change the apt_update exec's refreshonly attribute. (it should be true) + is_expected.to contain_exec('apt_update').with('refreshonly' => true) end end end context 'when $::apt_update_last_success is nil' do - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" } - it 'should not trigger an apt-get update run' do - #don't change the apt_update exec's refreshonly attribute. (it should be true) - is_expected.to contain_exec('apt_update').with({'refreshonly' => true}) + + it 'does not trigger an apt-get update run' do + # don't change the apt_update exec's refreshonly attribute. (it should be true) + is_expected.to contain_exec('apt_update').with('refreshonly' => true) end end end - ['daily','weekly'].each do |update_frequency| + %w[daily weekly].each do |update_frequency| context "and apt::update['frequency'] has the value of #{update_frequency}" do - { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| + { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| context "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :apt_update_last_success => factval, - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + apt_update_last_success: factval, + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } - it 'should trigger an apt-get update run' do - #set the apt_update exec\'s refreshonly attribute to false - is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) + + it 'triggers an apt-get update run' do + # set the apt_update exec\'s refreshonly attribute to false + is_expected.to contain_exec('apt_update').with('refreshonly' => false) end end end context 'when the $::apt_update_last_success fact has a recent value' do - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :apt_update_last_success => Time.now.to_i, - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + apt_update_last_success: Time.now.to_i, + puppetversion: Puppet.version, + } + end let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } - it 'should not trigger an apt-get update run' do - #don't change the apt_update exec\'s refreshonly attribute. (it should be true) - is_expected.to contain_exec('apt_update').with({'refreshonly' => true}) + + it 'does not trigger an apt-get update run' do + # don't change the apt_update exec\'s refreshonly attribute. (it should be true) + is_expected.to contain_exec('apt_update').with('refreshonly' => true) end end context 'when $::apt_update_last_success is nil' do - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :apt_update_last_success => nil, - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + apt_update_last_success: nil, + puppetversion: Puppet.version, + } + end let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } - it 'should trigger an apt-get update run' do - #set the apt_update exec\'s refreshonly attribute to false - is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) + + it 'triggers an apt-get update run' do + # set the apt_update exec\'s refreshonly attribute to false + is_expected.to contain_exec('apt_update').with('refreshonly' => false) end end end diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb index 16507c2..1296e99 100644 --- a/spec/defines/conf_spec.rb +++ b/spec/defines/conf_spec.rb @@ -1,24 +1,26 @@ require 'spec_helper' -describe 'apt::conf', :type => :define do +describe 'apt::conf', type: :define do let :pre_condition do 'class { "apt": }' end - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end let :title do 'norecommends' end - describe "when creating an apt preference" do + describe 'when creating an apt preference' do let :default_params do { - :priority => '00', - :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n" + priority: '00', + content: "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n", } end let :params do @@ -26,65 +28,63 @@ describe 'apt::conf', :type => :define do end let :filename do - "/etc/apt/apt.conf.d/00norecommends" + '/etc/apt/apt.conf.d/00norecommends' end - it { is_expected.to contain_file(filename).with({ - 'ensure' => 'present', - 'content' => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/, - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + it { + is_expected.to contain_file(filename).with('ensure' => 'present', + 'content' => %r{Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;}, + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644') + } - context "with notify_update = true (default)" do + context 'with notify_update = true (default)' do let :params do default_params end + it { is_expected.to contain_apt__setting("conf-#{title}").with_notify_update(true) } end - context "with notify_update = false" do + context 'with notify_update = false' do let :params do - default_params.merge({ - :notify_update => false - }) + default_params.merge(notify_update: false) end + it { is_expected.to contain_apt__setting("conf-#{title}").with_notify_update(false) } end end - describe "when creating a preference without content" do + describe 'when creating a preference without content' do let :params do { - :priority => '00', + priority: '00', } end it 'fails' do - expect { subject.call } .to raise_error(/pass in content/) + expect { subject.call } .to raise_error(%r{pass in content}) end end - describe "when removing an apt preference" do + describe 'when removing an apt preference' do let :params do { - :ensure => 'absent', - :priority => '00', + ensure: 'absent', + priority: '00', } end let :filename do - "/etc/apt/apt.conf.d/00norecommends" + '/etc/apt/apt.conf.d/00norecommends' end - it { is_expected.to contain_file(filename).with({ - 'ensure' => 'absent', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) + it { + is_expected.to contain_file(filename).with('ensure' => 'absent', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644') } end end diff --git a/spec/defines/key_compat_spec.rb b/spec/defines/key_compat_spec.rb index dab9d16..2d02bed 100644 --- a/spec/defines/key_compat_spec.rb +++ b/spec/defines/key_compat_spec.rb @@ -1,13 +1,15 @@ require 'spec_helper' -describe 'apt::key', :type => :define do - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :puppetversion => Puppet.version, - } } - GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F' +describe 'apt::key', type: :define do + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + puppetversion: Puppet.version, + } + end + GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze let :title do GPG_KEY_ID @@ -20,13 +22,11 @@ describe 'apt::key', :type => :define do describe 'normal operation' do describe 'default options' do it { - is_expected.to contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => nil, - :server => 'keyserver.ubuntu.com', - :content => nil, - }) + is_expected.to contain_apt_key(title).with(id: title, + ensure: 'present', + source: nil, + server: 'keyserver.ubuntu.com', + content: nil) } it 'contains the apt_key present anchor' do is_expected.to contain_anchor("apt_key #{title} present") @@ -38,18 +38,18 @@ describe 'apt::key', :type => :define do 'puppetlabs' end - let :params do { - :id => GPG_KEY_ID, - } end + let :params do + { + id: GPG_KEY_ID, + } + end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => GPG_KEY_ID, - :ensure => 'present', - :source => nil, - :server => 'keyserver.ubuntu.com', - :content => nil, - }) + is_expected.to contain_apt_key(title).with(id: GPG_KEY_ID, + ensure: 'present', + source: nil, + server: 'keyserver.ubuntu.com', + content: nil) end it 'contains the apt_key present anchor' do is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present") @@ -57,18 +57,18 @@ describe 'apt::key', :type => :define do end describe 'ensure => absent' do - let :params do { - :ensure => 'absent', - } end + let :params do + { + ensure: 'absent', + } + end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :ensure => 'absent', - :source => nil, - :server => 'keyserver.ubuntu.com', - :content => nil, - }) + is_expected.to contain_apt_key(title).with(id: title, + ensure: 'absent', + source: nil, + server: 'keyserver.ubuntu.com', + content: nil) end it 'contains the apt_key absent anchor' do is_expected.to contain_anchor("apt_key #{title} absent") @@ -76,206 +76,236 @@ describe 'apt::key', :type => :define do end describe 'set a bunch of things!' do - let :params do { - :content => 'GPG key content', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :server => 'pgp.mit.edu', - :options => 'debug', - } end + let :params do + { + content: 'GPG key content', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + server: 'pgp.mit.edu', + options: 'debug', + } + end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :server => 'pgp.mit.edu', - :content => params[:content], - :options => 'debug', - }) + is_expected.to contain_apt_key(title).with(id: title, + ensure: 'present', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + server: 'pgp.mit.edu', + content: params[:content], + options: 'debug') end it 'contains the apt_key present anchor' do is_expected.to contain_anchor("apt_key #{title} present") end end - context "domain with dash" do - let(:params) do{ - :server => 'p-gp.m-it.edu', - } end + context 'domain with dash' do + let(:params) do + { + server: 'p-gp.m-it.edu', + } + end + it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :server => 'p-gp.m-it.edu', - }) + is_expected.to contain_apt_key(title).with(id: title, + server: 'p-gp.m-it.edu') end end - context "url" do + context 'url' do let :params do { - :server => 'hkp://pgp.mit.edu', + server: 'hkp://pgp.mit.edu', } end + it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :server => 'hkp://pgp.mit.edu', - }) + is_expected.to contain_apt_key(title).with(id: title, + server: 'hkp://pgp.mit.edu') end end - context "url with port number" do + context 'url with port number' do let :params do { - :server => 'hkp://pgp.mit.edu:80', + server: 'hkp://pgp.mit.edu:80', } end + it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :server => 'hkp://pgp.mit.edu:80', - }) + is_expected.to contain_apt_key(title).with(id: title, + server: 'hkp://pgp.mit.edu:80') end end end describe 'validation' do - context "domain begin with dash" do - let(:params) do{ - :server => '-pgp.mit.edu', - } end + context 'domain begin with dash' do + let(:params) do + { + server: '-pgp.mit.edu', + } + end + it 'fails' do - expect { subject.call } .to raise_error(/does not match/) + expect { subject.call } .to raise_error(%r{does not match}) end end - context "domain begin with dot" do - let(:params) do{ - :server => '.pgp.mit.edu', - } end + context 'domain begin with dot' do + let(:params) do + { + server: '.pgp.mit.edu', + } + end + it 'fails' do - expect { subject.call } .to raise_error(/does not match/) + expect { subject.call } .to raise_error(%r{does not match}) end end - context "domain end with dot" do - let(:params) do{ - :server => "pgp.mit.edu.", - } end + context 'domain end with dot' do + let(:params) do + { + server: 'pgp.mit.edu.', + } + end + it 'fails' do - expect { subject.call } .to raise_error(/does not match/) + expect { subject.call } .to raise_error(%r{does not match}) end end - context "exceed character url" do + context 'exceed character url' do let :params do { - :server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' + server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "incorrect port number url" do + context 'incorrect port number url' do let :params do { - :server => 'hkp://pgp.mit.edu:8008080' + server: 'hkp://pgp.mit.edu:8008080', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "incorrect protocol for url" do + context 'incorrect protocol for url' do let :params do { - :server => 'abc://pgp.mit.edu:80' + server: 'abc://pgp.mit.edu:80', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "missing port number url" do + context 'missing port number url' do let :params do { - :server => 'hkp://pgp.mit.edu:' + server: 'hkp://pgp.mit.edu:', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "url ending with a dot" do + context 'url ending with a dot' do let :params do { - :server => 'hkp://pgp.mit.edu.' + server: 'hkp://pgp.mit.edu.', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "url begin with a dash" do - let(:params) do{ - :server => "hkp://-pgp.mit.edu", - } end + context 'url begin with a dash' do + let(:params) do + { + server: 'hkp://-pgp.mit.edu', + } + end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end context 'invalid key' do let :title do 'Out of rum. Why? Why are we out of rum?' end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end context 'invalid source' do - let :params do { - :source => 'afp://puppetlabs.com/key.gpg', - } end + let :params do + { + source: 'afp://puppetlabs.com/key.gpg', + } + end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end context 'invalid content' do - let :params do { - :content => [], - } end + let :params do + { + content: [], + } + end + it 'fails' do - expect { subject.call }.to raise_error(/expects a/) + expect { subject.call }.to raise_error(%r{expects a}) end end context 'invalid server' do - let :params do { - :server => 'two bottles of rum', - } end + let :params do + { + server: 'two bottles of rum', + } + end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end context 'invalid keyserver_options' do - let :params do { - :options => {}, - } end + let :params do + { + options: {}, + } + end + it 'fails' do - expect { subject.call }.to raise_error(/expects a/) + expect { subject.call }.to raise_error(%r{expects a}) end end context 'invalid ensure' do let :params do { - :ensure => 'foo', + ensure: 'foo', } end + it 'fails' do - expect { subject.call }.to raise_error(/Enum\['absent', 'present'\]/) + expect { subject.call }.to raise_error(%r{Enum\['absent', 'present'\]}) end end @@ -286,28 +316,22 @@ describe 'apt::key', :type => :define do end it 'contains the duplicate apt::key resource' do - is_expected.to contain_apt__key('duplicate').with({ - :id => title, - :ensure => 'present', - }) + is_expected.to contain_apt__key('duplicate').with(id: title, + ensure: 'present') end it 'contains the original apt::key resource' do - is_expected.to contain_apt__key(title).with({ - :id => title, - :ensure => 'present', - }) + is_expected.to contain_apt__key(title).with(id: title, + ensure: 'present') end it 'contains the native apt_key' do - is_expected.to contain_apt_key('duplicate').with({ - :id => title, - :ensure => 'present', - :source => nil, - :server => 'keyserver.ubuntu.com', - :content => nil, - :keyserver_options => nil, - }) + is_expected.to contain_apt_key('duplicate').with(id: title, + ensure: 'present', + source: nil, + server: 'keyserver.ubuntu.com', + content: nil, + keyserver_options: nil) end it 'does not contain the original apt_key' do @@ -319,8 +343,9 @@ describe 'apt::key', :type => :define do let :pre_condition do "#{super()}\napt::key { 'duplicate': id => '#{title}', ensure => 'absent', }" end + it 'informs the user of the impossibility' do - expect { subject.call }.to raise_error(/already ensured as absent/) + expect { subject.call }.to raise_error(%r{already ensured as absent}) end end end diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb index 334924d..ce433a3 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -5,15 +5,17 @@ describe 'apt::key' do 'class { "apt": }' end - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end - GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F' + GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze let :title do GPG_KEY_ID @@ -22,14 +24,12 @@ describe 'apt::key' do describe 'normal operation' do describe 'default options' do it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => nil, - :server => 'keyserver.ubuntu.com', - :content => nil, - :options => nil, - }) + is_expected.to contain_apt_key(title).with(id: title, + ensure: 'present', + source: nil, + server: 'keyserver.ubuntu.com', + content: nil, + options: nil) end it 'contains the apt_key present anchor' do is_expected.to contain_anchor("apt_key #{title} present") @@ -41,19 +41,19 @@ describe 'apt::key' do 'puppetlabs' end - let :params do { - :id => GPG_KEY_ID, - } end + let :params do + { + id: GPG_KEY_ID, + } + end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => GPG_KEY_ID, - :ensure => 'present', - :source => nil, - :server => 'keyserver.ubuntu.com', - :content => nil, - :options => nil, - }) + is_expected.to contain_apt_key(title).with(id: GPG_KEY_ID, + ensure: 'present', + source: nil, + server: 'keyserver.ubuntu.com', + content: nil, + options: nil) end it 'contains the apt_key present anchor' do is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present") @@ -61,19 +61,19 @@ describe 'apt::key' do end describe 'ensure => absent' do - let :params do { - :ensure => 'absent', - } end + let :params do + { + ensure: 'absent', + } + end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :ensure => 'absent', - :source => nil, - :server => 'keyserver.ubuntu.com', - :content => nil, - :keyserver => nil, - }) + is_expected.to contain_apt_key(title).with(id: title, + ensure: 'absent', + source: nil, + server: 'keyserver.ubuntu.com', + content: nil, + keyserver: nil) end it 'contains the apt_key absent anchor' do is_expected.to contain_anchor("apt_key #{title} absent") @@ -81,207 +81,237 @@ describe 'apt::key' do end describe 'set a bunch of things!' do - let :params do { - :content => 'GPG key content', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :server => 'pgp.mit.edu', - :options => 'debug', - } end + let :params do + { + content: 'GPG key content', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + server: 'pgp.mit.edu', + options: 'debug', + } + end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :server => 'pgp.mit.edu', - :content => params[:content], - :options => 'debug', - }) + is_expected.to contain_apt_key(title).with(id: title, + ensure: 'present', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + server: 'pgp.mit.edu', + content: params[:content], + options: 'debug') end it 'contains the apt_key present anchor' do is_expected.to contain_anchor("apt_key #{title} present") end end - context "domain with dash" do - let(:params) do{ - :server => 'p-gp.m-it.edu', - } end + context 'domain with dash' do + let(:params) do + { + server: 'p-gp.m-it.edu', + } + end + it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :server => 'p-gp.m-it.edu', - }) + is_expected.to contain_apt_key(title).with(id: title, + server: 'p-gp.m-it.edu') end end - context "url" do + context 'url' do let :params do { - :server => 'hkp://pgp.mit.edu', + server: 'hkp://pgp.mit.edu', } end + it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :server => 'hkp://pgp.mit.edu', - }) + is_expected.to contain_apt_key(title).with(id: title, + server: 'hkp://pgp.mit.edu') end end - context "url with port number" do + context 'url with port number' do let :params do { - :server => 'hkp://pgp.mit.edu:80', + server: 'hkp://pgp.mit.edu:80', } end + it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with({ - :id => title, - :server => 'hkp://pgp.mit.edu:80', - }) + is_expected.to contain_apt_key(title).with(id: title, + server: 'hkp://pgp.mit.edu:80') end end end describe 'validation' do - context "domain begin with dash" do - let(:params) do{ - :server => '-pgp.mit.edu', - } end + context 'domain begin with dash' do + let(:params) do + { + server: '-pgp.mit.edu', + } + end + it 'fails' do - expect { subject.call } .to raise_error(/does not match/) + expect { subject.call } .to raise_error(%r{does not match}) end end - context "domain begin with dot" do - let(:params) do{ - :server => '.pgp.mit.edu', - } end + context 'domain begin with dot' do + let(:params) do + { + server: '.pgp.mit.edu', + } + end + it 'fails' do - expect { subject.call } .to raise_error(/does not match/) + expect { subject.call } .to raise_error(%r{does not match}) end end - context "domain end with dot" do - let(:params) do{ - :server => "pgp.mit.edu.", - } end + context 'domain end with dot' do + let(:params) do + { + server: 'pgp.mit.edu.', + } + end + it 'fails' do - expect { subject.call } .to raise_error(/does not match/) + expect { subject.call } .to raise_error(%r{does not match}) end end - context "exceed character url" do + context 'exceed character url' do let :params do { - :server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' + server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "incorrect port number url" do + context 'incorrect port number url' do let :params do { - :server => 'hkp://pgp.mit.edu:8008080' + server: 'hkp://pgp.mit.edu:8008080', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "incorrect protocol for url" do + context 'incorrect protocol for url' do let :params do { - :server => 'abc://pgp.mit.edu:80' + server: 'abc://pgp.mit.edu:80', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "missing port number url" do + context 'missing port number url' do let :params do { - :server => 'hkp://pgp.mit.edu:' + server: 'hkp://pgp.mit.edu:', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "url ending with a dot" do + context 'url ending with a dot' do let :params do { - :server => 'hkp://pgp.mit.edu.' + server: 'hkp://pgp.mit.edu.', } end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end - context "url begin with a dash" do - let(:params) do{ - :server => "hkp://-pgp.mit.edu", - } end + context 'url begin with a dash' do + let(:params) do + { + server: 'hkp://-pgp.mit.edu', + } + end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end context 'invalid key' do let :title do 'Out of rum. Why? Why are we out of rum?' end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end context 'invalid source' do - let :params do { - :source => 'afp://puppetlabs.com/key.gpg', - } end + let :params do + { + source: 'afp://puppetlabs.com/key.gpg', + } + end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end context 'invalid content' do - let :params do { - :content => [], - } end + let :params do + { + content: [], + } + end + it 'fails' do - expect { subject.call }.to raise_error(/expects a/) + expect { subject.call }.to raise_error(%r{expects a}) end end context 'invalid server' do - let :params do { - :server => 'two bottles of rum', - } end + let :params do + { + server: 'two bottles of rum', + } + end + it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(%r{does not match}) end end context 'invalid options' do - let :params do { - :options => {}, - } end + let :params do + { + options: {}, + } + end + it 'fails' do - expect { subject.call }.to raise_error(/expects a/) + expect { subject.call }.to raise_error(%r{expects a}) end end context 'invalid ensure' do - %w(foo aabsent absenta apresent presenta).each do |param| + %w[foo aabsent absenta apresent presenta].each do |param| let :params do { - :ensure => param, + ensure: param, } - end + end + it 'fails' do - expect { subject.call }.to raise_error(/for Enum\['absent', 'present'\], got/) + expect { subject.call }.to raise_error(%r{for Enum\['absent', 'present'\], got}) end end end @@ -294,25 +324,19 @@ describe 'apt::key' do end it 'contains two apt::key resources' do - is_expected.to contain_apt__key('duplicate').with({ - :id => title, - :ensure => 'present', - }) - is_expected.to contain_apt__key(title).with({ - :id => title, - :ensure => 'present', - }) + is_expected.to contain_apt__key('duplicate').with(id: title, + ensure: 'present') + is_expected.to contain_apt__key(title).with(id: title, + ensure: 'present') end it 'contains only a single apt_key' do - is_expected.to contain_apt_key('duplicate').with({ - :id => title, - :ensure => 'present', - :source => nil, - :server => 'keyserver.ubuntu.com', - :content => nil, - :options => nil, - }) + is_expected.to contain_apt_key('duplicate').with(id: title, + ensure: 'present', + source: nil, + server: 'keyserver.ubuntu.com', + content: nil, + options: nil) is_expected.not_to contain_apt_key(title) end end @@ -322,8 +346,9 @@ describe 'apt::key' do "class { 'apt': } apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }" end + it 'informs the user of the impossibility' do - expect { subject.call }.to raise_error(/already ensured as absent/) + expect { subject.call }.to raise_error(%r{already ensured as absent}) end end end diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index 50890fc..a01a919 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -1,29 +1,32 @@ require 'spec_helper' -describe 'apt::pin', :type => :define do +describe 'apt::pin', type: :define do let :pre_condition do 'class { "apt": }' end - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end let(:title) { 'my_pin' } context 'defaults' do - it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)} + it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n}) } end context 'set version' do let :params do { 'packages' => 'vim', - 'version' => "1", + 'version' => '1', } end - it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)} + + it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n}) } end context 'set origin' do @@ -33,7 +36,8 @@ describe 'apt::pin', :type => :define do 'origin' => 'test', } end - it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)} + + it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n}) } end context 'not defaults' do @@ -50,28 +54,29 @@ describe 'apt::pin', :type => :define do 'priority' => 10, } end - it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) } - it { is_expected.to contain_apt__setting("pref-my_pin").with({ - 'priority' => 99, - }) + + it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n}) } + it { + is_expected.to contain_apt__setting('pref-my_pin').with('priority' => 99) } end context 'ensure absent' do let :params do { - 'ensure' => 'absent' + 'ensure' => 'absent', } end - it { is_expected.to contain_apt__setting("pref-my_pin").with({ - 'ensure' => 'absent', - }) + + it { + is_expected.to contain_apt__setting('pref-my_pin').with('ensure' => 'absent') } end context 'bad characters' do let(:title) { 'such bad && wow!' } - it { is_expected.to contain_apt__setting("pref-such__bad____wow_") } + + it { is_expected.to contain_apt__setting('pref-such__bad____wow_') } end describe 'validation' do @@ -81,10 +86,11 @@ describe 'apt::pin', :type => :define do 'order' => 'foo', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /expects an Integer value, got String/) + }.to raise_error(Puppet::Error, %r{expects an Integer value, got String}) end end @@ -94,10 +100,11 @@ describe 'apt::pin', :type => :define do 'version' => '1', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /parameter version cannot be used in general form/) + }.to raise_error(Puppet::Error, %r{parameter version cannot be used in general form}) end end @@ -108,10 +115,11 @@ describe 'apt::pin', :type => :define do 'release' => 'foo', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /parameters release and origin are mutually exclusive/) + }.to raise_error(Puppet::Error, %r{parameters release and origin are mutually exclusive}) end end @@ -123,10 +131,11 @@ describe 'apt::pin', :type => :define do 'packages' => 'vim', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/) + }.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) end end @@ -138,10 +147,11 @@ describe 'apt::pin', :type => :define do 'packages' => 'vim', } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/) + }.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) end end end diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index f95776f..89e5b36 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -7,49 +7,49 @@ describe 'apt::ppa' do describe 'defaults' do let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }}, - :lsbdistrelease => '11.04', - :lsbdistcodename => 'natty', - :operatingsystem => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } }, + lsbdistrelease: '11.04', + lsbdistcodename: 'natty', + operatingsystem: 'Ubuntu', + osfamily: 'Debian', + lsbdistid: 'Ubuntu', + puppetversion: Puppet.version, } end let(:title) { 'ppa:needs/such.substitution/wow+type' } - it { is_expected.to_not contain_package('python-software-properties') } - it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with({ - :environment => [], - :command => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type', - :unless => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-natty.list', - :user => 'root', - :logoutput => 'on_failure', - }) + + it { is_expected.not_to contain_package('python-software-properties') } + it { + is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with(environment: [], + command: '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type', # rubocop:disable Metrics/LineLength + unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-natty.list', # rubocop:disable Metrics/LineLength + user: 'root', + logoutput: 'on_failure') } end describe 'Ubuntu 15.10 sources.list filename' do let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '15', :full => '15.10' }}, - :lsbdistrelease => '15.10', - :lsbdistcodename => 'wily', - :operatingsystem => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '15', full: '15.10' } }, + lsbdistrelease: '15.10', + lsbdistcodename: 'wily', + operatingsystem: 'Ubuntu', + osfamily: 'Debian', + lsbdistid: 'Ubuntu', + puppetversion: Puppet.version, } end let(:title) { 'ppa:user/foo' } - it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({ - :environment => [], - :command => '/usr/bin/add-apt-repository -y ppa:user/foo', - :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list', - :user => 'root', - :logoutput => 'on_failure', - }) + + it { + is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [], + command: '/usr/bin/add-apt-repository -y ppa:user/foo', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list', + user: 'root', + logoutput: 'on_failure') } end @@ -65,36 +65,35 @@ describe 'apt::ppa' do end let :params do { - :package_name => 'software-properties-common', - :package_manage => true, + package_name: 'software-properties-common', + package_manage: true, } end let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }}, - :lsbdistrelease => '11.04', - :lsbdistcodename => 'natty', - :operatingsystem => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } }, + lsbdistrelease: '11.04', + lsbdistcodename: 'natty', + operatingsystem: 'Ubuntu', + osfamily: 'Debian', + lsbdistid: 'Ubuntu', + puppetversion: Puppet.version, } end let(:title) { 'ppa:needs/such.substitution/wow' } + it { is_expected.to contain_package('software-properties-common') } - it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with({ - 'environment' => [], - 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list', - 'user' => 'root', - 'logoutput' => 'on_failure', - }) + it { + is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [], + 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', # rubocop:disable Metrics/LineLength + 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list', # rubocop:disable Metrics/LineLength + 'user' => 'root', + 'logoutput' => 'on_failure') } - it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({ - 'ensure' => 'file', - }) + it { + is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file') } end @@ -107,35 +106,34 @@ describe 'apt::ppa' do end let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }}, - :lsbdistrelease => '11.04', - :lsbdistcodename => 'natty', - :operatingsystem => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } }, + lsbdistrelease: '11.04', + lsbdistcodename: 'natty', + operatingsystem: 'Ubuntu', + osfamily: 'Debian', + lsbdistid: 'Ubuntu', + puppetversion: Puppet.version, } end let :params do { - :package_manage => true, + package_manage: true, } end let(:title) { 'ppa:user/bar' } + it { is_expected.to contain_package('python-software-properties') } - it { is_expected.to contain_exec('add-apt-repository-ppa:user/bar').that_notifies('Class[Apt::Update]').with({ - 'environment' => [], - 'command' => '/usr/bin/add-apt-repository -y ppa:user/bar', - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/user-bar-natty.list', - 'user' => 'root', - 'logoutput' => 'on_failure', - }) + it { + is_expected.to contain_exec('add-apt-repository-ppa:user/bar').that_notifies('Class[Apt::Update]').with('environment' => [], + 'command' => '/usr/bin/add-apt-repository -y ppa:user/bar', + 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/user-bar-natty.list', + 'user' => 'root', + 'logoutput' => 'on_failure') } - it { is_expected.to contain_file('/etc/apt/sources.list.d/user-bar-natty.list').that_requires('Exec[add-apt-repository-ppa:user/bar]').with({ - 'ensure' => 'file', - }) + it { + is_expected.to contain_file('/etc/apt/sources.list.d/user-bar-natty.list').that_requires('Exec[add-apt-repository-ppa:user/bar]').with('ensure' => 'file') } end @@ -145,35 +143,34 @@ describe 'apt::ppa' do end let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }}, - :lsbdistrelease => '11.04', - :lsbdistcodename => 'natty', - :operatingsystem => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } }, + lsbdistrelease: '11.04', + lsbdistcodename: 'natty', + operatingsystem: 'Ubuntu', + osfamily: 'Debian', + lsbdistid: 'Ubuntu', + puppetversion: Puppet.version, } end let :params do { - :package_manage => false, + package_manage: false, } end let(:title) { 'ppa:needs/such.substitution/wow' } - it { is_expected.to_not contain_package('python-software-properties') } - it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with({ - 'environment' => [], - 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list', - 'user' => 'root', - 'logoutput' => 'on_failure', - }) + + it { is_expected.not_to contain_package('python-software-properties') } + it { + is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [], + 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', # rubocop:disable Metrics/LineLength + 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list', # rubocop:disable Metrics/LineLength + 'user' => 'root', + 'logoutput' => 'on_failure') } - it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({ - 'ensure' => 'file', - }) + it { + is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with('ensure' => 'file') } end @@ -185,32 +182,32 @@ describe 'apt::ppa' do end let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistrelease => '14.04', - :lsbdistcodename => 'trusty', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistrelease: '14.04', + lsbdistcodename: 'trusty', + operatingsystem: 'Ubuntu', + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :options => '', - :package_manage => true, - :require => 'Apt::Ppa[ppa:user/foo2]', + options: '', + package_manage: true, + require: 'Apt::Ppa[ppa:user/foo2]', } end let(:title) { 'ppa:user/foo' } + it { is_expected.to compile.with_all_deps } it { is_expected.to contain_package('software-properties-common') } - it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({ - :environment => [], - :command => '/usr/bin/add-apt-repository ppa:user/foo', - :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', - :user => 'root', - :logoutput => 'on_failure', - }) + it { + is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [], + command: '/usr/bin/add-apt-repository ppa:user/foo', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', + user: 'root', + logoutput: 'on_failure') } end @@ -222,13 +219,13 @@ describe 'apt::ppa' do end let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistrelease => '14.04', - :lsbdistcodename => 'trusty', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistrelease: '14.04', + lsbdistcodename: 'trusty', + operatingsystem: 'Ubuntu', + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do @@ -238,14 +235,14 @@ describe 'apt::ppa' do } end let(:title) { 'ppa:user/foo' } + it { is_expected.to contain_package('software-properties-common') } - it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({ - :environment => ['http_proxy=http://localhost:8080'], - :command => '/usr/bin/add-apt-repository ppa:user/foo', - :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', - :user => 'root', - :logoutput => 'on_failure', - }) + it { + is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8080'], + command: '/usr/bin/add-apt-repository ppa:user/foo', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', + user: 'root', + logoutput: 'on_failure') } end @@ -257,30 +254,30 @@ describe 'apt::ppa' do end let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistrelease => '14.04', - :lsbdistcodename => 'trusty', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistrelease: '14.04', + lsbdistcodename: 'trusty', + operatingsystem: 'Ubuntu', + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :options => '', - :package_manage => true, + options: '', + package_manage: true, } end let(:title) { 'ppa:user/foo' } + it { is_expected.to contain_package('software-properties-common') } - it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({ - :environment => ['http_proxy=http://localhost:8180'], - :command => '/usr/bin/add-apt-repository ppa:user/foo', - :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', - :user => 'root', - :logoutput => 'on_failure', - }) + it { + is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180'], + command: '/usr/bin/add-apt-repository ppa:user/foo', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', + user: 'root', + logoutput: 'on_failure') } end @@ -292,30 +289,30 @@ describe 'apt::ppa' do end let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistrelease => '14.04', - :lsbdistcodename => 'trusty', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistrelease: '14.04', + lsbdistcodename: 'trusty', + operatingsystem: 'Ubuntu', + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :options => '', - :package_manage => true, + options: '', + package_manage: true, } end let(:title) { 'ppa:user/foo' } + it { is_expected.to contain_package('software-properties-common') } - it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({ - :environment => ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'], - :command => '/usr/bin/add-apt-repository ppa:user/foo', - :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', - :user => 'root', - :logoutput => 'on_failure', - }) + it { + is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'], + command: '/usr/bin/add-apt-repository ppa:user/foo', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', + user: 'root', + logoutput: 'on_failure') } end @@ -325,24 +322,24 @@ describe 'apt::ppa' do end let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistrelease => '14.04', - :lsbdistcodename => 'trusty', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistrelease: '14.04', + lsbdistcodename: 'trusty', + operatingsystem: 'Ubuntu', + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let(:title) { 'ppa:user/foo' } let :params do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_file('/etc/apt/sources.list.d/user-foo-trusty.list').that_notifies('Class[Apt::Update]').with({ - :ensure => 'absent', - }) + + it { + is_expected.to contain_file('/etc/apt/sources.list.d/user-foo-trusty.list').that_notifies('Class[Apt::Update]').with(ensure: 'absent') } end @@ -350,40 +347,42 @@ describe 'apt::ppa' do describe 'no release' do let :facts do { - :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, - :lsbdistrelease => '14.04', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian', - :lsbdistcodeanme => nil, - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, + lsbdistrelease: '14.04', + operatingsystem: 'Ubuntu', + lsbdistid: 'Ubuntu', + osfamily: 'Debian', + lsbdistcodeanme: nil, + puppetversion: Puppet.version, } end let(:title) { 'ppa:user/foo' } + it do expect { subject.call - }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/) + }.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required}) end end describe 'not ubuntu' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '6', :full => '6.0.7' }}, - :lsbdistrelease => '6.0.7', - :lsbdistcodename => 'wheezy', - :operatingsystem => 'Debian', - :lsbdistid => 'debian', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '6', full: '6.0.7' } }, + lsbdistrelease: '6.0.7', + lsbdistcodename: 'wheezy', + operatingsystem: 'Debian', + lsbdistid: 'debian', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let(:title) { 'ppa:user/foo' } + it do expect { subject.call - }.to raise_error(Puppet::Error, /not currently supported on Debian/) + }.to raise_error(Puppet::Error, %r{not currently supported on Debian}) end end end diff --git a/spec/defines/setting_spec.rb b/spec/defines/setting_spec.rb index cdba312..0b6ca99 100644 --- a/spec/defines/setting_spec.rb +++ b/spec/defines/setting_spec.rb @@ -4,64 +4,68 @@ describe 'apt::setting' do let(:pre_condition) { 'class { "apt": }' } let :facts do { - :os => { :distro => { :codename => 'wheezy' }, :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistrelease => '7.0', - :lsbdistcodename => 'wheezy', - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistid => 'Debian', - :puppetversion => Puppet.version, + os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistrelease: '7.0', + lsbdistcodename: 'wheezy', + operatingsystem: 'Debian', + osfamily: 'Debian', + lsbdistid: 'Debian', + puppetversion: Puppet.version, } end let(:title) { 'conf-teddybear' } - let(:default_params) { { :content => 'di' } } + let(:default_params) { { content: 'di' } } describe 'when using the defaults' do context 'without source or content' do it do - expect { subject.call }.to raise_error(Puppet::Error, /needs either of /) + expect { subject.call }.to raise_error(Puppet::Error, %r{needs either of }) end end context 'with title=conf-teddybear ' do let(:params) { default_params } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]') } end context 'with title=pref-teddybear' do let(:title) { 'pref-teddybear' } let(:params) { default_params } + it { is_expected.to contain_file('/etc/apt/preferences.d/teddybear.pref').that_notifies('Class[Apt::Update]') } end context 'with title=list-teddybear' do let(:title) { 'list-teddybear' } let(:params) { default_params } + it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list').that_notifies('Class[Apt::Update]') } end context 'with source' do - let(:params) { { :source => 'puppet:///la/die/dah' } } + let(:params) { { source: 'puppet:///la/die/dah' } } + it { - is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({ - :ensure => 'file', - :owner => 'root', - :group => 'root', - :mode => '0644', - :source => "#{params[:source]}", - })} + is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with(ensure: 'file', + owner: 'root', + group: 'root', + mode: '0644', + source: params[:source].to_s) + } end context 'with content' do let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({ - :ensure => 'file', - :owner => 'root', - :group => 'root', - :mode => '0644', - :content => "#{params[:content]}", - })} + + it { + is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with(ensure: 'file', + owner: 'root', + group: 'root', + mode: '0644', + content: params[:content].to_s) + } end end @@ -71,63 +75,71 @@ describe 'apt::setting' do apt::setting { "list-teddybear": content => "foo" } ' end - let(:facts) { { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, - } } + let(:facts) do + { + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, + } + end let(:title) { 'conf-teddybear' } - let(:default_params) { { :content => 'di' } } + let(:default_params) { { content: 'di' } } - let(:params) { default_params.merge({ :require => 'Apt::Setting[list-teddybear]' }) } + let(:params) { default_params.merge(require: 'Apt::Setting[list-teddybear]') } it { is_expected.to compile.with_all_deps } end describe 'when trying to pull one over' do context 'with source and content' do - let(:params) { default_params.merge({ :source => 'la' }) } + let(:params) { default_params.merge(source: 'la') } + it do - expect { subject.call }.to raise_error(Puppet::Error, /cannot have both /) + expect { subject.call }.to raise_error(Puppet::Error, %r{cannot have both }) end end context 'with title=ext-teddybear' do let(:title) { 'ext-teddybear' } let(:params) { default_params } + it do - expect { subject.call }.to raise_error(Puppet::Error, /must start with either/) + expect { subject.call }.to raise_error(Puppet::Error, %r{must start with either}) end end context 'with ensure=banana' do - let(:params) { default_params.merge({ :ensure => 'banana' }) } + let(:params) { default_params.merge(ensure: 'banana') } + it do - expect { subject.call }.to raise_error(Puppet::Error, /Enum\['absent', 'file', 'present'\]/) + expect { subject.call }.to raise_error(Puppet::Error, %r{Enum\['absent', 'file', 'present'\]}) end end context 'with priority=1.2' do - let(:params) { default_params.merge({ :priority => 1.2 }) } - if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') >= 0 || ENV["FUTURE_PARSER"] == 'yes' - it { is_expected.to compile.and_raise_error(/expects a value of type/) } + let(:params) { default_params.merge(priority: 1.2) } + + if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') >= 0 || ENV['FUTURE_PARSER'] == 'yes' + it { is_expected.to compile.and_raise_error(%r{expects a value of type}) } else - it { is_expected.to compile.and_raise_error(/priority must be an integer or a zero-padded integer/) } + it { is_expected.to compile.and_raise_error(%r{priority must be an integer or a zero-padded integer}) } end end end describe 'with priority=100' do - let(:params) { default_params.merge({ :priority => 100 }) } + let(:params) { default_params.merge(priority: 100) } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Class[Apt::Update]') } end describe 'with ensure=absent' do - let(:params) { default_params.merge({ :ensure => 'absent' }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({ - :ensure => 'absent', - })} + let(:params) { default_params.merge(ensure: 'absent') } + + it { + is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with(ensure: 'absent') + } end end diff --git a/spec/defines/source_compat_spec.rb b/spec/defines/source_compat_spec.rb index 88cd625..c6b6aef 100644 --- a/spec/defines/source_compat_spec.rb +++ b/spec/defines/source_compat_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -describe 'apt::source', :type => :define do - GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F' +describe 'apt::source', type: :define do + GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze let :title do 'my_source' @@ -10,33 +10,34 @@ describe 'apt::source', :type => :define do context 'mostly defaults' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { 'include' => { 'deb' => false, 'src' => true }, - 'location' => 'http://debian.mirror.iweb.ca/debian/', + 'location' => 'http://debian.mirror.iweb.ca/debian/', } end - it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb-src http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb-src http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/) } end context 'no defaults' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do @@ -53,36 +54,35 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_apt__setting('list-my_source').with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) + it { + is_expected.to contain_apt__setting('list-my_source').with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(%r{deb-src}) # rubocop:disable Metrics/LineLength } - it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ - 'ensure' => 'present', - 'priority' => '10', - 'origin' => 'debian.mirror.iweb.ca', - }) + it { + is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with('ensure' => 'present', + 'priority' => '10', + 'origin' => 'debian.mirror.iweb.ca') } - it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({ - 'ensure' => 'present', - 'id' => GPG_KEY_ID, - }) + it { + is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with('ensure' => 'present', + 'id' => GPG_KEY_ID) } end context 'allow_unsigned true' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - 'include' => {'src' => false}, + 'include' => { 'src' => false }, 'location' => 'http://debian.mirror.iweb.ca/debian/', 'allow_unsigned' => true, } @@ -94,11 +94,11 @@ describe 'apt::source', :type => :define do context 'architecture equals x86_64' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do @@ -108,18 +108,19 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb \[arch=x86_64\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb \[arch=x86_64\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/) } end context 'ensure => absent' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do @@ -128,9 +129,8 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - 'ensure' => 'absent' - }) + it { + is_expected.to contain_apt__setting('list-my_source').with('ensure' => 'absent') } end @@ -138,15 +138,15 @@ describe 'apt::source', :type => :define do context 'no release' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + puppetversion: Puppet.version, } end it do - expect { subject.call }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/) + expect { subject.call }.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required}) end end end diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 79cc11b..eaa0887 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'apt::source' do - GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F' + GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze let :pre_condition do 'class { "apt": }' @@ -15,33 +15,33 @@ describe 'apt::source' do context 'without location' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :osfamily => 'Debian', - :lsbdistcodename => 'wheezy', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + osfamily: 'Debian', + lsbdistcodename: 'wheezy', + puppetversion: Puppet.version, } end + it do expect { subject.call - }.to raise_error(Puppet::Error, /source entry without specifying a location/) + }.to raise_error(Puppet::Error, %r{source entry without specifying a location}) end end context 'with location' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end - let(:params) { { :location => 'hello.there', } } + let(:params) { { location: 'hello.there' } } - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).without_content(/# my_source\ndeb-src hello.there wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n}) } end end @@ -49,143 +49,132 @@ describe 'apt::source' do describe 'no defaults' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :operatingsystem => 'Debian', - :lsbdistrelease => '7.0', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + operatingsystem: 'Debian', + lsbdistrelease: '7.0', + puppetversion: Puppet.version, } end context 'with complex pin' do let :params do { - :location => 'hello.there', - :pin => { 'release' => 'wishwash', - 'explanation' => 'wishwash', - 'priority' => 1001, }, + location: 'hello.there', + pin: { 'release' => 'wishwash', + 'explanation' => 'wishwash', + 'priority' => 1001 }, } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/hello.there wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there wheezy main\n}) } - it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]')} + it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]') } - it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ - :ensure => 'present', - :priority => 1001, - :explanation => 'wishwash', - :release => 'wishwash', - }) + it { + is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + priority: 1001, + explanation: 'wishwash', + release: 'wishwash') } end context 'with simple key' do let :params do { - :comment => 'foo', - :location => 'http://debian.mirror.iweb.ca/debian/', - :release => 'sid', - :repos => 'testing', - :key => GPG_KEY_ID, - :pin => '10', - :architecture => 'x86_64', - :allow_unsigned => true, + comment: 'foo', + location: 'http://debian.mirror.iweb.ca/debian/', + release: 'sid', + repos: 'testing', + key: GPG_KEY_ID, + pin: '10', + architecture: 'x86_64', + allow_unsigned: true, } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(%r{deb-src}) # rubocop:disable Metrics/LineLength } - it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ - :ensure => 'present', - :priority => '10', - :origin => 'debian.mirror.iweb.ca', - }) + it { + is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + priority: '10', + origin: 'debian.mirror.iweb.ca') } - it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({ - :ensure => 'present', - :id => GPG_KEY_ID, - }) + it { + is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + id: GPG_KEY_ID) } end context 'with complex key' do let :params do { - :comment => 'foo', - :location => 'http://debian.mirror.iweb.ca/debian/', - :release => 'sid', - :repos => 'testing', - :key => { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu', - 'content' => 'GPG key content', - 'source' => 'http://apt.puppetlabs.com/pubkey.gpg',}, - :pin => '10', - :architecture => 'x86_64', - :allow_unsigned => true, + comment: 'foo', + location: 'http://debian.mirror.iweb.ca/debian/', + release: 'sid', + repos: 'testing', + key: { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu', + 'content' => 'GPG key content', + 'source' => 'http://apt.puppetlabs.com/pubkey.gpg' }, + pin: '10', + architecture: 'x86_64', + allow_unsigned: true, } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(%r{deb-src}) # rubocop:disable Metrics/LineLength } - it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ - :ensure => 'present', - :priority => '10', - :origin => 'debian.mirror.iweb.ca', - }) + it { + is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + priority: '10', + origin: 'debian.mirror.iweb.ca') } - it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({ - :ensure => 'present', - :id => GPG_KEY_ID, - :server => 'pgp.mit.edu', - :content => 'GPG key content', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - }) + it { + is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + id: GPG_KEY_ID, + server: 'pgp.mit.edu', + content: 'GPG key content', + source: 'http://apt.puppetlabs.com/pubkey.gpg') } end context 'with simple key' do let :params do { - :comment => 'foo', - :location => 'http://debian.mirror.iweb.ca/debian/', - :release => 'sid', - :repos => 'testing', - :key => GPG_KEY_ID, - :pin => '10', - :architecture => 'x86_64', - :allow_unsigned => true, + comment: 'foo', + location: 'http://debian.mirror.iweb.ca/debian/', + release: 'sid', + repos: 'testing', + key: GPG_KEY_ID, + pin: '10', + architecture: 'x86_64', + allow_unsigned: true, } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(%r{deb-src}) # rubocop:disable Metrics/LineLength } - it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ - :ensure => 'present', - :priority => '10', - :origin => 'debian.mirror.iweb.ca', - }) + it { + is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + priority: '10', + origin: 'debian.mirror.iweb.ca') } - it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({ - :ensure => 'present', - :id => GPG_KEY_ID, - }) + it { + is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + id: GPG_KEY_ID) } end end @@ -193,164 +182,157 @@ describe 'apt::source' do context 'allow_unsigned true' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :location => 'hello.there', - :allow_unsigned => true, + location: 'hello.there', + allow_unsigned: true, } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n}) } end context 'architecture equals x86_64' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :location => 'hello.there', - :include => {'deb' => false, 'src' => true}, - :architecture => 'x86_64', + location: 'hello.there', + include: { 'deb' => false, 'src' => true }, + architecture: 'x86_64', } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/# my_source\ndeb-src \[arch=x86_64\] hello.there wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src \[arch=x86_64\] hello.there wheezy main\n}) } end context 'with architecture fact and unset architecture parameter' do let :facts do { - :architecture => 'amd64', - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + architecture: 'amd64', + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :location => 'hello.there', - :include => {'deb' => false, 'src' => true,}, + location: 'hello.there', + include: { 'deb' => false, 'src' => true }, } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/# my_source\ndeb-src hello.there wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there wheezy main\n}) } end context 'include_src => true' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :location => 'hello.there', - :include => {'src' => true}, + location: 'hello.there', + include: { 'src' => true }, } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/# my_source\ndeb hello.there wheezy main\ndeb-src hello.there wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there wheezy main\ndeb-src hello.there wheezy main\n}) } end context 'include deb => false' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'debian', + lsbdistcodename: 'wheezy', + osfamily: 'debian', + puppetversion: Puppet.version, } end let :params do { - :include => { 'deb' => false }, - :location => 'hello.there', + include: { 'deb' => false }, + location: 'hello.there', } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).without_content(/deb-src hello.there wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n}) } - it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) } + it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) } end context 'include src => true and include deb => false' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'debian', + lsbdistcodename: 'wheezy', + osfamily: 'debian', + puppetversion: Puppet.version, } end let :params do { - :include => { 'deb' => false, 'src' => true }, - :location => 'hello.there', + include: { 'deb' => false, 'src' => true }, + location: 'hello.there', } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'present', - }).with_content(/deb-src hello.there wheezy main\n/) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there wheezy main\n}) } - it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) } + it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) } end context 'ensure => absent' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :ensure => 'absent', + ensure: 'absent', } end - it { is_expected.to contain_apt__setting('list-my_source').with({ - :ensure => 'absent' - }) + it { + is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent') } end @@ -358,114 +340,116 @@ describe 'apt::source' do context 'no release' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + puppetversion: Puppet.version, } end - let(:params) { { :location => 'hello.there', } } + let(:params) { { location: 'hello.there' } } it do expect { subject.call - }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/) + }.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required}) end end context 'release is empty string' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + osfamily: 'Debian', + puppetversion: Puppet.version, } end - let(:params) { { :location => 'hello.there', :release => '' } } + let(:params) { { location: 'hello.there', release: '' } } - it { is_expected.to contain_apt__setting('list-my_source').with_content(/hello\.there main/) } + it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) } end context 'invalid pin' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :location => 'hello.there', - :pin => true, + location: 'hello.there', + pin: true, } end it do expect { subject.call - }.to raise_error(Puppet::Error, /invalid value for pin/) + }.to raise_error(Puppet::Error, %r{invalid value for pin}) end end - context "with notify_update = undef (default)" do + context 'with notify_update = undef (default)' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :location => 'hello.there', + location: 'hello.there', } end + it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) } end - context "with notify_update = true" do + context 'with notify_update = true' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :location => 'hello.there', - :notify_update => true, + location: 'hello.there', + notify_update: true, } end + it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) } end - context "with notify_update = false" do + context 'with notify_update = false' do let :facts do { - :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian', - :puppetversion => Puppet.version, + os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'wheezy', + osfamily: 'Debian', + puppetversion: Puppet.version, } end let :params do { - :location => 'hello.there', - :notify_update => false, + location: 'hello.there', + notify_update: false, } end + it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) } end - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 22d5d68..1b8480d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -#This file is generated by ModuleSync, do not edit. +# This file is generated by ModuleSync, do not edit. require 'puppetlabs_spec_helper/module_spec_helper' # put local configuration and setup into spec_helper_local diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 30eccbf..e5e7cbf 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -6,7 +6,7 @@ run_puppet_install_helper install_module_on(hosts) install_module_dependencies_on(hosts) -UNSUPPORTED_PLATFORMS = ['RedHat','Suse','windows','AIX','Solaris'] +UNSUPPORTED_PLATFORMS = %w[RedHat Suse windows AIX Solaris].freeze # This method allows a block to be passed in and if an exception is raised # that matches the 'error_matcher' matcher, the block will wait a set number @@ -25,7 +25,7 @@ def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, e try += 1 yield rescue Exception => e - if try < max_retry_count && (error_matcher == nil || e.message =~ error_matcher) + if try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher) sleep retry_wait_interval_secs retry else diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index d030e0f..fcc874d 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -2,37 +2,39 @@ require 'spec_helper' describe 'apt_has_updates fact' do subject { Facter.fact(:apt_has_updates).value } + after(:each) { Facter.clear } describe 'on non-Debian distro' do - before { + before(:each) do Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat' - } + end it { is_expected.to be_nil } end describe 'on Debian based distro missing apt-get' do - before { + before(:each) do Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' File.stubs(:executable?) # Stub all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns false - } + end it { is_expected.to be_nil } end describe 'on Debian based distro' do - before { + before(:each) do Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns ""+ - "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"+ - "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" - } + apt_output = <<-EOT +Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all]) +Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all]) +Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all]) +Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all]) +EOT + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + end it { is_expected.to be true } end end - diff --git a/spec/unit/facter/apt_package_security_updates_spec.rb b/spec/unit/facter/apt_package_security_updates_spec.rb index bc51aee..ff636d3 100644 --- a/spec/unit/facter/apt_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_package_security_updates_spec.rb @@ -2,30 +2,31 @@ require 'spec_helper' describe 'apt_package_security_updates fact' do subject { Facter.fact(:apt_package_security_updates).value } + after(:each) { Facter.clear } describe 'when apt has no updates' do - before { + before(:each) do Facter.fact(:apt_has_updates).stubs(:value).returns false - } + end it { is_expected.to be nil } end describe 'when apt has updates' do - before { + before(:each) do Facter.fact(:osfamily).stubs(:value).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_get_upgrade_output - } + end describe 'on Debian' do let(:apt_get_upgrade_output) do - "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"+ - "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" + "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" end it { @@ -39,22 +40,21 @@ describe 'apt_package_security_updates fact' do describe 'on Ubuntu' do let(:apt_get_upgrade_output) do - "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n"+ - "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n"+ - "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n"+ - "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n"+ - "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n"+ - "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" + "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ + "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ + "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ + "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { if Facter.version < '2.0.0' is_expected.to eq('tzdata,curl') else - is_expected.to eq(['tzdata', 'curl']) + is_expected.to eq(%w[tzdata curl]) end } end - end end diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index 49cecee..875a290 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -2,32 +2,35 @@ require 'spec_helper' describe 'apt_package_updates fact' do subject { Facter.fact(:apt_package_updates).value } + after(:each) { Facter.clear } describe 'when apt has no updates' do - before { + before(:each) do Facter.fact(:apt_has_updates).stubs(:value).returns false - } + end it { is_expected.to be nil } end describe 'when apt has updates' do - before { + before(:each) do Facter.fact(:osfamily).stubs(:value).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns ""+ - "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"+ - "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" - } + apt_output = <<-EOT +Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all]) +Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all]) +Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all]) +Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all]) +EOT + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + end it { if Facter.version < '2.0.0' is_expected.to eq('tzdata,unhide.rb') else - is_expected.to eq(['tzdata','unhide.rb']) + is_expected.to eq(['tzdata', 'unhide.rb']) end } end diff --git a/spec/unit/facter/apt_reboot_required_spec.rb b/spec/unit/facter/apt_reboot_required_spec.rb index ed6efd0..356f36b 100644 --- a/spec/unit/facter/apt_reboot_required_spec.rb +++ b/spec/unit/facter/apt_reboot_required_spec.rb @@ -2,24 +2,24 @@ require 'spec_helper' describe 'apt_reboot_required fact' do subject { Facter.fact(:apt_reboot_required).value } + after(:each) { Facter.clear } describe 'if a reboot is required' do - before { + before(:each) do Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' File.stubs(:file?).returns true File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns true - } + end it { is_expected.to eq true } end describe 'if a reboot is not required' do - before { + before(:each) do Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' File.stubs(:file?).returns true File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns false - } + end it { is_expected.to eq false } end - end diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index 1e54216..af8951b 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -2,30 +2,31 @@ require 'spec_helper' describe 'apt_security_updates fact' do subject { Facter.fact(:apt_security_updates).value } + after(:each) { Facter.clear } describe 'when apt has no updates' do - before { + before(:each) do Facter.fact(:apt_has_updates).stubs(:value).returns false - } + end it { is_expected.to be nil } end describe 'when apt has security updates' do - before { + before(:each) do Facter.fact(:osfamily).stubs(:value).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_get_upgrade_output - } + end describe 'on Debian' do let(:apt_get_upgrade_output) do - "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"+ - "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" + "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" end it { is_expected.to eq(1) } @@ -33,16 +34,15 @@ describe 'apt_security_updates fact' do describe 'on Ubuntu' do let(:apt_get_upgrade_output) do - "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n"+ - "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n"+ - "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n"+ - "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n"+ - "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n"+ - "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" + "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ + "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ + "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ + "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(2) } end end - end diff --git a/spec/unit/facter/apt_update_last_success_spec.rb b/spec/unit/facter/apt_update_last_success_spec.rb index ada6aa5..60d7273 100644 --- a/spec/unit/facter/apt_update_last_success_spec.rb +++ b/spec/unit/facter/apt_update_last_success_spec.rb @@ -2,24 +2,24 @@ require 'spec_helper' describe 'apt_update_last_success fact' do subject { Facter.fact(:apt_update_last_success).value } + before(:each) { Facter.clear } after(:each) { Facter.clear } describe 'on Debian based distro which has not yet created the update-success-stamp file' do - it 'should have a value of -1' do + it 'has a value of -1' do Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.expects(:exists?).with('/var/lib/apt/periodic/update-success-stamp').returns false + File.expects(:exist?).with('/var/lib/apt/periodic/update-success-stamp').returns false is_expected.to eq(-1) end end describe 'on Debian based distro which has created the update-success-stamp' do - it 'should have the value of the mtime of the file' do + it 'has the value of the mtime of the file' do Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:exists?).returns true - File.stubs(:mtime).returns 1407660561 - is_expected.to eq(1407660561) + File.stubs(:exist?).returns true + File.stubs(:mtime).returns 1_407_660_561 + is_expected.to eq(1_407_660_561) end end - end diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb index d2c2bf2..cc1aa94 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -2,28 +2,30 @@ require 'spec_helper' describe 'apt_updates fact' do subject { Facter.fact(:apt_updates).value } + after(:each) { Facter.clear } describe 'when apt has no updates' do - before { + before(:each) do Facter.fact(:apt_has_updates).stubs(:value).returns false - } + end it { is_expected.to be nil } end describe 'when apt has updates' do - before { + before(:each) do Facter.fact(:osfamily).stubs(:value).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns ""+ - "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n"+ - "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"+ - "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" - } + apt_output = <<-EOT +Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all]) +Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all]) +Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all]) +Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all]) +EOT + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + end it { is_expected.to eq(2) } end - end diff --git a/spec/unit/puppet/type/apt_key_spec.rb b/spec/unit/puppet/type/apt_key_spec.rb index 9c2dd91..a1f24b5 100644 --- a/spec/unit/puppet/type/apt_key_spec.rb +++ b/spec/unit/puppet/type/apt_key_spec.rb @@ -1,11 +1,14 @@ require 'spec_helper' require 'puppet' -describe Puppet::Type::type(:apt_key) do +describe Puppet::Type.type(:apt_key) do context 'only namevar 32bit key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + ) + end + it 'id is set' do expect(resource[:id]).to eq 'EF8D349F' end @@ -28,55 +31,72 @@ describe Puppet::Type::type(:apt_key) do end context 'with a lowercase 32bit key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => 'ef8d349f' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'ef8d349f', + ) + end + it 'id is set' do expect(resource[:id]).to eq 'EF8D349F' end end context 'with a 64bit key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => 'FFFFFFFFEF8D349F' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'FFFFFFFFEF8D349F', + ) + end + it 'id is set' do expect(resource[:id]).to eq 'FFFFFFFFEF8D349F' end end context 'with a 0x formatted key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '0xEF8D349F' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xEF8D349F', + ) + end + it 'id is set' do expect(resource[:id]).to eq 'EF8D349F' end end context 'with a 0x formatted lowercase key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '0xef8d349f' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xef8d349f', + ) + end + it 'id is set' do expect(resource[:id]).to eq 'EF8D349F' end end context 'with a 0x formatted 64bit key id' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => '0xFFFFFFFFEF8D349F' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xFFFFFFFFEF8D349F', + ) + end + it 'id is set' do expect(resource[:id]).to eq 'FFFFFFFFEF8D349F' end end context 'with source' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'http://apt.puppetlabs.com/pubkey.gpg' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + ) + end it 'source is set to the URL' do expect(resource[:source]).to eq 'http://apt.puppetlabs.com/pubkey.gpg' @@ -84,10 +104,12 @@ describe Puppet::Type::type(:apt_key) do end context 'with content' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :content => 'http://apt.puppetlabs.com/pubkey.gpg' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + content: 'http://apt.puppetlabs.com/pubkey.gpg', + ) + end it 'content is set to the string' do expect(resource[:content]).to eq 'http://apt.puppetlabs.com/pubkey.gpg' @@ -95,10 +117,12 @@ describe Puppet::Type::type(:apt_key) do end context 'with keyserver' do - let(:resource) { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :server => 'http://keyring.debian.org' - )} + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + server: 'http://keyring.debian.org', + ) + end it 'keyserver is set to Debian' do expect(resource[:server]).to eq 'http://keyring.debian.org' @@ -107,82 +131,104 @@ describe Puppet::Type::type(:apt_key) do context 'validation' do it 'raises an error if content and source are set' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :content => 'Completely invalid as a GPG key' - )}.to raise_error(/content and source are mutually exclusive/) + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + content: 'Completely invalid as a GPG key', + ) + }.to raise_error(%r{content and source are mutually exclusive}) end it 'raises an error if a weird length key is used' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'FEF8D349F', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :content => 'Completely invalid as a GPG key' - )}.to raise_error(/Valid values match/) + expect { + Puppet::Type.type(:apt_key).new( + id: 'FEF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + content: 'Completely invalid as a GPG key', + ) + }.to raise_error(%r{Valid values match}) end it 'raises an error when an invalid URI scheme is used in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'hkp://pgp.mit.edu' - )}.to raise_error(/Valid values match/) + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'hkp://pgp.mit.edu', + ) + }.to raise_error(%r{Valid values match}) end it 'allows the http URI scheme in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'http://pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'http://pgp.mit.edu', + ) + }.not_to raise_error end it 'allows the http URI with username and password' do - expect { Puppet::Type.type(:apt_key).new( - :id => '4BD6EC30', - :source => 'http://testme:Password2@pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new( + id: '4BD6EC30', + source: 'http://testme:Password2@pgp.mit.edu', + ) + }.not_to raise_error end it 'allows the https URI scheme in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'https://pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'https://pgp.mit.edu', + ) + }.not_to raise_error end it 'allows the https URI with username and password' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'https://testme:Password2@pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'https://testme:Password2@pgp.mit.edu', + ) + }.not_to raise_error end it 'allows the ftp URI scheme in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'ftp://pgp.mit.edu' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'ftp://pgp.mit.edu', + ) + }.not_to raise_error end it 'allows an absolute path in source' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => '/path/to/a/file' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: '/path/to/a/file', + ) + }.not_to raise_error end it 'allows 5-digit ports' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'http://pgp.mit.edu:12345/key' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'http://pgp.mit.edu:12345/key', + ) + }.not_to raise_error end it 'allows 5-digit ports when using key servers' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :server => 'http://pgp.mit.edu:12345' - )}.to_not raise_error + expect { + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + server: 'http://pgp.mit.edu:12345', + ) + }.not_to raise_error end end end -- 2.32.3