diff --git a/.fixtures.yml b/.fixtures.yml index 73051cc0..865b6470 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -6,7 +6,7 @@ fixtures: provision: "https://github.com/puppetlabs/provision.git" puppet_agent: repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.12.1 + ref: v4.13.0 package: "https://github.com/puppetlabs/puppetlabs-package.git" deploy_pe: "https://github.com/jarretlavallee/puppet-deploy_pe" sign_cert: "https://github.com/m0dular/sign_cert" diff --git a/.rubocop.yml b/.rubocop.yml index 31e8248f..2367276d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,8 +3,11 @@ require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.5' + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.7' Include: - "**/*.rb" Exclude: @@ -71,6 +74,7 @@ Style/TrailingCommaInArrayLiteral: Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets +inherit_from: ".rubocop_todo.yml" RSpec/MessageSpies: EnforcedStyle: receive Style/Documentation: @@ -79,441 +83,5 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets -Performance/AncestorsInclude: - Enabled: true -Performance/BigDecimalWithNumericArgument: - Enabled: true -Performance/BlockGivenWithExplicitBlock: - Enabled: true -Performance/CaseWhenSplat: - Enabled: true -Performance/ConstantRegexp: - Enabled: true -Performance/MethodObjectAsBlock: - Enabled: true -Performance/RedundantSortBlock: - Enabled: true -Performance/RedundantStringChars: - Enabled: true -Performance/ReverseFirst: - Enabled: true -Performance/SortReverse: - Enabled: true -Performance/Squeeze: - Enabled: true -Performance/StringInclude: - Enabled: true -Performance/Sum: - Enabled: true -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Bundler/InsecureProtocolSource: - Enabled: false -Gemspec/DuplicatedAssignment: - Enabled: false -Gemspec/OrderedDependencies: - Enabled: false -Gemspec/RequiredRubyVersion: - Enabled: false -Gemspec/RubyVersionGlobalsUsage: - Enabled: false -Layout/ArgumentAlignment: - Enabled: false -Layout/BeginEndAlignment: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: false -Layout/EmptyComment: - Enabled: false -Layout/EmptyLineAfterGuardClause: - Enabled: false -Layout/EmptyLinesAroundArguments: - Enabled: false -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/FirstArgumentIndentation: - Enabled: false -Layout/HashAlignment: - Enabled: false -Layout/HeredocIndentation: - Enabled: false -Layout/LeadingEmptyLines: - Enabled: false -Layout/SpaceAroundMethodCallOperator: - Enabled: false -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false -Layout/SpaceInsideReferenceBrackets: - Enabled: false -Lint/BigDecimalNew: - Enabled: false -Lint/BooleanSymbol: - Enabled: false -Lint/ConstantDefinitionInBlock: - Enabled: false -Lint/DeprecatedOpenSSLConstant: - Enabled: false -Lint/DisjunctiveAssignmentInConstructor: - Enabled: false -Lint/DuplicateElsifCondition: - Enabled: false -Lint/DuplicateRequire: - Enabled: false -Lint/DuplicateRescueException: - Enabled: false -Lint/EmptyConditionalBody: - Enabled: false -Lint/EmptyFile: - Enabled: false -Lint/ErbNewArguments: - Enabled: false -Lint/FloatComparison: - Enabled: false -Lint/HashCompareByIdentity: - Enabled: false -Lint/IdentityComparison: - Enabled: false -Lint/InterpolationCheck: - Enabled: false -Lint/MissingCopEnableDirective: - Enabled: false -Lint/MixedRegexpCaptureTypes: - Enabled: false -Lint/NestedPercentLiteral: - Enabled: false -Lint/NonDeterministicRequireOrder: - Enabled: false -Lint/OrderedMagicComments: - Enabled: false -Lint/OutOfRangeRegexpRef: - Enabled: false -Lint/RaiseException: - Enabled: false -Lint/RedundantCopEnableDirective: - Enabled: false -Lint/RedundantRequireStatement: - Enabled: false -Lint/RedundantSafeNavigation: - Enabled: false -Lint/RedundantWithIndex: - Enabled: false -Lint/RedundantWithObject: - Enabled: false -Lint/RegexpAsCondition: - Enabled: false -Lint/ReturnInVoidContext: - Enabled: false -Lint/SafeNavigationConsistency: - Enabled: false -Lint/SafeNavigationWithEmpty: - Enabled: false -Lint/SelfAssignment: - Enabled: false -Lint/SendWithMixinArgument: - Enabled: false -Lint/ShadowedArgument: - Enabled: false -Lint/StructNewOverride: - Enabled: false -Lint/ToJSON: - Enabled: false -Lint/TopLevelReturnWithArgument: - Enabled: false -Lint/TrailingCommaInAttributeDeclaration: - Enabled: false -Lint/UnreachableLoop: - Enabled: false -Lint/UriEscapeUnescape: - Enabled: false -Lint/UriRegexp: - Enabled: false -Lint/UselessMethodDefinition: - Enabled: false -Lint/UselessTimes: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Migration/DepartmentName: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Naming/BlockParameterName: - Enabled: false -Naming/HeredocDelimiterCase: - Enabled: false -Naming/HeredocDelimiterNaming: - Enabled: false -Naming/MemoizedInstanceVariableName: - Enabled: false -Naming/MethodParameterName: - Enabled: false -Naming/RescuedExceptionsVariableName: - Enabled: false -Naming/VariableNumber: - Enabled: false -Performance/BindCall: - Enabled: false -Performance/DeletePrefix: - Enabled: false -Performance/DeleteSuffix: - Enabled: false -Performance/InefficientHashSearch: - Enabled: false -Performance/UnfreezeString: - Enabled: false -Performance/UriDefaultParser: - Enabled: false -RSpec/Be: - Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false -RSpec/Capybara/FeatureMethods: - Enabled: false -RSpec/Capybara/VisibilityMatcher: - Enabled: false -RSpec/ContextMethod: - Enabled: false -RSpec/ContextWording: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/EmptyHook: - Enabled: false -RSpec/EmptyLineAfterExample: - Enabled: false -RSpec/EmptyLineAfterExampleGroup: - Enabled: false -RSpec/EmptyLineAfterHook: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWithoutDescription: - Enabled: false -RSpec/ExpectChange: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/FactoryBot/AttributeDefinedStatically: - Enabled: false -RSpec/FactoryBot/CreateList: - Enabled: false -RSpec/FactoryBot/FactoryClassName: - Enabled: false -RSpec/HooksBeforeExamples: - Enabled: false -RSpec/ImplicitBlockExpectation: - Enabled: false -RSpec/ImplicitSubject: - Enabled: false -RSpec/LeakyConstantDeclaration: - Enabled: false -RSpec/LetBeforeExamples: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false RSpec/MultipleExpectations: - Enabled: false -RSpec/MultipleMemoizedHelpers: - Enabled: false -RSpec/MultipleSubjects: - Enabled: false -RSpec/NestedGroups: - Enabled: false -RSpec/PredicateMatcher: - Enabled: false -RSpec/ReceiveCounts: - Enabled: false -RSpec/ReceiveNever: - Enabled: false -RSpec/RepeatedExampleGroupBody: - Enabled: false -RSpec/RepeatedExampleGroupDescription: - Enabled: false -RSpec/RepeatedIncludeExample: - Enabled: false -RSpec/ReturnFromStub: - Enabled: false -RSpec/SharedExamples: - Enabled: false -RSpec/StubbedMock: - Enabled: false -RSpec/UnspecifiedException: - Enabled: false -RSpec/VariableDefinition: - Enabled: false -RSpec/VoidExpect: - Enabled: false -RSpec/Yield: - Enabled: false -Security/Open: - Enabled: false -Style/AccessModifierDeclarations: - Enabled: false -Style/AccessorGrouping: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/BisectedAttrAccessor: - Enabled: false -Style/CaseLikeIf: - Enabled: false -Style/ClassEqualityComparison: - Enabled: false -Style/ColonMethodDefinition: - Enabled: false -Style/CombinableLoops: - Enabled: false -Style/CommentedKeyword: - Enabled: false -Style/Dir: - Enabled: false -Style/DoubleCopDisableDirective: - Enabled: false -Style/EmptyBlockParameter: - Enabled: false -Style/EmptyLambdaParameter: - Enabled: false -Style/Encoding: - Enabled: false -Style/EvalWithLocation: - Enabled: false -Style/ExpandPathArguments: - Enabled: false -Style/ExplicitBlockArgument: - Enabled: false -Style/ExponentialNotation: - Enabled: false -Style/FloatDivision: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalStdStream: - Enabled: false -Style/HashAsLastArrayItem: - Enabled: false -Style/HashLikeCase: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/KeywordParametersOrder: - Enabled: false -Style/MinMax: - Enabled: false -Style/MixinUsage: - Enabled: false -Style/MultilineWhenThen: - Enabled: false -Style/NegatedUnless: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OptionalBooleanParameter: - Enabled: false -Style/OrAssignment: - Enabled: false -Style/RandomWithOffset: - Enabled: false -Style/RedundantAssignment: - Enabled: false -Style/RedundantCondition: - Enabled: false -Style/RedundantConditional: - Enabled: false -Style/RedundantFetchBlock: - Enabled: false -Style/RedundantFileExtensionInRequire: - Enabled: false -Style/RedundantRegexpCharacterClass: - Enabled: false -Style/RedundantRegexpEscape: - Enabled: false -Style/RedundantSelfAssignment: - Enabled: false -Style/RedundantSort: - Enabled: false -Style/RescueStandardError: - Enabled: false -Style/SingleArgumentDig: - Enabled: false -Style/SlicingWithRange: - Enabled: false -Style/SoleNestedConditional: - Enabled: false -Style/StderrPuts: - Enabled: false -Style/StringConcatenation: - Enabled: false -Style/Strip: - Enabled: false -Style/SymbolProc: - Enabled: false -Style/TrailingBodyOnClass: - Enabled: false -Style/TrailingBodyOnMethodDefinition: - Enabled: false -Style/TrailingBodyOnModule: - Enabled: false -Style/TrailingCommaInHashLiteral: - Enabled: false -Style/TrailingMethodEndStatement: - Enabled: false -Style/UnpackFirst: - Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/DuplicateRegexpCharacterClassElement: - Enabled: false -Lint/EmptyBlock: - Enabled: false -Lint/EmptyClass: - Enabled: false -Lint/NoReturnInBeginEndBlocks: - Enabled: false -Lint/ToEnumArguments: - Enabled: false -Lint/UnexpectedBlockArity: - Enabled: false -Lint/UnmodifiedReduceAccumulator: - Enabled: false -Performance/CollectionLiteralInLoop: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionCompact: - Enabled: false -Style/DocumentDynamicEvalDefinition: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/NilLambda: - Enabled: false -Style/RedundantArgument: - Enabled: false -Style/SwapValues: - Enabled: false + Max: 3 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e69de29b..c21e0a76 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -0,0 +1,40 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-05 13:41:42 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: 9 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - '**/spec/features/**/*' + - '**/spec/requests/**/*' + - '**/spec/routing/**/*' + - '**/spec/system/**/*' + - '**/spec/views/**/*' + - 'spec/acceptance/class_spec.rb' + - 'spec/acceptance/integration_ntp_spec.rb' + - 'spec/acceptance/ntp_install_spec.rb' + - 'spec/acceptance/ntp_parameters_spec.rb' + - 'spec/acceptance/ntp_service_spec.rb' + - 'spec/acceptance/ntp_user_and_daemon_opts_spec.rb' + - 'spec/acceptance/preferred_servers_spec.rb' + - 'spec/acceptance/unsupported_spec.rb' + - 'spec/classes/contains_spec.rb' + +# Offense count: 95 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: + Exclude: + - 'spec/classes/ntp_spec.rb' + +# Offense count: 3 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' + - 'spec/spec_helper_acceptance_local.rb' + - 'spec/spec_helper_local.rb' diff --git a/Gemfile b/Gemfile index 1881afe1..3f6f5c7d 100644 --- a/Gemfile +++ b/Gemfile @@ -14,31 +14,31 @@ def location_for(place_or_version, fake_version = nil) end group :development do - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "voxpupuli-puppet-lint-plugins", '~> 3.1', require: false - gem "facterdb", '~> 1.18', require: false - gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false - gem "puppetlabs_spec_helper", '>= 3.0.0', '< 5.0.0', require: false - gem "rspec-puppet-facts", '~> 2.0', require: false - gem "codecov", '~> 0.2', require: false - gem "dependency_checker", '~> 0.2', require: false - gem "parallel_tests", '~> 3.4', require: false - gem "pry", '~> 0.10', require: false - gem "simplecov-console", '~> 0.5', require: false - gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.6.1', require: false - gem "rubocop-performance", '= 1.9.1', require: false - gem "rubocop-rspec", '= 2.0.1', require: false - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "github_changelog_generator", '= 1.15.2', require: false + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false + gem "puppetlabs_spec_helper", '~> 5.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 0.2', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.48.1', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "github_changelog_generator", '= 1.15.2', require: false end group :system_tests do - gem "puppet_litmus", '<= 0.34.6', require: false, platforms: [:ruby] - gem "serverspec", '~> 2.41', require: false + gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] + gem "serverspec", '~> 2.41', require: false end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index 60be1419..2e3bf644 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/metadata.json b/metadata.json index f2959685..47c23fca 100644 --- a/metadata.json +++ b/metadata.json @@ -76,11 +76,11 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.0.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "description": "NTP Module for Debian, Ubuntu, CentOS, RHEL, OEL, Fedora, FreeBSD, ArchLinux, Amazon Linux and Gentoo.", "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "heads/main-0-g9375381", - "pdk-version": "2.6.1" + "template-ref": "heads/main-0-ge5b0114", + "pdk-version": "2.7.1" } diff --git a/spec/acceptance/integration_ntp_spec.rb b/spec/acceptance/integration_ntp_spec.rb index 402a8cd2..9d609a52 100644 --- a/spec/acceptance/integration_ntp_spec.rb +++ b/spec/acceptance/integration_ntp_spec.rb @@ -5,42 +5,45 @@ require 'pry' describe 'we are able to setup an ntp server, and connect a client to it', :integration do - context 'set up the server' do + context 'when setting up the server' do before(:all) { change_target_host('ntpserver') } after(:all) { reset_target_host } + describe 'set up ntpserver' do - it 'check the date is 2023' do - result = run_shell('date') - expect(result.stdout).to match(%r{2023}) - end pp = <<-MANIFEST class { 'ntp': } MANIFEST - it 'sets up the service' do + + it 'check the date is 2023 and set up the service' do idempotent_apply(pp) + result = run_shell('date') + expect(result.stdout).to match(%r{2023}) end end end - context 'set up the client' do + + context 'when setting up the client' do before(:all) { change_target_host('ntpclient') } after(:all) { reset_target_host } + describe 'go to the future' do - it 'its 2023' do + it 'install ntpdate and check its 2023' do + apply_manifest("package { 'ntpdate': ensure => present }") result = run_shell('date') expect(result.stdout).to match(%r{2023}) end - it 'install ntpdate' do - apply_manifest("package { 'ntpdate': ensure => present }") - end + it 'disable ntp auto-sync' do result = run_shell('timedatectl set-ntp false') expect(result.exit_code).to eq(0) end + it 'go forward to 2024' do result = run_shell('date --set="$(date --date="next year")"') expect(result.stdout).to match(%r{2024}) expect(result.exit_code).to eq(0) end + it 'changed 2024' do result = run_shell('date') expect(result.stdout).to match(%r{2024}) diff --git a/spec/acceptance/ntp_install_spec.rb b/spec/acceptance/ntp_install_spec.rb index e749562d..838dd32b 100644 --- a/spec/acceptance/ntp_install_spec.rb +++ b/spec/acceptance/ntp_install_spec.rb @@ -18,9 +18,7 @@ describe 'ntp::install class', unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do it 'installs the package' do - apply_manifest(%( - class { 'ntp': } - ), catch_failures: true) + apply_manifest(%( class { 'ntp': } ), catch_failures: true) Array(packagename).each do |package| expect(package(package)).to be_installed end diff --git a/spec/acceptance/ntp_user_and_daemon_opts_spec.rb b/spec/acceptance/ntp_user_and_daemon_opts_spec.rb index 6b4f6268..8a65e686 100644 --- a/spec/acceptance/ntp_user_and_daemon_opts_spec.rb +++ b/spec/acceptance/ntp_user_and_daemon_opts_spec.rb @@ -32,13 +32,14 @@ let(:pp) { "class { 'ntp': service_enable => true, service_ensure => running, service_manage => true, service_name => '#{servicename}', user => 'ntp', daemon_extra_opts => '-g -i /var/lib/ntp' }" } context 'when run' do - it 'is successful' do + it 'is successful' do # rubocop:disable RSpec/NoExpectationExample apply_manifest(pp, catch_failures: true) end describe file(config.to_s) do - its(:content) { is_expected.to match(%r{(OPTIONS|NTPD_OPTS)='-g -i \/var\/lib\/ntp'}) } + its(:content) { is_expected.to match(%r{(OPTIONS|NTPD_OPTS)='-g -i /var/lib/ntp'}) } end + if os[:family] == 'redhat' && !os[:release].start_with?('6') describe file('/etc/systemd/system/multi-user.target.wants/ntpd.service') do its(:content) { is_expected.to match(%r{ntpd -u ntp:ntp}) } diff --git a/spec/acceptance/preferred_servers_spec.rb b/spec/acceptance/preferred_servers_spec.rb index d398b80b..b4854bbe 100644 --- a/spec/acceptance/preferred_servers_spec.rb +++ b/spec/acceptance/preferred_servers_spec.rb @@ -17,13 +17,10 @@ class { '::ntp': MANIFEST it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) do |r| - expect(r.stderr).not_to match(%r{error}i) - end + idempotent_apply(pp) expect(file(config.to_s)).to be_file - expect(file(config.to_s).content).to match 'server a' - expect(file(config.to_s).content).to match 'server b' - expect(file(config.to_s).content).to match %r{server c (iburst\s|)prefer} - expect(file(config.to_s).content).to match %r{server d (iburst\s|)prefer} + ['server a', 'server b', %r{server c (iburst\s|)prefer}, %r{server d (iburst\s|)prefer}].each do |check| + expect(file(config.to_s).content).to match(check) + end end end diff --git a/spec/classes/contains_spec.rb b/spec/classes/contains_spec.rb index ece3d67e..1e3c0bbe 100644 --- a/spec/classes/contains_spec.rb +++ b/spec/classes/contains_spec.rb @@ -13,12 +13,13 @@ end on_supported_os.each do |os, f| - context "on #{os}" do + context "when on #{os}" do let(:facts) do f.merge(super()) end it { is_expected.to compile.with_all_deps } + describe 'Testing the dependancies between the classes' do it { is_expected.to contain_class('ntp::install') } it { is_expected.to contain_class('ntp::config') } diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 1b4fdba2..6d0906b9 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -14,7 +14,7 @@ end end - context "on #{os}" do + context "when on #{os}" do let(:facts) do f.merge(super()) end @@ -36,9 +36,7 @@ it { is_expected.to contain_file('/etc/ntp/step-tickers').with_mode('0644') } end - if f[:os]['family'] == 'Suse' && f[:os]['release']['major'] == '12' - it { is_expected.to contain_file('/var/run/ntp/servers-netconfig').with_ensure_absent } - end + it { is_expected.to contain_file('/var/run/ntp/servers-netconfig').with_ensure_absent } if f[:os]['family'] == 'Suse' && f[:os]['release']['major'] == '12' describe 'allows template to be overridden with erb template' do let(:params) { { config_template: 'my_ntp/ntp.conf.erb' } } @@ -56,23 +54,24 @@ context 'when set to true' do let(:params) do { - broadcastclient: true, + broadcastclient: true } end it 'contains broadcastclient setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^broadcastclient\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^broadcastclient\n}) end end + context 'when set to false' do let(:params) do { - broadcastclient: false, + broadcastclient: false } end it 'does not contain broadcastclient setting' do - is_expected.not_to contain_file(conf_path).with('content' => %r{^broadcastclient\n}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^broadcastclient\n}) end end end @@ -81,88 +80,89 @@ context 'when set to true' do let(:params) do { - burst: true, + burst: true } end it do - is_expected.to contain_file(conf_path).with('content' => %r{ burst\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{ burst\n}) end end context 'when set to false' do let(:params) do { - burst: false, + burst: false } end it do - is_expected.not_to contain_file(conf_path).with('content' => %r{ burst\n}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{ burst\n}) end end end - context 'config_dir' do + context 'with config_dir' do context 'when set to custom dir' do let(:params) do { keys_enable: true, config_dir: '/tmp/foo', - keys_file: '/tmp/foo/ntp.keys', + keys_file: '/tmp/foo/ntp.keys' } end it 'contains custom config directory' do - is_expected.to contain_file('/tmp/foo').with( + expect(subject).to contain_file('/tmp/foo').with( 'ensure' => 'directory', 'owner' => '0', 'group' => '0', 'mode' => '0775', 'recurse' => 'false', ) end end end - context 'config_file_mode' do + context 'with config_file_mode' do context 'when set to custom mode' do let(:params) do { - config_file_mode: '0777', + config_file_mode: '0777' } end it 'contains file mode of 0777' do - is_expected.to contain_file(conf_path).with_mode('0777') + expect(subject).to contain_file(conf_path).with_mode('0777') end end end - context 'default pool servers' do # rubocop:disable RSpec/EmptyExampleGroup + context 'with default pool servers' do case f[:os]['family'] when 'RedHat' it 'uses the centos ntp servers' do - is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.centos.pool.ntp.org}) + expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.centos.pool.ntp.org}) end + it do - is_expected.to contain_file('/etc/ntp/step-tickers').with('content' => %r{\d.centos.pool.ntp.org}) + expect(subject).to contain_file('/etc/ntp/step-tickers').with('content' => %r{\d.centos.pool.ntp.org}) end when 'Debian' it 'uses the debian ntp servers' do - is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.debian.pool.ntp.org iburst\n}) + expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.debian.pool.ntp.org iburst\n}) end when 'Suse' it 'uses the opensuse ntp servers' do - is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.opensuse.pool.ntp.org}) + expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.opensuse.pool.ntp.org}) end when 'FreeBSD' it 'uses the freebsd ntp servers' do - is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.freebsd.pool.ntp.org iburst maxpoll 9}) + expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.freebsd.pool.ntp.org iburst maxpoll 9}) end when 'Solaris' it 'uses the generic NTP pool servers' do - is_expected.to contain_file('/etc/inet/ntp.conf').with('content' => %r{server \d.pool.ntp.org}) + expect(subject).to contain_file('/etc/inet/ntp.conf').with('content' => %r{server \d.pool.ntp.org}) end when 'AIX' it 'uses the generic NTP pool servers on AIX' do - is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.pool.ntp.org}) + expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.pool.ntp.org}) end else it { @@ -177,23 +177,24 @@ context 'when set to true' do let(:params) do { - disable_auth: true, + disable_auth: true } end it 'contains disable auth setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^disable auth\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^disable auth\n}) end end + context 'when set to false' do let(:params) do { - disable_auth: false, + disable_auth: false } end it 'does not contain disable auth setting' do - is_expected.not_to contain_file(conf_path).with('content' => %r{^disable auth\n}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^disable auth\n}) end end end @@ -202,32 +203,36 @@ context 'when set to true' do let(:params) do { - disable_dhclient: true, + disable_dhclient: true } end it 'contains disable ntp-servers setting' do - is_expected.to contain_augeas('disable ntp-servers in dhclient.conf') + expect(subject).to contain_augeas('disable ntp-servers in dhclient.conf') end + it 'contains dhcp file' do - is_expected.to contain_file('/var/lib/ntp/ntp.conf.dhcp').with_ensure('absent') + expect(subject).to contain_file('/var/lib/ntp/ntp.conf.dhcp').with_ensure('absent') end + it 'contains ntp.sh file' do - is_expected.to contain_file('/etc/dhcp/dhclient.d/ntp.sh').with_ensure('absent') + expect(subject).to contain_file('/etc/dhcp/dhclient.d/ntp.sh').with_ensure('absent') end end + context 'when set to false' do let(:params) do { - disable_dhclient: false, + disable_dhclient: false } end it 'does not contain disable ntp-servers setting' do - is_expected.not_to contain_augeas('disable ntp-servers in dhclient.conf') + expect(subject).not_to contain_augeas('disable ntp-servers in dhclient.conf') end + it 'does not contain dhcp file' do - is_expected.not_to contain_file('/var/lib/ntp/ntp.conf.dhcp').with_ensure('absent') + expect(subject).not_to contain_file('/var/lib/ntp/ntp.conf.dhcp').with_ensure('absent') end end end @@ -236,23 +241,24 @@ context 'when set to true' do let(:params) do { - disable_kernel: true, + disable_kernel: true } end it 'contains disable kernel setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^disable kernel\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^disable kernel\n}) end end + context 'when set to false' do let(:params) do { - disable_kernel: false, + disable_kernel: false } end it 'does not contain disable kernel setting' do - is_expected.not_to contain_file(conf_path).with('content' => %r{^disable kernel\n}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^disable kernel\n}) end end end @@ -260,34 +266,35 @@ describe 'disable_monitor' do context 'when default' do let(:params) do - { - } + {} end it 'contains disable monitor setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^disable monitor\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^disable monitor\n}) end end + context 'when set to true' do let(:params) do { - disable_monitor: true, + disable_monitor: true } end it 'contains disable monitor setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^disable monitor\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^disable monitor\n}) end end + context 'when set to false' do let(:params) do { - disable_monitor: false, + disable_monitor: false } end it 'does not contain disable monitor setting' do - is_expected.not_to contain_file(conf_path).with('content' => %r{^disable monitor\n}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^disable monitor\n}) end end end @@ -295,19 +302,19 @@ describe 'driftfile' do context 'when not set' do it 'contains default driftfile' do - is_expected.to contain_file(conf_path).with('content' => %r{^driftfile}) + expect(subject).to contain_file(conf_path).with('content' => %r{^driftfile}) end end context 'when set' do let(:params) do { - driftfile: '/tmp/driftfile', + driftfile: '/tmp/driftfile' } end it 'contains driftfile value' do - is_expected.to contain_file(conf_path).with('content' => %r{^driftfile /tmp/driftfile\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^driftfile /tmp/driftfile\n}) end end end @@ -315,34 +322,35 @@ describe 'enable_mode7' do context 'when default' do let(:params) do - { - } + {} end it 'does not contain enable mode7 setting' do - is_expected.not_to contain_file(conf_path).with('content' => %r{^enable mode7\n}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^enable mode7\n}) end end + context 'when set to true' do let(:params) do { - enable_mode7: true, + enable_mode7: true } end it 'contains enable mode7 setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^enable mode7\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^enable mode7\n}) end end + context 'when set to false' do let(:params) do { - enable_mode7: false, + enable_mode7: false } end it 'does not contain enable mode7 setting' do - is_expected.not_to contain_file(conf_path).with('content' => %r{^enable mode7\n}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^enable mode7\n}) end end end @@ -352,23 +360,24 @@ let(:params) do { servers: ['a', 'b', 'c', 'd'], - interfaces: ['127.0.0.1', 'a.b.c.d'], + interfaces: ['127.0.0.1', 'a.b.c.d'] } end it { - is_expected.to contain_file(conf_path).with('content' => %r{interface ignore wildcard\ninterface listen 127.0.0.1\ninterface listen a.b.c.d}) + expect(subject).to contain_file(conf_path).with('content' => %r{interface ignore wildcard\ninterface listen 127.0.0.1\ninterface listen a.b.c.d}) } end + context 'when not set' do let(:params) do { - servers: ['a', 'b', 'c', 'd'], + servers: ['a', 'b', 'c', 'd'] } end it { - is_expected.not_to contain_file(conf_path).with('content' => %r{interface ignore wildcard}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{interface ignore wildcard}) } end end @@ -378,24 +387,25 @@ let(:params) do { interfaces: ['a.b.c.d'], - interfaces_ignore: ['wildcard', 'ipv6'], + interfaces_ignore: ['wildcard', 'ipv6'] } end it { - is_expected.to contain_file(conf_path).with('content' => %r{interface ignore wildcard\ninterface ignore ipv6\ninterface listen a.b.c.d}) + expect(subject).to contain_file(conf_path).with('content' => %r{interface ignore wildcard\ninterface ignore ipv6\ninterface listen a.b.c.d}) } end + context 'when not set' do let(:params) do { interfaces: ['127.0.0.1'], - servers: ['a', 'b', 'c', 'd'], + servers: ['a', 'b', 'c', 'd'] } end it { - is_expected.to contain_file(conf_path).with('content' => %r{interface ignore wildcard\ninterface listen 127.0.0.1}) + expect(subject).to contain_file(conf_path).with('content' => %r{interface ignore wildcard\ninterface listen 127.0.0.1}) } end end @@ -408,7 +418,7 @@ keys_trusted: [1, 2, 3], keys_controlkey: 2, keys_requestkey: 3, - keys: ['1 M AAAABBBB'], + keys: ['1 M AAAABBBB'] } end @@ -423,16 +433,19 @@ end it { - is_expected.to contain_file(conf_path).with('content' => %r{trustedkey 1 2 3}) + expect(subject).to contain_file(conf_path).with('content' => %r{trustedkey 1 2 3}) } + it { - is_expected.to contain_file(conf_path).with('content' => %r{controlkey 2}) + expect(subject).to contain_file(conf_path).with('content' => %r{controlkey 2}) } + it { - is_expected.to contain_file(conf_path).with('content' => %r{requestkey 3}) + expect(subject).to contain_file(conf_path).with('content' => %r{requestkey 3}) } + it { - is_expected.to contain_file(keys_file).with('content' => %r{1 M AAAABBBB}) + expect(subject).to contain_file(keys_file).with('content' => %r{1 M AAAABBBB}) } end end @@ -443,18 +456,20 @@ keys_enable: false, keys_trusted: [1, 2, 3], keys_controlkey: 2, - keys_requestkey: 3, + keys_requestkey: 3 } end it { - is_expected.not_to contain_file(conf_path).with('content' => %r{trustedkey 1 2 3}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{trustedkey 1 2 3}) } + it { - is_expected.not_to contain_file(conf_path).with('content' => %r{controlkey 2}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{controlkey 2}) } + it { - is_expected.not_to contain_file(conf_path).with('content' => %r{requestkey 3}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{requestkey 3}) } end @@ -464,24 +479,25 @@ { servers: ['a', 'b', 'c', 'd'], noselect_servers: ['a', 'b'], - iburst_enable: false, + iburst_enable: false } end it { - is_expected.to contain_file(conf_path).with('content' => %r{server a (maxpoll 9 )?noselect\nserver b (maxpoll 9 )?noselect\nserver c( maxpoll 9)?\nserver d( maxpoll 9)?}) + expect(subject).to contain_file(conf_path).with('content' => %r{server a (maxpoll 9 )?noselect\nserver b (maxpoll 9 )?noselect\nserver c( maxpoll 9)?\nserver d( maxpoll 9)?}) } end + context 'when not set' do let(:params) do { servers: ['a', 'b', 'c', 'd'], - noselect_servers: [], + noselect_servers: [] } end it { - is_expected.not_to contain_file(conf_path).with('content' => %r{server a noselect}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{server a noselect}) } end end @@ -492,24 +508,25 @@ { servers: ['a', 'b', 'c', 'd'], preferred_servers: ['a', 'b'], - iburst_enable: false, + iburst_enable: false } end it { - is_expected.to contain_file(conf_path).with('content' => %r{server a prefer( maxpoll 9)?\nserver b prefer( maxpoll 9)?\nserver c( maxpoll 9)?\nserver d( maxpoll 9)?}) + expect(subject).to contain_file(conf_path).with('content' => %r{server a prefer( maxpoll 9)?\nserver b prefer( maxpoll 9)?\nserver c( maxpoll 9)?\nserver d( maxpoll 9)?}) } end + context 'when not set' do let(:params) do { servers: ['a', 'b', 'c', 'd'], - preferred_servers: [], + preferred_servers: [] } end it { - is_expected.not_to contain_file(conf_path).with('content' => %r{server a prefer}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{server a prefer}) } end end @@ -517,19 +534,19 @@ describe 'restrict' do context 'when not set' do it 'does not contain restrict value' do - is_expected.to contain_file(conf_path).without_content(%r{^restrict test restrict}) + expect(subject).to contain_file(conf_path).without_content(%r{^restrict test restrict}) end end context 'when set' do let(:params) do { - restrict: ['test restrict'], + restrict: ['test restrict'] } end it 'contains restrict value' do - is_expected.to contain_file(conf_path).with_content(%r{^restrict test restrict}) + expect(subject).to contain_file(conf_path).with_content(%r{^restrict test restrict}) end end end @@ -538,11 +555,11 @@ context 'when absent' do if f[:kernel] == 'AIX' it 'on AIX does contain "slewalways no"' do - is_expected.to contain_file(conf_path).with_content(%r{^slewalways no}) + expect(subject).to contain_file(conf_path).with_content(%r{^slewalways no}) end else it 'on non-AIX does not contain a slewalways' do - is_expected.to contain_file(conf_path).without_content(%r{^slewalways}) + expect(subject).to contain_file(conf_path).without_content(%r{^slewalways}) end end end @@ -550,24 +567,24 @@ context 'when "no"' do let(:params) do { - slewalways: 'no', + slewalways: 'no' } end it 'does contain "slewalways no"' do - is_expected.to contain_file(conf_path).with_content(%r{^slewalways no}) + expect(subject).to contain_file(conf_path).with_content(%r{^slewalways no}) end end context 'when "yes"' do let(:params) do { - slewalways: 'yes', + slewalways: 'yes' } end it 'does contain "slewalways yes"' do - is_expected.to contain_file(conf_path).with_content(%r{^slewalways yes}) + expect(subject).to contain_file(conf_path).with_content(%r{^slewalways yes}) end end end @@ -575,7 +592,7 @@ describe 'statistics' do context 'when not set' do it 'does not contain statistics' do - is_expected.to contain_file(conf_path).without_content(%r{^filegen loopstats file loopstats type day enable}) + expect(subject).to contain_file(conf_path).without_content(%r{^filegen loopstats file loopstats type day enable}) end end @@ -583,13 +600,13 @@ let(:params) do { statistics: ['loopstats'], - disable_monitor: false, + disable_monitor: false } end it 'contains statistics value' do - is_expected.to contain_file(conf_path).with_content(%r{^filegen loopstats file loopstats type day enable}) - is_expected.to contain_file(conf_path).with_content(%r{^statsdir /var/log/ntpstats}) + expect(subject).to contain_file(conf_path).with_content(%r{^filegen loopstats file loopstats type day enable}) + expect(subject).to contain_file(conf_path).with_content(%r{^statsdir /var/log/ntpstats}) end end end @@ -597,19 +614,19 @@ describe 'udlc' do context 'when not set' do it 'does not contain udlc' do - is_expected.to contain_file(conf_path).without_content(%r{127.127.1.0}) + expect(subject).to contain_file(conf_path).without_content(%r{127.127.1.0}) end end context 'when set' do let(:params) do { - udlc: true, + udlc: true } end it 'contains udlc value' do - is_expected.to contain_file(conf_path).with_content(%r{127.127.1.0}) + expect(subject).to contain_file(conf_path).with_content(%r{127.127.1.0}) end end end @@ -617,7 +634,7 @@ describe 'udlc_stratum' do context 'when not set' do it 'does not contain udlc_stratum' do - is_expected.to contain_file(conf_path).without_content(%r{stratum 10}) + expect(subject).to contain_file(conf_path).without_content(%r{stratum 10}) end end @@ -625,12 +642,12 @@ let(:params) do { udlc: true, - udlc_stratum: 10, + udlc_stratum: 10 } end it 'contains udlc_stratum value' do - is_expected.to contain_file(conf_path).with_content(%r{stratum 10}) + expect(subject).to contain_file(conf_path).with_content(%r{stratum 10}) end end end @@ -640,7 +657,7 @@ let(:params) { { package_ensure: 'present', package_name: ['ntp'], package_manage: true } } it { - is_expected.to contain_package('ntp').with( + expect(subject).to contain_package('ntp').with( ensure: 'present', ) } @@ -670,18 +687,15 @@ service_manage: true, service_enable: true, service_ensure: 'running', - service_name: 'ntp', + service_name: 'ntp' } end describe 'with defaults' do it { - is_expected.to contain_service('ntp').with( - enable: true, - ensure: 'running', - name: 'ntp', - hasstatus: true, - hasrestart: true, + expect(subject).to contain_service('ntp').with( + enable: true, ensure: 'running', name: 'ntp', + hasstatus: true, hasrestart: true ) } end @@ -691,24 +705,24 @@ let(:params) do { servers: ['a', 'b', 'c', 'd'], - authprov: '/opt/novell/xad/lib64/libw32time.so 131072:4294967295 global', + authprov: '/opt/novell/xad/lib64/libw32time.so 131072:4294967295 global' } end it 'contains authprov setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^authprov /opt/novell/xad/lib64/libw32time.so 131072:4294967295 global\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^authprov /opt/novell/xad/lib64/libw32time.so 131072:4294967295 global\n}) end end context 'when set to false' do let(:params) do { - servers: ['a', 'b', 'c', 'd'], + servers: ['a', 'b', 'c', 'd'] } end it 'does not contain a authprov line' do - is_expected.not_to contain_file(conf_path).with('content' => %r{authprov }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{authprov }) end end end @@ -719,7 +733,7 @@ end it 'disallows large clock skews' do - is_expected.not_to contain_file(conf_path).with('content' => %r{tinker panic 0}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{tinker panic 0}) end end @@ -729,11 +743,11 @@ end it 'does not use local clock as a time source' do - is_expected.not_to contain_file(conf_path).with('content' => %r{server.*127.127.1.0.*fudge.*127.127.1.0 stratum 10}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{server.*127.127.1.0.*fudge.*127.127.1.0 stratum 10}) end it 'allows large clock skews' do - is_expected.to contain_file(conf_path).with('content' => %r{tinker panic 0}) + expect(subject).to contain_file(conf_path).with('content' => %r{tinker panic 0}) end end @@ -741,24 +755,24 @@ context 'when set to true' do let(:params) do { - iburst_enable: true, + iburst_enable: true } end it do - is_expected.to contain_file(conf_path).with('content' => %r{iburst}) + expect(subject).to contain_file(conf_path).with('content' => %r{iburst}) end end context 'when set to false' do let(:params) do { - iburst_enable: false, + iburst_enable: false } end it do - is_expected.not_to contain_file(conf_path).with('content' => %r{iburst\n}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{iburst\n}) end end end @@ -768,24 +782,24 @@ let(:params) do { servers: ['a', 'b', 'c', 'd'], - leapfile: '/etc/leap-seconds.3629404800', + leapfile: '/etc/leap-seconds.3629404800' } end it 'contains leapfile setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^leapfile \/etc\/leap-seconds\.3629404800\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^leapfile /etc/leap-seconds\.3629404800\n}) end end context 'when set to false' do let(:params) do { - servers: ['a', 'b', 'c', 'd'], + servers: ['a', 'b', 'c', 'd'] } end it 'does not contain a leapfile line' do - is_expected.not_to contain_file(conf_path).with('content' => %r{leapfile }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{leapfile }) end end end @@ -795,24 +809,24 @@ let(:params) do { servers: ['a', 'b', 'c', 'd'], - logfile: '/var/log/foobar.log', + logfile: '/var/log/foobar.log' } end it 'contains logfile setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^logfile \/var\/log\/foobar\.log\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^logfile /var/log/foobar\.log\n}) end end context 'when set to false' do let(:params) do { - servers: ['a', 'b', 'c', 'd'], + servers: ['a', 'b', 'c', 'd'] } end it 'does not contain a logfile line' do - is_expected.not_to contain_file(conf_path).with('content' => %r{logfile }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{logfile }) end end end @@ -822,24 +836,24 @@ let(:params) do { servers: ['a', 'b', 'c', 'd'], - logconfig: '=syncall +peerinfo', + logconfig: '=syncall +peerinfo' } end it 'contains logconfig setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^logconfig =syncall \+peerinfo\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^logconfig =syncall \+peerinfo\n}) end end context 'when set to false' do let(:params) do { - servers: ['a', 'b', 'c', 'd'], + servers: ['a', 'b', 'c', 'd'] } end it 'does not contain a logconfig line' do - is_expected.not_to contain_file(conf_path).with('content' => %r{logconfig }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{logconfig }) end end end @@ -848,24 +862,24 @@ context 'when minpoll changed from default' do let(:params) do { - minpoll: 6, + minpoll: 6 } end it do - is_expected.to contain_file(conf_path).with('content' => %r{minpoll 6}) + expect(subject).to contain_file(conf_path).with('content' => %r{minpoll 6}) end end context 'when maxpoll changed from default' do let(:params) do { - maxpoll: 12, + maxpoll: 12 } end it do - is_expected.to contain_file(conf_path).with('content' => %r{maxpoll 12\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{maxpoll 12\n}) end end @@ -873,12 +887,12 @@ let(:params) do { minpoll: 6, - maxpoll: 12, + maxpoll: 12 } end it do - is_expected.to contain_file(conf_path).with('content' => %r{minpoll 6 maxpoll 12\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{minpoll 6 maxpoll 12\n}) end end end @@ -888,24 +902,24 @@ let(:params) do { servers: ['a', 'b', 'c', 'd'], - ntpsigndsocket: '/usr/local/samba/var/lib/ntp_signd', + ntpsigndsocket: '/usr/local/samba/var/lib/ntp_signd' } end it 'contains ntpsigndsocket setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^ntpsigndsocket /usr/local/samba/var/lib/ntp_signd\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^ntpsigndsocket /usr/local/samba/var/lib/ntp_signd\n}) end end context 'when set to false' do let(:params) do { - servers: ['a', 'b', 'c', 'd'], + servers: ['a', 'b', 'c', 'd'] } end it 'does not contain a ntpsigndsocket line' do - is_expected.not_to contain_file(conf_path).with('content' => %r{ntpsigndsocket }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{ntpsigndsocket }) end end end @@ -914,27 +928,28 @@ context 'when empty' do let(:params) do { - peers: [], + peers: [] } end it 'does not contain a peer line' do - is_expected.to contain_file(conf_path).without_content(%r{^peer}) + expect(subject).to contain_file(conf_path).without_content(%r{^peer}) end end context 'when set' do let(:params) do { - peers: ['foo', 'bar'], + peers: ['foo', 'bar'] } end it 'contains the peer lines - expectation one' do - is_expected.to contain_file(conf_path).with_content(%r{peer foo}) + expect(subject).to contain_file(conf_path).with_content(%r{peer foo}) end + it 'contains the peer lines - expectation two' do - is_expected.to contain_file(conf_path).with_content(%r{peer bar}) + expect(subject).to contain_file(conf_path).with_content(%r{peer bar}) end end end @@ -943,27 +958,28 @@ context 'when empty' do let(:params) do { - pool: [], + pool: [] } end it 'does not contain a pool line' do - is_expected.to contain_file(conf_path).without_content(%r{^pool}) + expect(subject).to contain_file(conf_path).without_content(%r{^pool}) end end context 'when set' do let(:params) do { - pool: ['foo', 'bar'], + pool: ['foo', 'bar'] } end it 'contains the pool lines - expectation one' do - is_expected.to contain_file(conf_path).with_content(%r{pool foo}) + expect(subject).to contain_file(conf_path).with_content(%r{pool foo}) end + it 'contains the pool lines - expectation two' do - is_expected.to contain_file(conf_path).with_content(%r{pool bar}) + expect(subject).to contain_file(conf_path).with_content(%r{pool bar}) end end end @@ -998,14 +1014,14 @@ service_manage: false, service_enable: true, service_ensure: 'running', - service_name: 'ntpd', + service_name: 'ntpd' } end it 'when set to false' do - is_expected.not_to contain_service('ntp').with('enable' => true, - 'ensure' => 'running', - 'name' => 'ntpd') + expect(subject).not_to contain_service('ntp').with('enable' => true, + 'ensure' => 'running', + 'name' => 'ntpd') end end @@ -1014,12 +1030,12 @@ context 'when panic or stepout not overriden' do let(:params) do { - tinker: false, + tinker: false } end it do - is_expected.not_to contain_file(conf_path).with('content' => %r{^tinker }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^tinker }) end end @@ -1027,12 +1043,12 @@ let(:params) do { tinker: false, - panic: 257, + panic: 257 } end it do - is_expected.not_to contain_file(conf_path).with('content' => %r{^tinker }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^tinker }) end end @@ -1040,12 +1056,12 @@ let(:params) do { tinker: false, - stepout: 5, + stepout: 5 } end it do - is_expected.not_to contain_file(conf_path).with('content' => %r{^tinker }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^tinker }) end end @@ -1054,12 +1070,12 @@ { tinker: false, panic: 257, - stepout: 5, + stepout: 5 } end it do - is_expected.not_to contain_file(conf_path).with('content' => %r{^tinker }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^tinker }) end end end @@ -1068,12 +1084,12 @@ context 'when only tinker set to true' do let(:params) do { - tinker: true, + tinker: true } end it do - is_expected.not_to contain_file(conf_path).with('content' => %r{^tinker }) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^tinker }) end end @@ -1081,12 +1097,12 @@ let(:params) do { tinker: true, - panic: 257, + panic: 257 } end it do - is_expected.to contain_file(conf_path).with('content' => %r{^tinker panic 257\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^tinker panic 257\n}) end end @@ -1094,12 +1110,12 @@ let(:params) do { tinker: true, - stepout: 5, + stepout: 5 } end it do - is_expected.to contain_file(conf_path).with('content' => %r{^tinker stepout 5\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^tinker stepout 5\n}) end end @@ -1108,12 +1124,12 @@ { tinker: true, panic: 257, - stepout: 5, + stepout: 5 } end it do - is_expected.to contain_file(conf_path).with('content' => %r{^tinker panic 257 stepout 5\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{^tinker panic 257 stepout 5\n}) end end end @@ -1123,24 +1139,24 @@ context 'when set to true' do let(:params) do { - tos: true, + tos: true } end it 'contains tos setting' do - is_expected.to contain_file(conf_path).with('content' => %r{^tos}) + expect(subject).to contain_file(conf_path).with('content' => %r{^tos}) end end context 'when set to false' do let(:params) do { - tos: false, + tos: false } end it 'does not contain tos setting' do - is_expected.not_to contain_file(conf_path).with('content' => %r{^tos}) + expect(subject).not_to contain_file(conf_path).with('content' => %r{^tos}) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07db7342..c6e55257 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,7 @@ default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ @@ -26,7 +26,7 @@ begin default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 19f89238..c0be02ff 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -9,13 +9,11 @@ def inventory_hash end def target_roles(roles) - # rubocop:disable Style/MultilineBlockChain inventory_hash['groups'].map { |group| - group['targets'].map { |node| + group['targets'].filter_map do |node| { name: node['uri'], role: node['vars']['role'] } if roles.include? node['vars']['role'] - }.reject { |val| val.nil? } + end }.flatten - # rubocop:enable Style/MultilineBlockChain end RSpec.configure do |config| @@ -27,7 +25,7 @@ def target_roles(roles) end def change_target_host(role) - @orig_target_host = ENV['TARGET_HOST'] + @orig_target_host = ENV.fetch('TARGET_HOST', nil) ENV['TARGET_HOST'] = target_roles(role)[0][:name] end