diff --git a/.fixtures.yml b/.fixtures.yml index 1cfbdc361e..7e9bfa941f 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,7 +5,7 @@ fixtures: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' puppet_agent: repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.12.1 + ref: v4.13.0 provision: 'https://github.com/puppetlabs/provision.git' symlinks: "apt": "#{source_dir}" diff --git a/.rubocop.yml b/.rubocop.yml index 31e8248ff8..2dbf4503f8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,15 @@ --- +inherit_from: .rubocop_todo.yml + require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.5' + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.7' Include: - "**/*.rb" Exclude: @@ -79,441 +84,7 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets -Performance/AncestorsInclude: - Enabled: true -Performance/BigDecimalWithNumericArgument: - Enabled: true -Performance/BlockGivenWithExplicitBlock: - Enabled: true -Performance/CaseWhenSplat: - Enabled: true -Performance/ConstantRegexp: - Enabled: true -Performance/MethodObjectAsBlock: - Enabled: true -Performance/RedundantSortBlock: - Enabled: true -Performance/RedundantStringChars: - Enabled: true -Performance/ReverseFirst: - Enabled: true -Performance/SortReverse: - Enabled: true -Performance/Squeeze: - Enabled: true -Performance/StringInclude: - Enabled: true -Performance/Sum: - Enabled: true -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Bundler/InsecureProtocolSource: - Enabled: false -Gemspec/DuplicatedAssignment: - Enabled: false -Gemspec/OrderedDependencies: - Enabled: false -Gemspec/RequiredRubyVersion: - Enabled: false -Gemspec/RubyVersionGlobalsUsage: - Enabled: false -Layout/ArgumentAlignment: - Enabled: false -Layout/BeginEndAlignment: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: false -Layout/EmptyComment: - Enabled: false -Layout/EmptyLineAfterGuardClause: - Enabled: false -Layout/EmptyLinesAroundArguments: - Enabled: false -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/FirstArgumentIndentation: - Enabled: false -Layout/HashAlignment: - Enabled: false -Layout/HeredocIndentation: - Enabled: false -Layout/LeadingEmptyLines: - Enabled: false -Layout/SpaceAroundMethodCallOperator: - Enabled: false -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false -Layout/SpaceInsideReferenceBrackets: - Enabled: false -Lint/BigDecimalNew: - Enabled: false -Lint/BooleanSymbol: - Enabled: false -Lint/ConstantDefinitionInBlock: - Enabled: false -Lint/DeprecatedOpenSSLConstant: - Enabled: false -Lint/DisjunctiveAssignmentInConstructor: - Enabled: false -Lint/DuplicateElsifCondition: - Enabled: false -Lint/DuplicateRequire: - Enabled: false -Lint/DuplicateRescueException: - Enabled: false -Lint/EmptyConditionalBody: - Enabled: false -Lint/EmptyFile: - Enabled: false -Lint/ErbNewArguments: - Enabled: false -Lint/FloatComparison: - Enabled: false -Lint/HashCompareByIdentity: - Enabled: false -Lint/IdentityComparison: - Enabled: false -Lint/InterpolationCheck: - Enabled: false -Lint/MissingCopEnableDirective: - Enabled: false -Lint/MixedRegexpCaptureTypes: - Enabled: false -Lint/NestedPercentLiteral: - Enabled: false -Lint/NonDeterministicRequireOrder: - Enabled: false -Lint/OrderedMagicComments: - Enabled: false -Lint/OutOfRangeRegexpRef: - Enabled: false -Lint/RaiseException: - Enabled: false -Lint/RedundantCopEnableDirective: - Enabled: false -Lint/RedundantRequireStatement: - Enabled: false -Lint/RedundantSafeNavigation: - Enabled: false -Lint/RedundantWithIndex: - Enabled: false -Lint/RedundantWithObject: - Enabled: false -Lint/RegexpAsCondition: - Enabled: false -Lint/ReturnInVoidContext: - Enabled: false -Lint/SafeNavigationConsistency: - Enabled: false -Lint/SafeNavigationWithEmpty: - Enabled: false -Lint/SelfAssignment: - Enabled: false -Lint/SendWithMixinArgument: - Enabled: false -Lint/ShadowedArgument: - Enabled: false -Lint/StructNewOverride: - Enabled: false -Lint/ToJSON: - Enabled: false -Lint/TopLevelReturnWithArgument: - Enabled: false -Lint/TrailingCommaInAttributeDeclaration: - Enabled: false -Lint/UnreachableLoop: - Enabled: false -Lint/UriEscapeUnescape: - Enabled: false -Lint/UriRegexp: - Enabled: false -Lint/UselessMethodDefinition: - Enabled: false -Lint/UselessTimes: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Migration/DepartmentName: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Naming/BlockParameterName: - Enabled: false -Naming/HeredocDelimiterCase: - Enabled: false -Naming/HeredocDelimiterNaming: - Enabled: false -Naming/MemoizedInstanceVariableName: - Enabled: false -Naming/MethodParameterName: - Enabled: false -Naming/RescuedExceptionsVariableName: - Enabled: false -Naming/VariableNumber: - Enabled: false -Performance/BindCall: - Enabled: false -Performance/DeletePrefix: - Enabled: false -Performance/DeleteSuffix: - Enabled: false -Performance/InefficientHashSearch: - Enabled: false -Performance/UnfreezeString: - Enabled: false -Performance/UriDefaultParser: - Enabled: false -RSpec/Be: - Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false -RSpec/Capybara/FeatureMethods: - Enabled: false -RSpec/Capybara/VisibilityMatcher: - Enabled: false -RSpec/ContextMethod: - Enabled: false -RSpec/ContextWording: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/EmptyHook: - Enabled: false -RSpec/EmptyLineAfterExample: - Enabled: false -RSpec/EmptyLineAfterExampleGroup: - Enabled: false -RSpec/EmptyLineAfterHook: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWithoutDescription: - Enabled: false -RSpec/ExpectChange: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/FactoryBot/AttributeDefinedStatically: - Enabled: false -RSpec/FactoryBot/CreateList: - Enabled: false -RSpec/FactoryBot/FactoryClassName: - Enabled: false -RSpec/HooksBeforeExamples: - Enabled: false -RSpec/ImplicitBlockExpectation: - Enabled: false -RSpec/ImplicitSubject: - Enabled: false -RSpec/LeakyConstantDeclaration: - Enabled: false -RSpec/LetBeforeExamples: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false RSpec/MultipleExpectations: - Enabled: false -RSpec/MultipleMemoizedHelpers: - Enabled: false -RSpec/MultipleSubjects: - Enabled: false -RSpec/NestedGroups: - Enabled: false -RSpec/PredicateMatcher: - Enabled: false -RSpec/ReceiveCounts: - Enabled: false -RSpec/ReceiveNever: - Enabled: false -RSpec/RepeatedExampleGroupBody: - Enabled: false -RSpec/RepeatedExampleGroupDescription: - Enabled: false -RSpec/RepeatedIncludeExample: - Enabled: false -RSpec/ReturnFromStub: - Enabled: false -RSpec/SharedExamples: - Enabled: false -RSpec/StubbedMock: - Enabled: false -RSpec/UnspecifiedException: - Enabled: false -RSpec/VariableDefinition: - Enabled: false -RSpec/VoidExpect: - Enabled: false -RSpec/Yield: - Enabled: false -Security/Open: - Enabled: false -Style/AccessModifierDeclarations: - Enabled: false -Style/AccessorGrouping: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/BisectedAttrAccessor: - Enabled: false -Style/CaseLikeIf: - Enabled: false -Style/ClassEqualityComparison: - Enabled: false -Style/ColonMethodDefinition: - Enabled: false -Style/CombinableLoops: - Enabled: false -Style/CommentedKeyword: - Enabled: false -Style/Dir: - Enabled: false -Style/DoubleCopDisableDirective: - Enabled: false -Style/EmptyBlockParameter: - Enabled: false -Style/EmptyLambdaParameter: - Enabled: false -Style/Encoding: - Enabled: false -Style/EvalWithLocation: - Enabled: false -Style/ExpandPathArguments: - Enabled: false -Style/ExplicitBlockArgument: - Enabled: false -Style/ExponentialNotation: - Enabled: false -Style/FloatDivision: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalStdStream: - Enabled: false -Style/HashAsLastArrayItem: - Enabled: false -Style/HashLikeCase: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/KeywordParametersOrder: - Enabled: false -Style/MinMax: - Enabled: false -Style/MixinUsage: - Enabled: false -Style/MultilineWhenThen: - Enabled: false -Style/NegatedUnless: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OptionalBooleanParameter: - Enabled: false -Style/OrAssignment: - Enabled: false -Style/RandomWithOffset: - Enabled: false -Style/RedundantAssignment: - Enabled: false -Style/RedundantCondition: - Enabled: false -Style/RedundantConditional: - Enabled: false -Style/RedundantFetchBlock: - Enabled: false -Style/RedundantFileExtensionInRequire: - Enabled: false -Style/RedundantRegexpCharacterClass: - Enabled: false -Style/RedundantRegexpEscape: - Enabled: false -Style/RedundantSelfAssignment: - Enabled: false -Style/RedundantSort: - Enabled: false -Style/RescueStandardError: - Enabled: false -Style/SingleArgumentDig: - Enabled: false -Style/SlicingWithRange: - Enabled: false -Style/SoleNestedConditional: - Enabled: false -Style/StderrPuts: - Enabled: false -Style/StringConcatenation: - Enabled: false -Style/Strip: - Enabled: false -Style/SymbolProc: - Enabled: false -Style/TrailingBodyOnClass: - Enabled: false -Style/TrailingBodyOnMethodDefinition: - Enabled: false -Style/TrailingBodyOnModule: - Enabled: false -Style/TrailingCommaInHashLiteral: - Enabled: false -Style/TrailingMethodEndStatement: - Enabled: false -Style/UnpackFirst: - Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/DuplicateRegexpCharacterClassElement: - Enabled: false -Lint/EmptyBlock: - Enabled: false -Lint/EmptyClass: - Enabled: false -Lint/NoReturnInBeginEndBlocks: - Enabled: false -Lint/ToEnumArguments: - Enabled: false -Lint/UnexpectedBlockArity: - Enabled: false -Lint/UnmodifiedReduceAccumulator: - Enabled: false -Performance/CollectionLiteralInLoop: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionCompact: - Enabled: false -Style/DocumentDynamicEvalDefinition: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/NilLambda: - Enabled: false -Style/RedundantArgument: - Enabled: false -Style/SwapValues: - Enabled: false + Max: 3 +Naming/MethodParameterName: + AllowedNames: 'is' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 23d36faa4d..da3cce5150 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,2 +1,97 @@ -GetText/DecorateString: - Enabled: false \ No newline at end of file +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-21 12:46:34 UTC using RuboCop version 1.48.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 6 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 40 + +# Offense count: 3 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 180 + +# Offense count: 3 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 11 + +# Offense count: 8 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 39 + +# Offense count: 3 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 12 + +# Offense count: 32 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Enabled: false + +# Offense count: 13 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 15 + +# Offense count: 3 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 6 + +# Offense count: 204 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: + Exclude: + - 'spec/classes/apt_backports_spec.rb' + - 'spec/classes/apt_spec.rb' + - 'spec/classes/apt_update_spec.rb' + - 'spec/defines/conf_spec.rb' + - 'spec/defines/key_compat_spec.rb' + - 'spec/defines/key_spec.rb' + - 'spec/defines/mark_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' + - 'spec/unit/facter/apt_update_last_success_spec.rb' + +# Offense count: 2 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 4 + +# Offense count: 24 +# Configuration parameters: AllowedPatterns. +# AllowedPatterns: ^expect_, ^assert_ +RSpec/NoExpectationExample: + Exclude: + - 'spec/acceptance/01_apt_class_spec.rb' + - 'spec/acceptance/apt_backports_spec.rb' + - 'spec/acceptance/apt_key_provider_spec.rb' + - 'spec/acceptance/apt_spec.rb' + +# Offense count: 3 +RSpec/StubbedMock: + Exclude: + - 'spec/unit/puppet/provider/apt_key_spec.rb' + +# Offense count: 2 +Security/Open: + Exclude: + - 'lib/puppet/provider/apt_key/apt_key.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' diff --git a/Gemfile b/Gemfile index 8456bee1c3..3f6f5c7d55 100644 --- a/Gemfile +++ b/Gemfile @@ -30,9 +30,9 @@ group :development do gem "pry", '~> 0.10', require: false gem "simplecov-console", '~> 0.5', require: false gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.6.1', require: false - gem "rubocop-performance", '= 1.9.1', require: false - gem "rubocop-rspec", '= 2.0.1', require: false + gem "rubocop", '= 1.48.1', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "github_changelog_generator", '= 1.15.2', require: false end diff --git a/Rakefile b/Rakefile index 8fdf11b998..4477dcbc56 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,6 @@ require 'bundler' require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? diff --git a/lib/facter/apt_updates.rb b/lib/facter/apt_updates.rb index f261d2c165..66c6a89286 100644 --- a/lib/facter/apt_updates.rb +++ b/lib/facter/apt_updates.rb @@ -14,6 +14,7 @@ def get_updates(upgrade_option) apt_updates = [[], []] apt_get_result.each_line do |line| next unless %r{^Inst\s}.match?(line) + package = line.gsub(%r{^Inst\s([^\s]+)\s.*}, '\1').strip apt_updates[0].push(package) security_matches = [ @@ -22,9 +23,7 @@ def get_updates(upgrade_option) %r{ gNewSense[^\s]+-security[, ]}, ] re = Regexp.union(security_matches) - if line.match(re) - apt_updates[1].push(package) - end + apt_updates[1].push(package) if line.match(re) end end end @@ -35,9 +34,7 @@ def get_updates(upgrade_option) confine osfamily: 'Debian' setcode do apt_package_updates = get_updates('upgrade') - if !apt_package_updates.nil? && apt_package_updates.length == 2 - apt_package_updates != [[], []] - end + apt_package_updates != [[], []] if !apt_package_updates.nil? && apt_package_updates.length == 2 end end @@ -45,9 +42,7 @@ def get_updates(upgrade_option) confine osfamily: 'Debian' setcode do apt_dist_updates = get_updates('dist-upgrade') - if !apt_dist_updates.nil? && apt_dist_updates.length == 2 - apt_dist_updates != [[], []] - end + apt_dist_updates != [[], []] if !apt_dist_updates.nil? && apt_dist_updates.length == 2 end end diff --git a/lib/puppet/provider/apt_key/apt_key.rb b/lib/puppet/provider/apt_key/apt_key.rb index 115ed316de..546f2c154b 100644 --- a/lib/puppet/provider/apt_key/apt_key.rb +++ b/lib/puppet/provider/apt_key/apt_key.rb @@ -49,9 +49,7 @@ def self.instances expired = false - if line_hash[:key_expiry] - expired = Time.now >= line_hash[:key_expiry] - end + expired = Time.now >= line_hash[:key_expiry] if line_hash[:key_expiry] new( name: line_hash[:key_fingerprint], @@ -73,13 +71,14 @@ def self.instances def self.prefetch(resources) apt_keys = instances resources.each_key do |name| - if name.length == 40 + case name.length + when 40 provider = apt_keys.find { |key| key.fingerprint == name } resources[name].provider = provider if provider - elsif name.length == 16 + when 16 provider = apt_keys.find { |key| key.long == name } resources[name].provider = provider if provider - elsif name.length == 8 + when 8 provider = apt_keys.find { |key| key.short == name } resources[name].provider = provider if provider end @@ -93,12 +92,12 @@ def self.key_line_hash(pub_line, fpr_line) 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_long: fingerprint[-16..], # last 16 characters of fingerprint + key_short: fingerprint[-8..], # 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_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 @@ -120,6 +119,7 @@ def source_to_file(value) parsed_value = URI.parse(value) if parsed_value.scheme.nil? raise(_('The file %{_value} does not exist') % { _value: value }) 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 @@ -136,14 +136,14 @@ def source_to_file(value) # Some webservers (e.g. Amazon S3) return code 400 if empty basic auth is sent if parsed_value.userinfo.nil? key = if parsed_value.scheme == 'https' && resource[:weak_ssl] == true - open(parsed_value, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE).read + URI.open(parsed_value, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE).read else parsed_value.read end else user_pass = parsed_value.userinfo.split(':') parsed_value.userinfo = '' - key = open(parsed_value, http_basic_authentication: user_pass).read + key = URI.open(parsed_value, http_basic_authentication: user_pass).read end rescue *exceptions => e raise(_('%{_e} for %{_resource}') % { _e: e.message, _resource: resource[:source] }) @@ -170,9 +170,7 @@ def tempfile(content) found_match = false extracted_key.each_line do |line| - if line.chomp == name - found_match = true - end + found_match = true if line.chomp == name end unless found_match raise(_('The id in your manifest %{_resource} and the fingerprint from content/source don\'t match. Check for an error in the id and content/source is legitimate.') % { _resource: resource[:name] }) # rubocop:disable Layout/LineLength @@ -195,9 +193,7 @@ def create # Breaking up the command like this is needed because it blows up # if --recv-keys isn't the last argument. command.push('adv', '--no-tty', '--keyserver', resource[:server]) - unless resource[:options].nil? - command.push('--keyserver-options', resource[:options]) - end + command.push('--keyserver-options', resource[:options]) unless resource[:options].nil? command.push('--recv-keys', resource[:id]) elsif resource[:content] key_file = tempfile(resource[:content]) diff --git a/lib/puppet/type/apt_key.rb b/lib/puppet/type/apt_key.rb index c78ba8fb43..faa430be42 100644 --- a/lib/puppet/type/apt_key.rb +++ b/lib/puppet/type/apt_key.rb @@ -25,15 +25,10 @@ ensurable validate do - if self[:refresh] == true && self[:ensure] == :absent - raise(_('ensure => absent and refresh => true are mutually exclusive')) - end - if self[:content] && self[:source] - raise(_('The properties content and source are mutually exclusive.')) - end - if self[:id].length < 40 - warning(_('The id should be a full fingerprint (40 characters), see README.')) - end + raise(_('ensure => absent and refresh => true are mutually exclusive')) if self[:refresh] == true && self[:ensure] == :absent + raise(_('The properties content and source are mutually exclusive.')) if self[:content] && self[:source] + + warning(_('The id should be a full fingerprint (40 characters), see README.')) if self[:id].length < 40 end newparam(:id, namevar: true) do @@ -61,16 +56,14 @@ end autorequire(:file) do - if self[:source] && Pathname.new(self[:source]).absolute? - self[:source] - end + self[:source] if self[:source] && Pathname.new(self[:source]).absolute? end newparam(:server) 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(%r{\A((hkp|hkps|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?(\/[a-zA-Z\d\-_.]+)*\/?$}) + newvalues(%r{\A((hkp|hkps|http|https)://)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?(/[a-zA-Z\d\-_.]+)*/?$}) end newparam(:options) do diff --git a/metadata.json b/metadata.json index 0565eaa205..076f068de1 100644 --- a/metadata.json +++ b/metadata.json @@ -33,10 +33,10 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.24.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "tags/2.7.3-0-g8f110f1", - "pdk-version": "2.7.0 (8)" + "template-ref": "heads/main-0-ge5b0114", + "pdk-version": "2.7.1" } diff --git a/spec/acceptance/apt_key_provider_spec.rb b/spec/acceptance/apt_key_provider_spec.rb index ee4a4c8242..2c99343070 100644 --- a/spec/acceptance/apt_key_provider_spec.rb +++ b/spec/acceptance/apt_key_provider_spec.rb @@ -111,7 +111,7 @@ def apply_manifest_twice(manifest_pp) =cXcR -----END PGP PUBLIC KEY BLOCK-----' } - MANIFEST +MANIFEST gpg_key_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -170,7 +170,7 @@ def apply_manifest_twice(manifest_pp) =mMjt -----END PGP PUBLIC KEY BLOCK-----", } - MANIFEST +MANIFEST multiple_keys_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -423,7 +423,7 @@ def apply_manifest_twice(manifest_pp) =TREp -----END PGP PUBLIC KEY BLOCK----- ", } - MANIFEST +MANIFEST bogus_key_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -431,7 +431,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', content => 'For posterity: such content, much bogus, wow', } - MANIFEST +MANIFEST hkp_pool_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -439,7 +439,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', server => 'hkp://keyserver.ubuntu.com:80', } - MANIFEST +MANIFEST hkps_protocol_supported = host_inventory['facter']['os']['family'] =~ %r{Ubuntu}i && \ host_inventory['facter']['os']['release']['major'] =~ %r{^18\.04} @@ -451,7 +451,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', server => 'hkps://keyserver.ubuntu.com', } - MANIFEST + MANIFEST end nonexistant_key_server_pp = <<-MANIFEST @@ -460,7 +460,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', server => 'nonexistant.key.server', } - MANIFEST +MANIFEST dot_server_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -468,7 +468,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', server => '.pgp.key.server', } - MANIFEST +MANIFEST http_works_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -476,7 +476,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'http://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}', } - MANIFEST +MANIFEST http_works_userinfo_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -484,7 +484,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'http://dummyuser:dummypassword@#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}', } - MANIFEST +MANIFEST four_oh_four_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -492,7 +492,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'http://#{PUPPETLABS_APT_URL}/herpderp.gpg', } - MANIFEST +MANIFEST socket_error_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -500,7 +500,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'http://apt.puppetlabss.com/herpderp.gpg', } - MANIFEST +MANIFEST ftp_works_pp = <<-MANIFEST apt_key { 'CentOS 6': @@ -508,7 +508,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'ftp://#{CENTOS_REPO_URL}/#{CENTOS_GPG_KEY_FILE}', } - MANIFEST +MANIFEST ftp_550_pp = <<-MANIFEST apt_key { 'CentOS 6': @@ -516,7 +516,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'ftp://#{CENTOS_REPO_URL}/herpderp.gpg', } - MANIFEST +MANIFEST ftp_socket_error_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -524,7 +524,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'ftp://apt.puppetlabss.com/herpderp.gpg', } - MANIFEST +MANIFEST https_works_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -532,7 +532,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}', } - MANIFEST +MANIFEST https_with_weak_ssl_works_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -541,7 +541,7 @@ def apply_manifest_twice(manifest_pp) source => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}', weak_ssl => true, } - MANIFEST +MANIFEST https_userinfo_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -549,7 +549,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'https://dummyuser:dummypassword@#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}', } - MANIFEST +MANIFEST https_404_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -557,7 +557,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'https://#{PUPPETLABS_APT_URL}/herpderp.gpg', } - MANIFEST +MANIFEST https_socket_error_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -565,7 +565,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'https://apt.puppetlabss.com/herpderp.gpg', } - MANIFEST +MANIFEST path_exists_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -573,7 +573,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => '/tmp/puppetlabs-pubkey.gpg', } - MANIFEST +MANIFEST path_does_not_exist_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -581,7 +581,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => '/tmp/totally_bogus.file', } - MANIFEST +MANIFEST path_bogus_content_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -589,7 +589,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => '/tmp/fake-key.gpg', } - MANIFEST +MANIFEST debug_works_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -597,7 +597,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', options => 'debug', } - MANIFEST +MANIFEST fingerprint_match_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -605,7 +605,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}', } - MANIFEST +MANIFEST fingerprint_does_not_match_pp = <<-MANIFEST apt_key { 'puppetlabs': @@ -613,7 +613,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', source => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}', } - MANIFEST +MANIFEST refresh_true_pp = <<-MANIFEST apt_key { '#{PUPPETLABS_EXP_KEY_LONG_ID}': @@ -621,7 +621,7 @@ def apply_manifest_twice(manifest_pp) ensure => 'present', refresh => true, } - MANIFEST +MANIFEST refresh_false_pp = <<-MANIFEST apt_key { '#{PUPPETLABS_EXP_KEY_LONG_ID}': @@ -657,18 +657,19 @@ def apply_manifest_twice(manifest_pp) id => '#{CENTOS_GPG_KEY_LONG_ID}', ensure => 'present', } - MANIFEST + MANIFEST ensure_absent_pp = <<-MANIFEST apt_key { 'centos': id => '#{CENTOS_GPG_KEY_LONG_ID}', ensure => 'absent', } - MANIFEST + MANIFEST it 'add an apt_key resource' do apply_manifest_twice(ensure_present_pp) end + it 'remove the apt_key resource' do apply_manifest_twice(ensure_absent_pp) end @@ -676,7 +677,7 @@ def apply_manifest_twice(manifest_pp) describe 'content =>' do context 'with puppetlabs gpg key' do - it 'works' do + it 'applies without error' do # Apply the manifest (Retry if timeout error is received from key pool) retry_on_error_matching do apply_manifest(gpg_key_pp, catch_failures: true) @@ -705,7 +706,7 @@ def apply_manifest_twice(manifest_pp) describe 'server =>' do context 'with hkp://pgp.mit.edu:80' do - it 'works' do + it 'applies without error' do retry_on_error_matching do apply_manifest(hkp_pool_pp, catch_failures: true) end @@ -717,7 +718,7 @@ def apply_manifest_twice(manifest_pp) if hkps_protocol_supported context 'with hkps://keyserver.ubuntu.com' do - it 'works' do + it 'applies without error' do retry_on_error_matching do apply_manifest(hkps_ubuntu_pp, catch_failures: true) end @@ -747,7 +748,7 @@ def apply_manifest_twice(manifest_pp) describe 'source =>' do context 'with http://' do - it 'works' do + it 'applies without error' do apply_manifest_twice(http_works_pp) run_shell(PUPPETLABS_KEY_CHECK_COMMAND) end @@ -776,7 +777,7 @@ def apply_manifest_twice(manifest_pp) run_shell("apt-key del #{CENTOS_GPG_KEY_LONG_ID}", expect_failures: true) end - it 'works' do + it 'applies without error' do apply_manifest_twice(ftp_works_pp) run_shell(CENTOS_KEY_CHECK_COMMAND) end @@ -795,7 +796,7 @@ def apply_manifest_twice(manifest_pp) end context 'with https://' do - it 'works' do + it 'applies without error' do apply_manifest_twice(https_works_pp) run_shell(PUPPETLABS_KEY_CHECK_COMMAND) end @@ -833,7 +834,7 @@ def apply_manifest_twice(manifest_pp) run_shell('rm /tmp/puppetlabs-pubkey.gpg') end - it 'works' do + it 'applies without error' do apply_manifest_twice(path_exists_pp) run_shell(PUPPETLABS_KEY_CHECK_COMMAND) end @@ -855,6 +856,7 @@ def apply_manifest_twice(manifest_pp) after(:each) do run_shell('rm /tmp/fake-key.gpg') end + it 'fails' do apply_manifest(path_bogus_content_pp, expect_failures: true) do |r| expect(r.stderr).to match(%r{no valid OpenPGP data found}) @@ -865,7 +867,7 @@ def apply_manifest_twice(manifest_pp) describe 'options =>' do context 'with debug' do - it 'works' do + it 'applies without error' do apply_manifest_twice(debug_works_pp) run_shell(PUPPETLABS_KEY_CHECK_COMMAND) end @@ -874,13 +876,13 @@ def apply_manifest_twice(manifest_pp) describe 'fingerprint validation against source/content' do context 'with fingerprint in id matches fingerprint from remote key' do - it 'works' do + it 'applies without error' do apply_manifest_twice(fingerprint_match_pp) end end context 'with fingerprint in id does NOT match fingerprint from remote key' do - it 'works' do + it 'applies without error' do apply_manifest(fingerprint_does_not_match_pp, expect_failures: true) do |r| expect(r.stderr).to match(%r{don't match}) end @@ -897,6 +899,7 @@ def apply_manifest_twice(manifest_pp) apply_manifest(refresh_del_key_pp) apply_manifest(refresh_pp, catch_failures: true) end + context 'when refresh => true' do it 'updates an expired key' do apply_manifest(refresh_true_pp) @@ -904,6 +907,7 @@ def apply_manifest_twice(manifest_pp) run_shell(PUPPETLABS_EXP_CHECK_COMMAND.to_s) end end + context 'when refresh => false' do it 'does not replace an expired key' do apply_manifest(refresh_false_pp) diff --git a/spec/acceptance/apt_spec.rb b/spec/acceptance/apt_spec.rb index 7e4fe3787b..802858e8e2 100644 --- a/spec/acceptance/apt_spec.rb +++ b/spec/acceptance/apt_spec.rb @@ -29,10 +29,10 @@ class { 'apt': }, sources => $sources, } - MANIFEST +MANIFEST describe 'apt class' do - context 'with reset' do + context 'with test start reset' do it 'fixes the sources.list' do run_shell('cp /etc/apt/sources.list /tmp') end @@ -45,13 +45,14 @@ class { 'apt': apply_manifest(everything_everything_pp, catch_failures: true) end end + it 'stills work' do run_shell('apt-get update') run_shell('apt-get -y --force-yes upgrade') end end - context 'with reset' do + context 'with test end reset' do it 'fixes the sources.list' do run_shell('cp /tmp/sources.list /etc/apt') end diff --git a/spec/acceptance/init_task_spec.rb b/spec/acceptance/init_task_spec.rb index 02b3f34dfd..7a21a43854 100644 --- a/spec/acceptance/init_task_spec.rb +++ b/spec/acceptance/init_task_spec.rb @@ -10,18 +10,21 @@ expect(result.stdout).to contain(%r{Reading package lists}) end end + describe 'upgrade' do it 'upgrades packages' do result = run_bolt_task('apt', 'action' => 'upgrade') expect(result.stdout).to contain(%r{\d+ upgraded, \d+ newly installed, \d+ to remove and \d+ not upgraded}) end end + describe 'dist-upgrade' do it 'dist-upgrades packages' do result = run_bolt_task('apt', 'action' => 'dist-upgrade') expect(result.stdout).to contain(%r{\d+ upgraded, \d+ newly installed, \d+ to remove and \d+ not upgraded}) end end + describe 'autoremove' do it 'autoremoves obsolete packages' do result = run_bolt_task('apt', 'action' => 'autoremove') diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb index 6f6d530921..e7a951a758 100644 --- a/spec/classes/apt_backports_spec.rb +++ b/spec/classes/apt_backports_spec.rb @@ -14,23 +14,24 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end it { - is_expected.to contain_apt__source('backports').with(location: 'http://deb.debian.org/debian', - repos: 'main contrib non-free', - release: 'stretch-backports', - pin: { 'priority' => 200, 'release' => 'stretch-backports' }) + expect(subject).to contain_apt__source('backports').with(location: 'http://deb.debian.org/debian', + repos: 'main contrib non-free', + release: 'stretch-backports', + pin: { 'priority' => 200, 'release' => 'stretch-backports' }) } end + context 'with defaults on ubuntu' do let(:facts) do { @@ -39,24 +40,25 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionac', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end it { - is_expected.to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu', - key: '630239CC130E1A7FD81A27B140976EAF437D05B5', - repos: 'main universe multiverse restricted', - release: 'bionac-backports', - pin: { 'priority' => 200, 'release' => 'bionac-backports' }) + expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5', + repos: 'main universe multiverse restricted', + release: 'bionac-backports', + pin: { 'priority' => 200, 'release' => 'bionac-backports' }) } end + context 'with everything set' do let(:facts) do { @@ -65,13 +67,13 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionac', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end let(:params) do @@ -80,18 +82,19 @@ release: 'vivid', repos: 'main', key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - pin: '90', + 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' }) + expect(subject).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 'when set things with hashes' do let(:facts) do { @@ -100,32 +103,33 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionac', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end let(:params) do { key: { - 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' }, pin: { - 'priority' => '90', - }, + 'priority' => '90' + } } end it { - is_expected.to contain_apt__source('backports').with(key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' }, - pin: { 'priority' => '90' }) + expect(subject).to contain_apt__source('backports').with(key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' }, + pin: { 'priority' => '90' }) } end end + describe 'mint tests' do let(:facts) do { @@ -134,13 +138,13 @@ name: 'LinuxMint', release: { major: '17', - full: '17', + full: '17' }, distro: { codename: 'qiana', - id: 'LinuxMint', - }, - }, + id: 'LinuxMint' + } + } } end @@ -150,71 +154,76 @@ location: 'http://archive.ubuntu.com/ubuntu', release: 'trusty-backports', repos: 'main universe multiverse restricted', - key: '630239CC130E1A7FD81A27B140976EAF437D05B5', + 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' }) + expect(subject).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 'with missing location' do let(:params) do { release: 'trusty-backports', repos: 'main universe multiverse restricted', - key: '630239CC130E1A7FD81A27B140976EAF437D05B5', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5' } end it do - is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) + expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) end end + context 'with missing release' do let(:params) do { location: 'http://archive.ubuntu.com/ubuntu', repos: 'main universe multiverse restricted', - key: '630239CC130E1A7FD81A27B140976EAF437D05B5', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5' } end it do - is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) + expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) end end + context 'with missing repos' do let(:params) do { location: 'http://archive.ubuntu.com/ubuntu', release: 'trusty-backports', - key: '630239CC130E1A7FD81A27B140976EAF437D05B5', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5' } end it do - is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) + expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) end end + context 'with missing key' do let(:params) do { location: 'http://archive.ubuntu.com/ubuntu', release: 'trusty-backports', - repos: 'main universe multiverse restricted', + repos: 'main universe multiverse restricted' } end it do - is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) + expect(subject).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 { @@ -223,69 +232,73 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionac', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end context 'with invalid location' do let(:params) do { - location: true, + location: true } end it do - is_expected.to raise_error(Puppet::Error, %r{expects a}) + expect(subject).to raise_error(Puppet::Error, %r{expects a}) end end + context 'with invalid release' do let(:params) do { - release: true, + release: true } end it do - is_expected.to raise_error(Puppet::Error, %r{expects a}) + expect(subject).to raise_error(Puppet::Error, %r{expects a}) end end + context 'with invalid repos' do let(:params) do { - repos: true, + repos: true } end it do - is_expected.to raise_error(Puppet::Error, %r{expects a}) + expect(subject).to raise_error(Puppet::Error, %r{expects a}) end end + context 'with invalid key' do let(:params) do { - key: true, + key: true } end it do - is_expected.to raise_error(Puppet::Error, %r{expects a}) + expect(subject).to raise_error(Puppet::Error, %r{expects a}) end end + context 'with invalid pin' do let(:params) do { - pin: true, + pin: true } end it do - is_expected.to raise_error(Puppet::Error, %r{expects a}) + expect(subject).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 1a7513c44a..cb65c1e001 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -46,48 +46,48 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end context 'with defaults' do it { - is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list) + expect(subject).to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list) } it { - is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d) + expect(subject).to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d) } it { - is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences) + expect(subject).to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences) } it { - is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d) + expect(subject).to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d) } it { - is_expected.to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d) + expect(subject).to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d) } it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') } 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', - owner: 'root').with_content( - %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};}, - ) + expect(subject).to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root', + owner: 'root').with_content( + %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};}, + ) end it { - is_expected.to contain_exec('apt_update').with(refreshonly: 'true') + expect(subject).to contain_exec('apt_update').with(refreshonly: 'true') } it { is_expected.not_to contain_apt__setting('conf-proxy') } @@ -98,7 +98,7 @@ let(:params) { { proxy: { 'host' => 'localhost' } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy "http://localhost:8080/";}, ).without_content( %r{Acquire::https::proxy }, @@ -110,7 +110,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'host' => 'proxyhost' }] } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy::proxyscope "http://proxyhost:8080/";}, ) } @@ -120,7 +120,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'host' => 'proxyhost', 'port' => 8081 }] } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy::proxyscope "http://proxyhost:8081/";}, ) } @@ -130,7 +130,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'host' => 'proxyhost', 'https' => true }] } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::https::proxy::proxyscope "https://proxyhost:8080/";}, ) } @@ -140,7 +140,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'direct' => true }] } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy::proxyscope "DIRECT";}, ) } @@ -150,7 +150,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'https' => true, 'direct' => true }] } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::https::proxy::proxyscope "DIRECT";}, ) } @@ -160,7 +160,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'host' => 'proxyhost' }, { 'scope' => 'proxyscope2', 'host' => 'proxyhost2' }] } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy::proxyscope "http://proxyhost:8080/";}, ).with_content( %r{Acquire::http::proxy::proxyscope2 "http://proxyhost2:8080/";}, @@ -172,7 +172,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy "http://localhost:8180/";}, ).without_content( %r{Acquire::https::proxy }, @@ -184,7 +184,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy "http://localhost:8080/";}, ).with_content( %r{Acquire::https::proxy "https://localhost:8080/";}, @@ -196,7 +196,7 @@ let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy "http://localhost:8080/";}, ).with_content( %r{Acquire::https::proxy "DIRECT";}, @@ -208,14 +208,15 @@ let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy "http://localhost:8080/";}, ).with_content( %r{Acquire::https::proxy "https://localhost:8080/";}, ) } + it { - is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + expect(subject).to contain_apt__setting('conf-proxy').with(priority: '01').with_content( %r{Acquire::http::proxy "http://localhost:8080/";}, ).without_content( %r{Acquire::https::proxy "DIRECT";}, @@ -227,88 +228,89 @@ let(:params) { { proxy: { 'ensure' => 'absent' } } } it { - is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent', - priority: '01') + expect(subject).to contain_apt__setting('conf-proxy').with(ensure: 'absent', + priority: '01') } end end - context 'with lots of non-defaults' do + + context 'with lots of non-defaults - one' do let :params do { update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 }, purge: { 'sources.list' => false, 'sources.list.d' => false, 'preferences' => false, 'preferences.d' => false, - 'apt.conf.d' => false }, + 'apt.conf.d' => false } } end it { - is_expected.to contain_file('sources.list').with(content: nil) + expect(subject).to contain_file('sources.list').with(content: nil) } it { - is_expected.to contain_file('sources.list.d').with(purge: false, - recurse: false) + expect(subject).to contain_file('sources.list.d').with(purge: false, + recurse: false) } it { - is_expected.to contain_file('preferences').with(ensure: 'file') + expect(subject).to contain_file('preferences').with(ensure: 'file') } it { - is_expected.to contain_file('preferences.d').with(purge: false, - recurse: false) + expect(subject).to contain_file('preferences.d').with(purge: false, + recurse: false) } it { - is_expected.to contain_file('apt.conf.d').with(purge: false, - recurse: false) + expect(subject).to contain_file('apt.conf.d').with(purge: false, + recurse: false) } it { - is_expected.to contain_exec('apt_update').with(refreshonly: false, - timeout: 1, - tries: 3) + expect(subject).to contain_exec('apt_update').with(refreshonly: false, + timeout: 1, + tries: 3) } end - context 'with lots of non-defaults' do + context 'with lots of non-defaults - two' do let :params do { update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 }, purge: { 'sources.list' => true, 'sources.list.d' => true, 'preferences' => true, 'preferences.d' => true, - 'apt.conf.d' => true }, + 'apt.conf.d' => true } } end it { - is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n") + expect(subject).to contain_file('sources.list').with(content: "# Repos managed by puppet.\n") } it { - is_expected.to contain_file('sources.list.d').with(purge: true, - recurse: true) + expect(subject).to contain_file('sources.list.d').with(purge: true, + recurse: true) } it { - is_expected.to contain_file('preferences').with(ensure: 'absent') + expect(subject).to contain_file('preferences').with(ensure: 'absent') } it { - is_expected.to contain_file('preferences.d').with(purge: true, - recurse: true) + expect(subject).to contain_file('preferences.d').with(purge: true, + recurse: true) } it { - is_expected.to contain_file('apt.conf.d').with(purge: true, - recurse: true) + expect(subject).to contain_file('apt.conf.d').with(purge: true, + recurse: true) } it { - is_expected.to contain_exec('apt_update').with(refreshonly: false, - timeout: 1, - tries: 3) + expect(subject).to contain_exec('apt_update').with(refreshonly: false, + timeout: 1, + tries: 3) } end @@ -317,12 +319,12 @@ { update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 }, purge: { 'sources.list' => true }, - sources_list_force: false, + sources_list_force: false } end it { - is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n") + expect(subject).to contain_file('sources.list').with(content: "# Repos managed by puppet.\n") } end @@ -331,12 +333,12 @@ { update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 }, purge: { 'sources.list' => true }, - sources_list_force: true, + sources_list_force: true } end it { - is_expected.to contain_file('sources.list').with(ensure: 'absent') + expect(subject).to contain_file('sources.list').with(ensure: 'absent') } end @@ -348,13 +350,13 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionic', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } }, 'Debian 9.0' => { os: { @@ -362,13 +364,13 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } }, 'Debian 10.0' => { os: { @@ -376,18 +378,18 @@ name: 'Debian', release: { major: '10', - full: '10.0', + full: '10.0' }, distro: { codename: 'buster', - id: 'Debian', - }, - }, - }, + id: 'Debian' + } + } + } } facts_hash.each do |os, facts| - context "on #{os}" do + context "when on #{os}" do let(:facts) do facts end @@ -397,14 +399,14 @@ { machine: 'deb.example.net', login: 'foologin', - password: 'secret', + password: 'secret' }, { machine: 'apt.example.com', login: 'aptlogin', - password: 'supersecret', + password: 'supersecret' }, - ], + ] } end @@ -419,12 +421,12 @@ " it { - is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present', - owner: '_apt', - group: 'root', - mode: '0600', - notify: 'Class[Apt::Update]', - content: sensitive(auth_conf_content)) + expect(subject).to contain_file('/etc/apt/auth.conf').with(ensure: 'present', + owner: '_apt', + group: 'root', + mode: '0600', + notify: 'Class[Apt::Update]', + content: sensitive(auth_conf_content)) } end @@ -434,7 +436,7 @@ end it { - is_expected.not_to contain_file('/etc/apt/auth.conf') + expect(subject).not_to contain_file('/etc/apt/auth.conf') } end end @@ -446,14 +448,14 @@ { machinn: 'deb.example.net', username: 'foologin', - password: 'secret', + password: 'secret' }, { machine: 'apt.example.com', login: 'aptlogin', - password: 'supersecret', + password: 'supersecret' }, - ], + ] } end @@ -470,42 +472,42 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionic', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } 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 }, + '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' }, - }, + 'repos' => 'main', + 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' } + } } } end it { - is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present') + expect(subject).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(%r{^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(%r{^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') + expect(subject).to contain_apt__setting('list-puppetlabs').with(ensure: 'present') } it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com bionic main$}) } @@ -519,32 +521,32 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionic', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end let(:params) do { confs: { 'foo' => { - 'content' => 'foo', + 'content' => 'foo' }, 'bar' => { - 'content' => 'bar', - }, + 'content' => 'bar' + } } } end it { - is_expected.to contain_apt__conf('foo').with(content: 'foo') + expect(subject).to contain_apt__conf('foo').with(content: 'foo') } it { - is_expected.to contain_apt__conf('bar').with(content: 'bar') + expect(subject).to contain_apt__conf('bar').with(content: 'bar') } end @@ -556,32 +558,32 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionic', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end let(:params) do { keys: { '55BE302B' => { - 'server' => 'subkeys.pgp.net', + 'server' => 'subkeys.pgp.net' }, 'EF8D349F' => { - 'server' => 'pgp.mit.edu', - }, + 'server' => 'pgp.mit.edu' + } } } end it { - is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net') + expect(subject).to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net') } it { - is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu') + expect(subject).to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu') } end @@ -593,19 +595,19 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionic', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end let(:params) do { ppas: { 'ppa:drizzle-developers/ppa' => {}, - 'ppa:nginx/stable' => {}, + 'ppa:nginx/stable' => {} } } end @@ -621,19 +623,19 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionic', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end let(:params) do { settings: { 'conf-banana' => { 'content' => 'banana' }, - 'pref-banana' => { 'content' => 'banana' }, + 'pref-banana' => { 'content' => 'banana' } } } end @@ -649,19 +651,19 @@ name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'bionic', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end let(:params) do { pins: { 'stable' => { 'priority' => 600, 'order' => 50 }, - 'testing' => { 'priority' => 700, 'order' => 100 }, + 'testing' => { 'priority' => 700, 'order' => 100 } } } end @@ -674,7 +676,7 @@ let(:params) { { purge: { 'sources.list' => 'banana' } } } it do - is_expected.to raise_error(Puppet::Error) + expect(subject).to raise_error(Puppet::Error) end end @@ -682,7 +684,7 @@ let(:params) { { purge: { 'sources.list.d' => 'banana' } } } it do - is_expected.to raise_error(Puppet::Error) + expect(subject).to raise_error(Puppet::Error) end end @@ -690,7 +692,7 @@ let(:params) { { purge: { 'preferences' => 'banana' } } } it do - is_expected.to raise_error(Puppet::Error) + expect(subject).to raise_error(Puppet::Error) end end @@ -698,7 +700,7 @@ let(:params) { { purge: { 'preferences.d' => 'banana' } } } it do - is_expected.to raise_error(Puppet::Error) + expect(subject).to raise_error(Puppet::Error) end end @@ -706,7 +708,7 @@ let(:params) { { purge: { 'apt.conf.d' => 'banana' } } } it do - is_expected.to raise_error(Puppet::Error) + expect(subject).to raise_error(Puppet::Error) end end end diff --git a/spec/classes/apt_update_spec.rb b/spec/classes/apt_update_spec.rb index 71774550f8..c46771a52d 100644 --- a/spec/classes/apt_update_spec.rb +++ b/spec/classes/apt_update_spec.rb @@ -5,9 +5,9 @@ describe 'apt::update', type: :class do context "when apt::update['frequency']='always'" do { - 'a recent run' => Time.now.to_i, - 'we are due for a run' => 1_406_660_561, - 'the update-success-stamp file does not exist' => -1, + 'a recent run' => Time.now.to_i, + '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 "when $apt_update_last_success indicates #{desc}" do let(:facts) do @@ -17,14 +17,14 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, + id: 'Debian' + } }, - 'apt_update_last_success': factval, + apt_update_last_success: factval } end let(:pre_condition) do @@ -33,7 +33,7 @@ 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => false) end end end @@ -45,23 +45,24 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" } 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => false) end end - context 'and Exec[apt_update] refreshonly is overridden to true and has recent run' do + + context 'when Exec[apt_update] refreshonly is overridden to true and has recent run' do let(:facts) do { os: { @@ -69,14 +70,14 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, + id: 'Debian' + } }, - 'apt_update_last_success': Time.now.to_i, + apt_update_last_success: Time.now.to_i } end let(:pre_condition) do @@ -88,15 +89,16 @@ it 'skips 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' => true) + expect(subject).to contain_exec('apt_update').with('refreshonly' => true) end end end + context "when apt::update['frequency']='reluctantly'" do { - 'a recent run' => Time.now.to_i, - 'we are due for a run' => 1_406_660_561, - 'the update-success-stamp file does not exist' => -1, + 'a recent run' => Time.now.to_i, + '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 "when $apt_update_last_success indicates #{desc}" do let(:facts) do @@ -106,21 +108,21 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, + id: 'Debian' + } }, - 'apt_update_last_success': factval, + apt_update_last_success: factval } end let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" } 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => true) end end end @@ -132,26 +134,28 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" } 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => true) end end end + ['daily', 'weekly'].each do |update_frequency| context "when apt::update['frequency'] has the value of #{update_frequency}" do - { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| + pair = { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 } + pair.each_pair do |desc, factval| context "when $apt_update_last_success indicates #{desc}" do let(:facts) do { @@ -160,21 +164,21 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, + id: 'Debian' + } }, - 'apt_update_last_success': factval, + apt_update_last_success: factval } end let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => false) end end end @@ -186,23 +190,24 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, + id: 'Debian' + } }, - 'apt_update_last_success': Time.now.to_i, + apt_update_last_success: Time.now.to_i } end let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => true) end end + context 'when $apt_update_last_success is nil' do let(:facts) do { @@ -211,21 +216,21 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, + id: 'Debian' + } }, - 'apt_update_last_success': nil, + apt_update_last_success: nil } end let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } 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) + expect(subject).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 f1e42b5f67..26638e338a 100644 --- a/spec/defines/conf_spec.rb +++ b/spec/defines/conf_spec.rb @@ -12,13 +12,13 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let :title do @@ -29,7 +29,7 @@ let :default_params do { priority: '00', - content: "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n", + content: "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n" } end let :params do @@ -41,10 +41,10 @@ end it { - is_expected.to contain_file(filename).with('ensure' => 'present', - 'content' => %r{Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;}, - 'owner' => 'root', - 'group' => 'root') + expect(subject).to contain_file(filename).with('ensure' => 'present', + 'content' => %r{Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;}, + 'owner' => 'root', + 'group' => 'root') } context 'with notify_update = true (default)' do @@ -67,12 +67,12 @@ describe 'when creating a preference without content' do let :params do { - priority: '00', + priority: '00' } end it 'fails' do - is_expected.to raise_error(%r{pass in content}) + expect(subject).to raise_error(%r{pass in content}) end end @@ -80,7 +80,7 @@ let :params do { ensure: 'absent', - priority: '00', + priority: '00' } end @@ -89,9 +89,9 @@ end it { - is_expected.to contain_file(filename).with('ensure' => 'absent', - 'owner' => 'root', - 'group' => 'root') + expect(subject).to contain_file(filename).with('ensure' => 'absent', + 'owner' => 'root', + 'group' => 'root') } end end diff --git a/spec/defines/key_compat_spec.rb b/spec/defines/key_compat_spec.rb index d477937552..613c7fd999 100644 --- a/spec/defines/key_compat_spec.rb +++ b/spec/defines/key_compat_spec.rb @@ -21,8 +21,7 @@ def apt_key_example(title) end describe 'apt::key', type: :define do - GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F' - + let(:key_id) { '6F6B15509CF8E59E6E469F327F438280EF8D349F' } let(:facts) do { os: { @@ -30,18 +29,18 @@ def apt_key_example(title) name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let :title do - GPG_KEY_ID + key_id end let :pre_condition do @@ -51,14 +50,15 @@ def apt_key_example(title) 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) + expect(subject).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") + expect(subject).to contain_anchor("apt_key #{title} present") end end @@ -69,38 +69,40 @@ def apt_key_example(title) let :params do { - id: GPG_KEY_ID, + id: 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) + expect(subject).to contain_apt_key(title).with(id: 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") + expect(subject).to contain_anchor("apt_key #{key_id} present") end end describe 'ensure => absent' do let :params do { - ensure: 'absent', + 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) + expect(subject).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") + expect(subject).to contain_anchor("apt_key #{title} absent") end end @@ -110,53 +112,55 @@ def apt_key_example(title) content: 'GPG key content', source: 'http://apt.puppetlabs.com/pubkey.gpg', server: 'pgp.mit.edu', - options: 'debug', + options: 'debug' } end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with(contains_apt_key_example(title)) + expect(subject).to contain_apt_key(title).with(contains_apt_key_example(title)) end + it 'contains the apt_key present anchor' do - is_expected.to contain_anchor("apt_key #{title} present") + expect(subject).to contain_anchor("apt_key #{title} present") end end context 'when domain has dash' do let(:params) do { - server: 'p-gp.m-it.edu', + 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') + expect(subject).to contain_apt_key(title).with(id: title, + server: 'p-gp.m-it.edu') end end context 'with 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') + expect(subject).to contain_apt_key(title).with(id: title, + server: 'hkp://pgp.mit.edu') end end + context 'with url and 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') + expect(subject).to contain_apt_key(title).with(id: title, + server: 'hkp://pgp.mit.edu:80') end end end @@ -165,171 +169,178 @@ def apt_key_example(title) context 'when domain begins with a dash' do let(:params) do { - server: '-pgp.mit.edu', + server: '-pgp.mit.edu' } end it 'fails' do - is_expected .to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end context 'when domain begins with dot' do let(:params) do { - server: '.pgp.mit.edu', + server: '.pgp.mit.edu' } end it 'fails' do - is_expected .to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end context 'when domain ends with dot' do let(:params) do { - server: 'pgp.mit.edu.', + server: 'pgp.mit.edu.' } end it 'fails' do - is_expected .to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'when url character limit is exceeded' do let :params do { - server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu', + server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with incorrect port number url' do let :params do { - server: 'hkp://pgp.mit.edu:8008080', + server: 'hkp://pgp.mit.edu:8008080' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end - context 'with incorrect protocol for url' do + + context 'with incorrect protocol for url' do let :params do { - server: 'abc://pgp.mit.edu:80', + server: 'abc://pgp.mit.edu:80' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with missing port number url' do let :params do { - server: 'hkp://pgp.mit.edu:', + server: 'hkp://pgp.mit.edu:' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with url ending with a dot' do let :params do { - server: 'hkp://pgp.mit.edu.', + server: 'hkp://pgp.mit.edu.' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with url begin with a dash' do let(:params) do { - server: 'hkp://-pgp.mit.edu', + server: 'hkp://-pgp.mit.edu' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with invalid key' do let :title do 'Out of rum. Why? Why are we out of rum?' end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end context 'with invalid source' do let :params do { - source: 'afp://puppetlabs.com/key.gpg', + source: 'afp://puppetlabs.com/key.gpg' } end it 'fails' do - is_expected.to raise_error(%r{evaluating a Resource}) + expect(subject).to raise_error(%r{evaluating a Resource}) end end context 'with invalid content' do let :params do { - content: [], + content: [] } end it 'fails' do - is_expected.to raise_error(%r{expects a}) + expect(subject).to raise_error(%r{expects a}) end end context 'with invalid server' do let :params do { - server: 'two bottles of rum', + server: 'two bottles of rum' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end context 'with invalid keyserver_options' do let :params do { - options: {}, + options: {} } end it 'fails' do - is_expected.to raise_error(%r{expects a}) + expect(subject).to raise_error(%r{expects a}) end end context 'with invalid ensure' do let :params do { - ensure: 'foo', + ensure: 'foo' } end it 'fails' do - is_expected.to raise_error(%r{Enum\['absent', 'present', 'refreshed'\]}) + expect(subject).to raise_error(%r{Enum\['absent', 'present', 'refreshed'\]}) end end @@ -339,21 +350,21 @@ def apt_key_example(title) end it 'contains the duplicate apt::key resource' do - is_expected.to contain_apt__key('duplicate').with(id: title, - ensure: 'present') + expect(subject).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') + expect(subject).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(apt_key_example(title)) + expect(subject).to contain_apt_key('duplicate').with(apt_key_example(title)) end it 'does not contain the original apt_key' do - is_expected.not_to contain_apt_key(title) + expect(subject).not_to contain_apt_key(title) end end @@ -363,7 +374,7 @@ def apt_key_example(title) end it 'informs the user of the impossibility' do - is_expected.to raise_error(%r{already ensured as absent}) + expect(subject).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 fd63965f7b..59695006c2 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -51,13 +51,13 @@ def absent_apt_key(title) name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end @@ -68,10 +68,11 @@ def absent_apt_key(title) describe 'normal operation' do describe 'default options' do it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with(default_apt_key_example(title)) + expect(subject).to contain_apt_key(title).with(default_apt_key_example(title)) end + it 'contains the apt_key present anchor' do - is_expected.to contain_anchor("apt_key #{title} present") + expect(subject).to contain_anchor("apt_key #{title} present") end end @@ -82,42 +83,44 @@ def absent_apt_key(title) let :params do { - id: GPG_KEY_ID, + id: GPG_KEY_ID } end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with(title_key_example) + expect(subject).to contain_apt_key(title).with(title_key_example) end + it 'contains the apt_key present anchor' do - is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present") + expect(subject).to contain_anchor("apt_key #{GPG_KEY_ID} present") end end describe 'ensure => absent' do let :params do { - ensure: 'absent', + ensure: 'absent' } end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with(absent_apt_key(title)) + expect(subject).to contain_apt_key(title).with(absent_apt_key(title)) end + it 'contains the apt_key absent anchor' do - is_expected.to contain_anchor("apt_key #{title} absent") + expect(subject).to contain_anchor("apt_key #{title} absent") end end describe 'ensure => refreshed' do let :params do { - ensure: 'refreshed', + ensure: 'refreshed' } end it 'contains the apt_key with refresh => true' do - is_expected.to contain_apt_key(title).with( + expect(subject).to contain_apt_key(title).with( ensure: 'present', refresh: true, ) @@ -130,53 +133,55 @@ def absent_apt_key(title) content: 'GPG key content', source: 'http://apt.puppetlabs.com/pubkey.gpg', server: 'pgp.mit.edu', - options: 'debug', + options: 'debug' } end it 'contains the apt_key' do - is_expected.to contain_apt_key(title).with(bunch_things_apt_key_example(title, params)) + expect(subject).to contain_apt_key(title).with(bunch_things_apt_key_example(title, params)) end + it 'contains the apt_key present anchor' do - is_expected.to contain_anchor("apt_key #{title} present") + expect(subject).to contain_anchor("apt_key #{title} present") end end context 'when domain with dash' do let(:params) do { - server: 'p-gp.m-it.edu', + 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') + expect(subject).to contain_apt_key(title).with(id: title, + server: 'p-gp.m-it.edu') end end context 'with 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') + expect(subject).to contain_apt_key(title).with(id: title, + server: 'hkp://pgp.mit.edu') end end + context 'when 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') + expect(subject).to contain_apt_key(title).with(id: title, + server: 'hkp://pgp.mit.edu:80') end end end @@ -185,159 +190,166 @@ def absent_apt_key(title) context 'when domain begin with dash' do let(:params) do { - server: '-pgp.mit.edu', + server: '-pgp.mit.edu' } end it 'fails' do - is_expected .to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end context 'when domain begin with dot' do let(:params) do { - server: '.pgp.mit.edu', + server: '.pgp.mit.edu' } end it 'fails' do - is_expected .to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end context 'when domain end with dot' do let(:params) do { - server: 'pgp.mit.edu.', + server: 'pgp.mit.edu.' } end it 'fails' do - is_expected .to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'when character url exceeded' do let :params do { - server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu', + server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with incorrect port number url' do let :params do { - server: 'hkp://pgp.mit.edu:8008080', + server: 'hkp://pgp.mit.edu:8008080' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with incorrect protocol for url' do let :params do { - server: 'abc://pgp.mit.edu:80', + server: 'abc://pgp.mit.edu:80' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with missing port number url' do let :params do { - server: 'hkp://pgp.mit.edu:', + server: 'hkp://pgp.mit.edu:' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with url ending with a dot' do let :params do { - server: 'hkp://pgp.mit.edu.', + server: 'hkp://pgp.mit.edu.' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'when url begins with a dash' do let(:params) do { - server: 'hkp://-pgp.mit.edu', + server: 'hkp://-pgp.mit.edu' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end + context 'with invalid key' do let :title do 'Out of rum. Why? Why are we out of rum?' end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end context 'with invalid source' do let :params do { - source: 'afp://puppetlabs.com/key.gpg', + source: 'afp://puppetlabs.com/key.gpg' } end it 'fails' do - is_expected.to raise_error(%r{evaluating a Resource}) + expect(subject).to raise_error(%r{evaluating a Resource}) end end context 'with invalid content' do let :params do { - content: [], + content: [] } end it 'fails' do - is_expected.to raise_error(%r{expects a}) + expect(subject).to raise_error(%r{expects a}) end end context 'with invalid server' do let :params do { - server: 'two bottles of rum', + server: 'two bottles of rum' } end it 'fails' do - is_expected.to raise_error(%r{expects a match}) + expect(subject).to raise_error(%r{expects a match}) end end context 'with invalid options' do let :params do { - options: {}, + options: {} } end it 'fails' do - is_expected.to raise_error(%r{expects a}) + expect(subject).to raise_error(%r{expects a}) end end @@ -345,12 +357,12 @@ def absent_apt_key(title) ['foo', 'aabsent', 'absenta', 'apresent', 'presenta', 'refresh', 'arefreshed', 'refresheda'].each do |param| let :params do { - ensure: param, + ensure: param } end it 'fails' do - is_expected.to raise_error(%r{for Enum\['absent', 'present', 'refreshed'\], got}) + expect(subject).to raise_error(%r{for Enum\['absent', 'present', 'refreshed'\], got}) end end end @@ -362,19 +374,21 @@ def absent_apt_key(title) end it 'contains two apt::key resource - duplicate' do - is_expected.to contain_apt__key('duplicate').with(id: title, - ensure: 'present') + expect(subject).to contain_apt__key('duplicate').with(id: title, + ensure: 'present') end + it 'contains two apt::key resource - title' do - is_expected.to contain_apt__key(title).with(id: title, - ensure: 'present') + expect(subject).to contain_apt__key(title).with(id: title, + ensure: 'present') end it 'contains only a single apt_key - duplicate' do - is_expected.to contain_apt_key('duplicate').with(default_apt_key_example(title)) + expect(subject).to contain_apt_key('duplicate').with(default_apt_key_example(title)) end + it 'contains only a single apt_key - no title' do - is_expected.not_to contain_apt_key(title) + expect(subject).not_to contain_apt_key(title) end end @@ -385,7 +399,7 @@ def absent_apt_key(title) end it 'informs the user of the impossibility' do - is_expected.to raise_error(%r{already ensured as absent}) + expect(subject).to raise_error(%r{already ensured as absent}) end end end @@ -399,7 +413,7 @@ def absent_apt_key(title) end it 'uses default keyserver' do - is_expected.to contain_apt_key(title).with_server('keyserver.example.com') + expect(subject).to contain_apt_key(title).with_server('keyserver.example.com') end end @@ -411,7 +425,7 @@ def absent_apt_key(title) end it 'uses default keyserver' do - is_expected.to contain_apt_key(title).with_options('http-proxy=http://proxy.example.com:8080') + expect(subject).to contain_apt_key(title).with_options('http-proxy=http://proxy.example.com:8080') end end end diff --git a/spec/defines/mark_spec.rb b/spec/defines/mark_spec.rb index 5375fe236f..e73901e95a 100644 --- a/spec/defines/mark_spec.rb +++ b/spec/defines/mark_spec.rb @@ -14,37 +14,37 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end context 'with correct seting' do let :params do { - 'setting' => 'manual', + 'setting' => 'manual' } end it { - is_expected.to contain_exec('apt-mark manual mysource') + expect(subject).to contain_exec('apt-mark manual mysource') } end describe 'with wrong setting' do let :params do { - 'setting' => 'foobar', + 'setting' => 'foobar' } end it do - is_expected.to raise_error(Puppet::PreformattedError, %r{expects a match for Enum\['auto', 'hold', 'manual', 'unhold'\], got 'foobar'}) + expect(subject).to raise_error(Puppet::PreformattedError, %r{expects a match for Enum\['auto', 'hold', 'manual', 'unhold'\], got 'foobar'}) end end @@ -65,12 +65,12 @@ let :params do { - 'setting' => 'manual', + 'setting' => 'manual' } end it do - is_expected.to contain_exec("apt-mark manual #{title}") + expect(subject).to contain_exec("apt-mark manual #{title}") end end end @@ -94,12 +94,12 @@ let :params do { - 'setting' => 'manual', + 'setting' => 'manual' } end it do - is_expected.to raise_error(Puppet::PreformattedError, %r{Invalid package name: #{title}}) + expect(subject).to raise_error(Puppet::PreformattedError, %r{Invalid package name: #{title}}) end end end diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index 5edc79cc6d..1dd02980af 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -12,13 +12,13 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let(:title) { 'my_pin' } @@ -31,7 +31,7 @@ let :params do { 'packages' => 'vim', - 'version' => '1', + 'version' => '1' } end @@ -42,7 +42,7 @@ let :params do { 'packages' => 'vim', - 'origin' => 'test', + 'origin' => 'test' } end @@ -52,33 +52,34 @@ context 'without defaults' do let :params do { - 'explanation' => 'foo', - 'order' => 99, - 'release' => '1', - 'codename' => 'bar', + 'explanation' => 'foo', + 'order' => 99, + 'release' => '1', + 'codename' => 'bar', 'release_version' => '2', - 'component' => 'baz', - 'originator' => 'foobar', - 'label' => 'foobaz', - 'priority' => 10, + 'component' => 'baz', + 'originator' => 'foobar', + 'label' => 'foobaz', + 'priority' => 10 } end 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) + expect(subject).to contain_apt__setting('pref-my_pin').with('priority' => 99) } end context 'with ensure absent' do let :params do { - 'ensure' => 'absent', + 'ensure' => 'absent' } end it { - is_expected.to contain_apt__setting('pref-my_pin').with('ensure' => 'absent') + expect(subject).to contain_apt__setting('pref-my_pin').with('ensure' => 'absent') } end @@ -92,65 +93,65 @@ context 'with invalid order' do let :params do { - 'order' => 'foo', + 'order' => 'foo' } end it do - is_expected.to raise_error(Puppet::Error, %r{expects an Integer value, got String}) + expect(subject).to raise_error(Puppet::Error, %r{expects an Integer value, got String}) end end context 'with packages == * and version' do let :params do { - 'version' => '1', + 'version' => '1' } end it do - is_expected.to raise_error(Puppet::Error, %r{parameter version cannot be used in general form}) + expect(subject).to raise_error(Puppet::Error, %r{parameter version cannot be used in general form}) end end context 'with packages == * and release and origin' do let :params do { - 'origin' => 'test', - 'release' => 'foo', + 'origin' => 'test', + 'release' => 'foo' } end it do - is_expected.to raise_error(Puppet::Error, %r{parameters release and origin are mutually exclusive}) + expect(subject).to raise_error(Puppet::Error, %r{parameters release and origin are mutually exclusive}) end end context 'with specific release and origin' do let :params do { - 'release' => 'foo', - 'origin' => 'test', - 'packages' => 'vim', + 'release' => 'foo', + 'origin' => 'test', + 'packages' => 'vim' } end it do - is_expected.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) + expect(subject).to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) end end context 'with specific version and origin' do let :params do { - 'version' => '1', - 'origin' => 'test', - 'packages' => 'vim', + 'version' => '1', + 'origin' => 'test', + 'packages' => 'vim' } end it do - is_expected.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) + expect(subject).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 00424dccb7..05718ebc34 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -23,12 +23,12 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, puppet_vardir: '/opt/puppetlabs/puppet/cache' } @@ -37,8 +37,9 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) let(:title) { 'ppa:needs/substitution' } it { is_expected.not_to contain_package('python-software-properties') } + it { - is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') + expect(subject).to contain_exec('add-apt-repository-ppa:needs/substitution') .that_notifies('Class[Apt::Update]') .with(*ppa_exec_params('needs', 'substitution')) } @@ -58,13 +59,13 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end @@ -91,13 +92,13 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end @@ -115,21 +116,21 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '15', - full: '15.10', + full: '15.10' }, distro: { codename: 'wily', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, - puppet_vardir: '/opt/puppetlabs/puppet/cache', + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end let(:title) { 'ppa:user/foo' } it { - is_expected.to contain_exec('add-apt-repository-ppa:user/foo') + expect(subject).to contain_exec('add-apt-repository-ppa:user/foo') .that_notifies('Class[Apt::Update]') .with(*ppa_exec_params('user', 'foo', 'wily')) } @@ -143,7 +144,7 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) let :params do { package_name: 'software-properties-common', - package_manage: true, + package_manage: true } end @@ -154,22 +155,23 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, - puppet_vardir: '/opt/puppetlabs/puppet/cache', + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end let(:title) { 'ppa:needs/substitution' } it { is_expected.to contain_package('software-properties-common') } + it { - is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') + expect(subject).to contain_exec('add-apt-repository-ppa:needs/substitution') .that_notifies('Class[Apt::Update]') .with(*ppa_exec_params('needs', 'substitution')) } @@ -187,28 +189,29 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, - puppet_vardir: '/opt/puppetlabs/puppet/cache', + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end let :params do { - package_manage: false, + package_manage: false } end let(:title) { 'ppa:needs/substitution' } it { is_expected.not_to contain_package('python-software-properties') } + it { - is_expected.to contain_exec('add-apt-repository-ppa:needs/substitution') + expect(subject).to contain_exec('add-apt-repository-ppa:needs/substitution') .that_notifies('Class[Apt::Update]') .with(*ppa_exec_params('needs', 'substitution')) } @@ -228,21 +231,21 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, - puppet_vardir: '/opt/puppetlabs/puppet/cache', + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end let :params do { package_manage: true, - require: 'Apt::Ppa[ppa:user/foo2]', + require: 'Apt::Ppa[ppa:user/foo2]' } end @@ -250,8 +253,9 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) 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') + expect(subject).to contain_exec('add-apt-repository-ppa:user/foo') .that_notifies('Class[Apt::Update]') .with(*ppa_exec_params('user', 'foo')) } @@ -271,28 +275,29 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, - puppet_vardir: '/opt/puppetlabs/puppet/cache', + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end let :params do { - 'package_manage' => true, + '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') + expect(subject).to contain_exec('add-apt-repository-ppa:user/foo') .that_notifies('Class[Apt::Update]') .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8080'])) } @@ -312,28 +317,29 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, - puppet_vardir: '/opt/puppetlabs/puppet/cache', + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end let :params do { - package_manage: true, + 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') + expect(subject).to contain_exec('add-apt-repository-ppa:user/foo') .that_notifies('Class[Apt::Update]') .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180'])) } @@ -353,28 +359,29 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, - puppet_vardir: '/opt/puppetlabs/puppet/cache', + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end let :params do { - package_manage: true, + 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') + expect(subject).to contain_exec('add-apt-repository-ppa:user/foo') .that_notifies('Class[Apt::Update]') .with(*ppa_exec_params('user', 'foo', 'trusty', ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'])) } @@ -392,14 +399,14 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: 'trusty', - id: 'Ubuntu', - }, + id: 'Ubuntu' + } }, - puppet_vardir: '/opt/puppetlabs/puppet/cache', + puppet_vardir: '/opt/puppetlabs/puppet/cache' } end @@ -407,15 +414,15 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) let :params do { - ensure: 'absent', + ensure: 'absent' } end it { - is_expected.to contain_tidy("remove-apt-repository-script-#{title}") + expect(subject).to contain_tidy("remove-apt-repository-script-#{title}") .with('path' => '/opt/puppetlabs/puppet/cache/add-apt-repository-user-ubuntu-foo-trusty.sh') - is_expected.to contain_tidy("remove-apt-repository-#{title}") + expect(subject).to contain_tidy("remove-apt-repository-#{title}") .with('path' => '/etc/apt/sources.list.d/user-ubuntu-foo-trusty.list') .that_notifies('Class[Apt::Update]') } @@ -430,20 +437,20 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Ubuntu', release: { major: '18', - full: '18.04', + full: '18.04' }, distro: { codename: nil, - id: 'Ubuntu', - }, - }, + id: 'Ubuntu' + } + } } end let(:title) { 'ppa:user/foo' } it do - is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required}) + expect(subject).to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required}) end end @@ -455,20 +462,20 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) name: 'Debian', release: { major: '6', - full: '6.0.7', + full: '6.0.7' }, distro: { codename: 'wheezy', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let(:title) { 'ppa:user/foo' } it do - is_expected.to raise_error(Puppet::Error, %r{not currently supported on Debian}) + expect(subject).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 97ebdc4658..7a71896053 100644 --- a/spec/defines/setting_spec.rb +++ b/spec/defines/setting_spec.rb @@ -11,13 +11,13 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let(:title) { 'conf-teddybear' } @@ -27,11 +27,11 @@ describe 'when using the defaults' do context 'without source or content' do it do - is_expected.to raise_error(Puppet::Error, %r{needs either of }) + expect(subject).to raise_error(Puppet::Error, %r{needs either of }) end end - context 'with title=conf-teddybear ' do + 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]') } @@ -55,10 +55,10 @@ 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', - source: params[:source].to_s) + expect(subject).to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with(ensure: 'file', + owner: 'root', + group: 'root', + source: params[:source].to_s) } end @@ -66,10 +66,10 @@ 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', - content: params[:content].to_s) + expect(subject).to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with(ensure: 'file', + owner: 'root', + group: 'root', + content: params[:content].to_s) } end end @@ -87,13 +87,13 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let(:title) { 'conf-teddybear' } @@ -109,7 +109,7 @@ let(:params) { default_params.merge(source: 'la') } it do - is_expected.to raise_error(Puppet::Error, %r{cannot have both }) + expect(subject).to raise_error(Puppet::Error, %r{cannot have both }) end end @@ -118,7 +118,7 @@ let(:params) { default_params } it do - is_expected.to raise_error(Puppet::Error, %r{must start with either}) + expect(subject).to raise_error(Puppet::Error, %r{must start with either}) end end @@ -126,7 +126,7 @@ let(:params) { default_params.merge(ensure: 'banana') } it do - is_expected.to raise_error(Puppet::Error, %r{Enum\['absent', 'file', 'present'\]}) + expect(subject).to raise_error(Puppet::Error, %r{Enum\['absent', 'file', 'present'\]}) end end @@ -147,7 +147,7 @@ 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') + expect(subject).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 d7dfb78695..55be585aa6 100644 --- a/spec/defines/source_compat_spec.rb +++ b/spec/defines/source_compat_spec.rb @@ -3,12 +3,8 @@ require 'spec_helper' describe 'apt::source', type: :define do - GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F' - - let :title do - 'my_source' - end - + let(:id) { '6F6B15509CF8E59E6E469F327F438280EF8D349F' } + let(:title) { 'my_source' } let :facts do { os: { @@ -16,13 +12,13 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end @@ -30,53 +26,53 @@ 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(%r{# my_source\ndeb-src http://debian.mirror.iweb.ca/debian/ stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb-src http://debian.mirror.iweb.ca/debian/ stretch main\n}) } end context 'with no defaults' do let :params do { - 'comment' => 'foo', - 'location' => 'http://debian.mirror.iweb.ca/debian/', - 'release' => 'sid', - 'repos' => 'testing', - 'include' => { 'src' => false }, - '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', + 'include' => { 'src' => false }, + 'key' => id, + 'pin' => '10', + 'architecture' => 'x86_64', + 'allow_unsigned' => true } end it { - is_expected.to contain_apt__setting('list-my_source').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n}) - .without_content(%r{deb-src}) + expect(subject).to contain_apt__setting('list-my_source').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n}) + .without_content(%r{deb-src}) } 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') + expect(subject).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) + expect(subject).to contain_apt__key("Add key: #{id} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with('ensure' => 'present', + 'id' => id) } end context 'when allow_insecure true' do let :params do { - 'include' => { 'src' => false }, - 'location' => 'http://debian.mirror.iweb.ca/debian/', - 'allow_insecure' => true, + 'include' => { 'src' => false }, + 'location' => 'http://debian.mirror.iweb.ca/debian/', + 'allow_insecure' => true } end @@ -86,9 +82,9 @@ context 'when allow_unsigned true' do let :params do { - 'include' => { 'src' => false }, - 'location' => 'http://debian.mirror.iweb.ca/debian/', - 'allow_unsigned' => true, + 'include' => { 'src' => false }, + 'location' => 'http://debian.mirror.iweb.ca/debian/', + 'allow_unsigned' => true } end @@ -98,25 +94,25 @@ context 'with architecture equals x86_64' do let :params do { - 'location' => 'http://debian.mirror.iweb.ca/debian/', - 'architecture' => 'x86_64', + 'location' => 'http://debian.mirror.iweb.ca/debian/', + 'architecture' => 'x86_64' } end it { - is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb \[arch=x86_64\] http://debian.mirror.iweb.ca/debian/ stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb \[arch=x86_64\] http://debian.mirror.iweb.ca/debian/ stretch main\n}) } end context 'with ensure => absent' do let :params do { - 'ensure' => 'absent', + 'ensure' => 'absent' } end it { - is_expected.to contain_apt__setting('list-my_source').with('ensure' => 'absent') + expect(subject).to contain_apt__setting('list-my_source').with('ensure' => 'absent') } end @@ -129,17 +125,17 @@ name: 'Debian', release: { major: '8', - full: '8.0', + full: '8.0' }, distro: { - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end it do - is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required}) + expect(subject).to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required}) end end end diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 641089568e..e9c0cf28af 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -3,16 +3,9 @@ require 'spec_helper' describe 'apt::source' do - GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F' - - let :pre_condition do - 'class { "apt": }' - end - - let :title do - 'my_source' - end - + let(:id) { '6F6B15509CF8E59E6E469F327F438280EF8D349F' } + let(:title) { 'my_source' } + let(:pre_condition) { 'class { "apt": }' } let :facts do { os: { @@ -20,28 +13,29 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end context 'with defaults' do context 'without location' do it do - is_expected.to raise_error(Puppet::Error, %r{source entry without specifying a location}) + expect(subject).to raise_error(Puppet::Error, %r{source entry without specifying a location}) end end + context 'with location' do let(:params) { { location: 'hello.there' } } 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}) - is_expected.not_to contain_package('apt-transport-https') + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n}) + expect(subject).not_to contain_package('apt-transport-https') } end end @@ -53,21 +47,21 @@ location: 'hello.there', pin: { 'release' => 'wishwash', 'explanation' => 'wishwash', - 'priority' => 1001 }, + 'priority' => 1001 } } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{hello.there stretch 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_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', - priority: 1001, - explanation: 'wishwash', - release: 'wishwash') + expect(subject).to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + priority: 1001, + explanation: 'wishwash', + release: 'wishwash') } end @@ -78,27 +72,27 @@ location: 'http://debian.mirror.iweb.ca/debian/', release: 'sid', repos: 'testing', - key: GPG_KEY_ID, + key: id, pin: '10', architecture: 'x86_64', - allow_unsigned: true, + allow_unsigned: true } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n}) - .without_content(%r{deb-src}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n}) + .without_content(%r{deb-src}) } 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') + expect(subject).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) + expect(subject).to contain_apt__key("Add key: #{id} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'present', + id: id) } end @@ -111,36 +105,36 @@ repos: 'testing', key: { 'ensure' => 'refreshed', - 'id' => GPG_KEY_ID, + 'id' => id, 'server' => 'pgp.mit.edu', 'content' => 'GPG key content', - 'source' => 'http://apt.puppetlabs.com/pubkey.gpg', - 'weak_ssl' => true, + 'source' => 'http://apt.puppetlabs.com/pubkey.gpg', + 'weak_ssl' => true }, pin: '10', architecture: 'x86_64', - allow_unsigned: true, + allow_unsigned: true } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n}) - .without_content(%r{deb-src}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n}) + .without_content(%r{deb-src}) } 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') + expect(subject).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: 'refreshed', - id: GPG_KEY_ID, - server: 'pgp.mit.edu', - content: 'GPG key content', - source: 'http://apt.puppetlabs.com/pubkey.gpg', - weak_ssl: true) + expect(subject).to contain_apt__key("Add key: #{id} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with(ensure: 'refreshed', + id: GPG_KEY_ID, + server: 'pgp.mit.edu', + content: 'GPG key content', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + weak_ssl: true) } end end @@ -149,12 +143,12 @@ let :params do { location: 'hello.there', - allow_insecure: true, + allow_insecure: true } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[allow-insecure=yes\] hello.there stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[allow-insecure=yes\] hello.there stretch main\n}) } end @@ -162,12 +156,12 @@ let :params do { location: 'hello.there', - allow_unsigned: true, + allow_unsigned: true } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[trusted=yes\] hello.there stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[trusted=yes\] hello.there stretch main\n}) } end @@ -175,12 +169,12 @@ let :params do { location: 'hello.there', - check_valid_until: false, + check_valid_until: false } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[check-valid-until=false\] hello.there stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb \[check-valid-until=false\] hello.there stretch main\n}) } end @@ -188,12 +182,12 @@ let :params do { location: 'hello.there', - check_valid_until: true, + check_valid_until: true } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there stretch main\n}) } end @@ -201,12 +195,12 @@ let :params do { location: 'hello.there', - keyring: '/usr/share/keyrings/foo-archive-keyring.gpg', + keyring: '/usr/share/keyrings/foo-archive-keyring.gpg' } end it { - is_expected.to contain_apt__setting('list-my_source') + expect(subject).to contain_apt__setting('list-my_source') .with(ensure: 'present') .with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n}) } @@ -218,12 +212,12 @@ location: 'hello.there', architecture: 'amd64', allow_unsigned: true, - keyring: '/usr/share/keyrings/foo-archive-keyring.gpg', + keyring: '/usr/share/keyrings/foo-archive-keyring.gpg' } end it { - is_expected.to contain_apt__setting('list-my_source') + expect(subject).to contain_apt__setting('list-my_source') .with(ensure: 'present') .with_content(%r{# my_source\ndeb \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there stretch main\n}) } @@ -233,12 +227,12 @@ let :params do { location: 'HTTPS://foo.bar', - allow_unsigned: false, + allow_unsigned: false } end it { - is_expected.to contain_package('apt-transport-https') + expect(subject).to contain_package('apt-transport-https') } end @@ -250,26 +244,26 @@ name: 'Debian', release: { major: '9', - full: '9.0', + full: '9.0' }, distro: { codename: 'stretch', - id: 'Debian', - }, + id: 'Debian' + } }, - puppetversion: Puppet.version, + puppetversion: Puppet.version } end let :params do { location: 'HTTPS://foo.bar', allow_unsigned: false, - release: 'customrelease', + release: 'customrelease' } end it { - is_expected.to contain_package('apt-transport-https') + expect(subject).to contain_package('apt-transport-https') } end @@ -281,24 +275,24 @@ name: 'Debian', release: { major: '10', - full: '10.0', + full: '10.0' }, distro: { codename: 'buster', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let :params do { location: 'https://foo.bar', - allow_unsigned: false, + allow_unsigned: false } end it { - is_expected.not_to contain_package('apt-transport-https') + expect(subject).not_to contain_package('apt-transport-https') } end @@ -310,25 +304,25 @@ name: 'Debian', release: { major: '7', - full: '7.0', + full: '7.0' }, distro: { codename: 'wheezy', - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let :params do { location: 'hello.there', include: { 'deb' => false, 'src' => true }, - architecture: 'x86_64', + architecture: 'x86_64' } end 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}) + expect(subject).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 @@ -339,12 +333,12 @@ let :params do { location: 'hello.there', - include: { 'deb' => false, 'src' => true }, + include: { 'deb' => false, 'src' => true } } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there stretch main\n}) } end @@ -352,12 +346,12 @@ let :params do { location: 'hello.there', - include: { 'src' => true }, + include: { 'src' => true } } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there stretch main\ndeb-src hello.there stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb hello.there stretch main\ndeb-src hello.there stretch main\n}) } end @@ -365,13 +359,14 @@ let :params do { include: { 'deb' => false }, - location: 'hello.there', + location: 'hello.there' } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n}) + expect(subject).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(%r{deb hello.there wheezy main\n}) } end @@ -379,25 +374,26 @@ let :params do { include: { 'deb' => false, 'src' => true }, - location: 'hello.there', + location: 'hello.there' } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there stretch main\n}) + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there stretch main\n}) } + it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there stretch main\n}) } end context 'with ensure => absent' do let :params do { - ensure: 'absent', + ensure: 'absent' } end it { - is_expected.to contain_apt__setting('list-my_source').with(ensure: 'absent') + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'absent') } end @@ -410,18 +406,18 @@ name: 'Debian', release: { major: '8', - full: '8.0', + full: '8.0' }, distro: { - id: 'Debian', - }, - }, + id: 'Debian' + } + } } end let(:params) { { location: 'hello.there' } } it do - is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required}) + expect(subject).to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required}) end end @@ -435,19 +431,19 @@ let :params do { location: 'hello.there', - pin: true, + pin: true } end it do - is_expected.to raise_error(Puppet::Error, %r{expects a value}) + expect(subject).to raise_error(Puppet::Error, %r{expects a value}) end end context 'with notify_update = undef (default)' do let :params do { - location: 'hello.there', + location: 'hello.there' } end @@ -458,7 +454,7 @@ let :params do { location: 'hello.there', - notify_update: true, + notify_update: true } end @@ -469,7 +465,7 @@ let :params do { location: 'hello.there', - notify_update: false, + notify_update: false } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07db73426e..c6e5525752 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,7 @@ default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ @@ -26,7 +26,7 @@ begin default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 9f0cd18b7b..b0e6728217 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -9,11 +9,11 @@ c.before :suite do # lsb-release is needed for facter 3 (puppet 6) to resolve os.distro facts. Not needed with facter # 4 (puppet 7). - lsb_package = <<-MANIFEST -package { 'lsb-release': - ensure => installed, -} -MANIFEST + lsb_package = <<~MANIFEST + package { 'lsb-release': + ensure => installed, + } + MANIFEST include PuppetLitmus extend PuppetLitmus apply_manifest(lsb_package) @@ -40,6 +40,7 @@ def retry_on_error_matching(max_retry_count = MAX_RETRY_COUNT, retry_wait_interv yield rescue StandardError => e raise('Attempted this %{value0} times. Raising %{value1}' % { value0: max_retry_count, value1: e }) unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher) + sleep retry_wait_interval_secs retry end diff --git a/spec/unit/facter/apt_dist_has_updates_spec.rb b/spec/unit/facter/apt_dist_has_updates_spec.rb index 3ed4f3b213..b5b05b6f05 100644 --- a/spec/unit/facter/apt_dist_has_updates_spec.rb +++ b/spec/unit/facter/apt_dist_has_updates_spec.rb @@ -11,6 +11,7 @@ before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat') end + it { is_expected.to be_nil } end @@ -20,6 +21,7 @@ allow(File).to receive(:executable?) # Stub all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false) end + it { is_expected.to be_nil } end @@ -36,6 +38,7 @@ "Conf planet.rb (22-2~bpo8+1 Debian Backports:stretch-backports [all])\n" allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output) end + it { is_expected.to be true } end end diff --git a/spec/unit/facter/apt_dist_package_security_updates_spec.rb b/spec/unit/facter/apt_dist_package_security_updates_spec.rb index f16ff52657..1e8aeb8a58 100644 --- a/spec/unit/facter/apt_dist_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_security_updates_spec.rb @@ -11,7 +11,8 @@ before(:each) do allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false) end - it { is_expected.to be nil } + + it { is_expected.to be_nil } end describe 'when apt has updates' do diff --git a/spec/unit/facter/apt_dist_package_updates_spec.rb b/spec/unit/facter/apt_dist_package_updates_spec.rb index a27d607bab..43e2d7e7d9 100644 --- a/spec/unit/facter/apt_dist_package_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_updates_spec.rb @@ -11,7 +11,8 @@ before(:each) do allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false) end - it { is_expected.to be nil } + + it { is_expected.to be_nil } end describe 'when apt has updates' do @@ -28,6 +29,7 @@ "Conf planet.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n" allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output) end + it { is_expected.to eq(['extremetuxracer', 'planet.rb']) } end end diff --git a/spec/unit/facter/apt_dist_security_updates_spec.rb b/spec/unit/facter/apt_dist_security_updates_spec.rb index aa21e649c6..baaf0484e9 100644 --- a/spec/unit/facter/apt_dist_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_security_updates_spec.rb @@ -11,7 +11,8 @@ before(:each) do allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false) end - it { is_expected.to be nil } + + it { is_expected.to be_nil } end describe 'when apt has security updates' do diff --git a/spec/unit/facter/apt_dist_updates_spec.rb b/spec/unit/facter/apt_dist_updates_spec.rb index 21352b5567..ac87f666a1 100644 --- a/spec/unit/facter/apt_dist_updates_spec.rb +++ b/spec/unit/facter/apt_dist_updates_spec.rb @@ -11,7 +11,8 @@ before(:each) do allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false) end - it { is_expected.to be nil } + + it { is_expected.to be_nil } end describe 'when apt has updates' do @@ -28,6 +29,7 @@ "Conf planet.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n" allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output) end + it { is_expected.to eq(2) } end end diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index 0f0a74094c..77a95b4391 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -11,6 +11,7 @@ before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat') end + it { is_expected.to be_nil } end @@ -20,6 +21,7 @@ allow(File).to receive(:executable?) # Stub all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false) end + it { is_expected.to be_nil } end @@ -35,6 +37,7 @@ "Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n" allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(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 28516cac48..d546715426 100644 --- a/spec/unit/facter/apt_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_package_security_updates_spec.rb @@ -11,7 +11,8 @@ before(:each) do allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false) end - it { is_expected.to be nil } + + it { is_expected.to be_nil } end describe 'when apt has updates' do diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index 69db490dd6..7960306e00 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -11,7 +11,8 @@ before(:each) do allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false) end - it { is_expected.to be nil } + + it { is_expected.to be_nil } end describe 'when apt has updates' do @@ -26,6 +27,7 @@ "Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n" allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output) end + it { 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 7621872d08..b60724514e 100644 --- a/spec/unit/facter/apt_reboot_required_spec.rb +++ b/spec/unit/facter/apt_reboot_required_spec.rb @@ -13,7 +13,8 @@ allow(File).to receive(:file?).and_return(true) allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(true) end - it { is_expected.to eq true } + + it { is_expected.to be true } end describe 'if a reboot is not required' do @@ -22,6 +23,7 @@ allow(File).to receive(:file?).and_return(true) allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(false) end - it { is_expected.to eq false } + + it { is_expected.to be false } end end diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index 9d3e587a89..25ba3114ed 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -11,7 +11,8 @@ before(:each) do allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false) end - it { is_expected.to be nil } + + it { is_expected.to be_nil } end describe 'when apt has security updates' do diff --git a/spec/unit/facter/apt_update_last_success_spec.rb b/spec/unit/facter/apt_update_last_success_spec.rb index c0b028aac9..05a12240aa 100644 --- a/spec/unit/facter/apt_update_last_success_spec.rb +++ b/spec/unit/facter/apt_update_last_success_spec.rb @@ -11,7 +11,7 @@ it 'has a value of -1' do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:exist?).with('/var/lib/apt/periodic/update-success-stamp').and_return(false) - is_expected.to eq(-1) + expect(subject).to eq(-1) end end @@ -20,7 +20,7 @@ allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:exist?).and_return(true) allow(File).to receive(:mtime).and_return(1_407_660_561) - is_expected.to eq(1_407_660_561) + expect(subject).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 a8eacbf20b..4397f766bb 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -11,7 +11,8 @@ before(:each) do allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false) end - it { is_expected.to be nil } + + it { is_expected.to be_nil } end describe 'when apt has updates' do @@ -26,6 +27,7 @@ "Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n" allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output) end + it { is_expected.to eq(2) } end end diff --git a/spec/unit/puppet/provider/apt_key_spec.rb b/spec/unit/puppet/provider/apt_key_spec.rb index b895817014..d683c9bf72 100644 --- a/spec/unit/puppet/provider/apt_key_spec.rb +++ b/spec/unit/puppet/provider/apt_key_spec.rb @@ -15,35 +15,37 @@ end end - context 'self.instances no key' do + context 'with self.instances no key' do before :each do # Unable to remove `master` from below terminology as it relies on outside code allow(described_class).to receive(:apt_key).with( ['adv', '--no-tty', '--list-keys', '--with-colons', '--fingerprint', '--fixed-list-mode'], ).and_return('uid:-::::1284991450::07BEBE04F4AE4A8E885A761325717D8509D9C1DC::Ubuntu Extras Archive Automatic Signing Key ::::::::::0:') end + it 'returns no resources' do expect(described_class.instances.size).to eq(0) end end - context 'self.instances multiple keys' do + context 'with self.instances multiple keys' do before :each do - command_output = <<-OUTPUT -Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.DU0GdRxjmE --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/puppetlabs-pc1-keyring.gpg --no-tty --list-keys --with-colons --fingerprint --fixed-list-mode -tru:t:1:1549900774:0:3:1:5 -pub:-:1024:17:40976EAF437D05B5:1095016255:::-:::scESC: -fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5: -uid:-::::1095016255::B84AE656F4F5A826C273A458512EF8E282754CE1::Ubuntu Archive Automatic Signing Key : -sub:-:2048:16:251BEFF479164387:1095016263::::::e: -pub:-:1024:17:46181433FBB75451:1104433784:::-:::scSC: -fpr:::::::::C5986B4F1257FFA86632CBA746181433FBB75451: -OUTPUT + command_output = <<~OUTPUT + Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.DU0GdRxjmE --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/puppetlabs-pc1-keyring.gpg --no-tty --list-keys --with-colons --fingerprint --fixed-list-mode + tru:t:1:1549900774:0:3:1:5 + pub:-:1024:17:40976EAF437D05B5:1095016255:::-:::scESC: + fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5: + uid:-::::1095016255::B84AE656F4F5A826C273A458512EF8E282754CE1::Ubuntu Archive Automatic Signing Key : + sub:-:2048:16:251BEFF479164387:1095016263::::::e: + pub:-:1024:17:46181433FBB75451:1104433784:::-:::scSC: + fpr:::::::::C5986B4F1257FFA86632CBA746181433FBB75451: + OUTPUT allow(described_class).to receive(:apt_key).with( ['adv', '--no-tty', '--list-keys', '--with-colons', '--fingerprint', '--fixed-list-mode'], ).and_return(command_output) end - it 'returns 2 resources' do + + it 'returns 2 resources' do # rubocop:disable RSpec/MultipleExpectations expect(described_class.instances.size).to eq(2) expect(described_class.instances[0].name).to eq('630239CC130E1A7FD81A27B140976EAF437D05B5') expect(described_class.instances[0].id).to eq('40976EAF437D05B5') @@ -52,11 +54,11 @@ end end - context 'create apt_key resource' do + context 'with create apt_key resource' do it 'apt_key with content set and source nil' do expect(described_class).to receive(:apt_key).with(['adv', '--no-tty', '--keyserver', - :"keyserver.ubuntu.com", + :'keyserver.ubuntu.com', '--recv-keys', 'C105B9DE']) resource = Puppet::Type::Apt_key.new(name: 'source and content nil', @@ -72,7 +74,7 @@ it 'apt_key content and source nil, options set' do expect(described_class).to receive(:apt_key).with(['adv', '--no-tty', '--keyserver', - :"keyserver.ubuntu.com", + :'keyserver.ubuntu.com', '--keyserver-options', 'jimno', '--recv-keys', @@ -88,7 +90,7 @@ expect(provider).to be_exist end - it 'apt_key with content set' do + it 'apt_key with content set' do # rubocop:disable RSpec/MultipleExpectations expect(described_class).to receive(:apt_key).with(array_including('add', kind_of(String))) resource = Puppet::Type::Apt_key.new(name: 'gsd', id: 'C105B9DE', @@ -102,7 +104,7 @@ expect(provider).to be_exist end - it 'apt_key with source set' do + it 'apt_key with source set' do # rubocop:disable RSpec/MultipleExpectations expect(described_class).to receive(:apt_key).with(array_including('add', kind_of(String))) resource = Puppet::Type::Apt_key.new(name: 'gsd', id: 'C105B9DE', @@ -116,7 +118,7 @@ expect(provider).to be_exist end - it 'apt_key with source and weak ssl verify set' do + it 'apt_key with source and weak ssl verify set' do # rubocop:disable RSpec/MultipleExpectations expect(described_class).to receive(:apt_key).with(array_including('add', kind_of(String))) resource = Puppet::Type::Apt_key.new(name: 'gsd', id: 'C105B9DE', @@ -136,18 +138,18 @@ '32bit key id' => 'EF8D349F', '64bit key id' => '7F438280EF8D349F', '160bit key fingerprint' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', - '32bit key id lowercase' => 'EF8D349F'.downcase, - '64bit key id lowercase' => '7F438280EF8D349F'.downcase, + '32bit key id lowercase' => 'EF8D349F'.downcase, + '64bit key id lowercase' => '7F438280EF8D349F'.downcase, '160bit key fingerprint lowercase' => '6F6B15509CF8E59E6E469F327F438280EF8D349F'.downcase, - '32bit key id 0x formatted' => '0xEF8D349F', - '64bit key id 0x formatted' => '0x7F438280EF8D349F', - '160bit key fingerprint 0x formatted' => '0x6F6B15509CF8E59E6E469F327F438280EF8D349F', + '32bit key id 0x formatted' => '0xEF8D349F', + '64bit key id 0x formatted' => '0x7F438280EF8D349F', + '160bit key fingerprint 0x formatted' => '0x6F6B15509CF8E59E6E469F327F438280EF8D349F' } hash_of_keys.each do |key_type, value| it "#{key_type} #{value} is valid" do expect(described_class).to receive(:apt_key).with(array_including('adv', '--no-tty', '--keyserver', - :"keyserver.ubuntu.com", + :'keyserver.ubuntu.com', '--recv-keys')) resource = Puppet::Type::Apt_key.new(name: 'source and content nil', id: value, @@ -170,7 +172,7 @@ end end - context 'key_line_hash function' do + context 'with key_line_hash function' do it 'matches rsa' do expect(described_class.key_line_hash('pub:-:1024:1:40976EAF437D05B5:1095016255:::-:::scESC:', 'fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:')).to include( key_expiry: nil, diff --git a/spec/unit/puppet/type/apt_key_spec.rb b/spec/unit/puppet/type/apt_key_spec.rb index b20a09a101..a146a26e82 100644 --- a/spec/unit/puppet/type/apt_key_spec.rb +++ b/spec/unit/puppet/type/apt_key_spec.rb @@ -24,19 +24,19 @@ end it 'source is not set' do - expect(resource[:source]).to eq nil + expect(resource[:source]).to be_nil end it 'content is not set' do - expect(resource[:content]).to eq nil + expect(resource[:content]).to be_nil end it 'refresh is not set' do - expect(resource[:refresh]).to eq nil + expect(resource[:refresh]).to be_nil end it 'weak_ssl is not set' do - expect(resource[:weak_ssl]).to eq nil + expect(resource[:weak_ssl]).to be_nil end end @@ -164,10 +164,10 @@ it 'raises an error if refresh => true and ensure => absent' do expect { - Puppet::Type.type(:apt_key).new(id: 'EF8D349F', - source: 'http://apt.puppetlabs.com/pubkey.gpg', - ensure: :absent, - refresh: :true) + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + ensure: :absent, + refresh: true) }.to raise_error(%r{ensure => absent and refresh => true are mutually exclusive}) end diff --git a/tasks/init.rb b/tasks/init.rb index 86367d9396..ee141cdb69 100755 --- a/tasks/init.rb +++ b/tasks/init.rb @@ -17,10 +17,11 @@ def apt_get(action) end stdout, stderr, status = Open3.capture3(*cmd) raise Puppet::Error, stderr if status != 0 + { status: stdout.strip } end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) action = params['action'] begin