diff --git a/.gitignore b/.gitignore index f7b390e..6344515 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,26 @@ -pkg/ -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.librarian/ -Puppetfile.lock +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns *.iml -.*.sw? -.yardoc/ -Guardfile +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store *.log +convert_report.txt diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..650022e --- /dev/null +++ b/.pdkignore @@ -0,0 +1,24 @@ +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store diff --git a/.rspec b/.rspec index 8c18f1a..16f9cdb 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ ---format documentation --color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..54d1597 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,118 @@ +--- +require: rubocop-rspec +AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.1' + Include: + - "./**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Metrics/LineLength: + Description: People have wide screens, use them. + Max: 200 +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/FormatString: + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 + EnforcedStyle: percent_r +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +Style/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true +Layout/EndOfLine: + Enabled: false +Layout/IndentHeredoc: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/ModuleLength: + Enabled: false +Metrics/ParameterLists: + Enabled: false +Metrics/PerceivedComplexity: + Enabled: false +RSpec/DescribeClass: + Enabled: false +RSpec/ExampleLength: + Enabled: false +RSpec/MessageExpectation: + Enabled: false +RSpec/MultipleExpectations: + Enabled: false +RSpec/NestedGroups: + Enabled: false +Style/AsciiComments: + Enabled: false +Style/IfUnlessModifier: + Enabled: false +Style/SymbolProc: + Enabled: false diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..5040ef4 --- /dev/null +++ b/.sync.yml @@ -0,0 +1,14 @@ +--- +.gitignore: + paths: + - '*.log' + - 'convert_report.txt' + +.gitlab-ci.yml: + delete: true + +appveyor.yml: + delete: true + +.yardopts: + delete: true diff --git a/.travis.yml b/.travis.yml index 6e784d3..4ea920d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,38 +1,44 @@ --- sudo: false -language: ruby dist: trusty +language: ruby cache: bundler before_install: - bundle -v - - rm Gemfile.lock || true + - rm -f Gemfile.lock - gem update --system - - gem update bundler - gem --version - bundle -v script: - 'bundle exec rake $CHECK' +bundler_args: --without system_tests +rvm: + - 2.4.4 +env: + global: + - BEAKER_PUPPET_COLLECTION=puppet5 PUPPET_GEM_VERSION="~> 5.0" matrix: fast_finish: true include: - - rvm: 2.4.1 - bundler_args: --without system_tests development - env: PUPPET_VERSION="~> 4.6.0" CHECK=test STRICT_VARIABLES=yes - - rvm: 2.4.1 - bundler_args: --without system_tests development - env: PUPPET_VERSION="~> 4.7.0" CHECK=test STRICT_VARIABLES=yes - - rvm: 2.4.1 - bundler_args: --without system_tests development - env: PUPPET_VERSION="~> 4.8.0" CHECK=test STRICT_VARIABLES=yes - - rvm: 2.4.1 - bundler_args: --without system_tests development - env: PUPPET_VERSION="~> 4.9.0" CHECK=test STRICT_VARIABLES=yes - - rvm: 2.4.1 - bundler_args: --without system_tests development - env: PUPPET_VERSION="~> 4.10.0" CHECK=test STRICT_VARIABLES=yes - - rvm: 2.4.1 - bundler_args: --without system_tests development - env: PUPPET_VERSION="~> 5.0.0" CHECK=test STRICT_VARIABLES=yes - - rvm: 2.4.1 - bundler_args: --without system_tests development - env: PUPPET_VERSION="~> 5.1.0" CHECK=test STRICT_VARIABLES=yes + - + env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" + - + env: CHECK=parallel_spec + - + env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec + rvm: 2.1.9 +branches: + only: + - master + - /^v\d/ +notifications: + email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "" + on: + tags: true + all_branches: true + condition: "$DEPLOY_TO_FORGE = yes" diff --git a/Gemfile b/Gemfile index 419379b..5cda86e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,43 +1,78 @@ -source ENV['GEM_SOURCE'] || "https://rubygems.org" - -group :test do - gem 'rake', :require => false - gem 'puppet-lint', :require => false - gem 'puppet-lint-absolute_classname-check', :require => false - gem 'puppet-lint-alias-check', :require => false - gem 'puppet-lint-package_ensure-check', :require => false - gem 'puppet-lint-legacy_facts-check', :require => false - gem 'puppet-lint-leading_zero-check', :require => false - gem 'puppet-lint-global_resource-check', :require => false - gem 'puppet-lint-file_source_rights-check', :require => false - gem 'puppet-lint-file_ensure-check', :require => false - gem 'puppet-lint-empty_string-check', :require => false - gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false - gem 'rspec-puppet-facts', :require => false - gem 'rspec-puppet-utils', :require => false - gem 'puppet-syntax', :require => false - gem 'safe_yaml', '~> 1.0.4', :require => false - gem 'rspec-puppet', '~> 2.5', :require => false - gem 'metadata-json-lint', :require => false - gem 'xmlrpc', :require => false - gem 'json', '< 2.0.0', :require => false +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +def location_for(place_or_version, fake_version = nil) + if place_or_version =~ %r{\A(git[:@][^#]*)#(.*)} + [fake_version, { git: Regexp.last_match(1), branch: Regexp.last_match(2), require: false }].compact + elsif place_or_version =~ %r{\Afile:\/\/(.*)} + ['>= 0', { path: File.expand_path(Regexp.last_match(1)), require: false }] + else + [place_or_version, { require: false }] + end +end + +def gem_type(place_or_version) + if place_or_version =~ %r{\Agit[:@]} + :git + elsif !place_or_version.nil? && place_or_version.start_with?('file:') + :file + else + :gem + end end + +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') + group :development do - gem 'travis', :require => false - gem 'travis-lint', :require => false - gem 'vagrant-wrapper', :require => false - gem 'puppet-blacksmith', :require => false - gem 'guard-rake', :require => false + gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') + gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') + gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') + gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') + gem "json", '<= 2.0.4', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4') + gem "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] end -group :system_tests do - gem 'beaker', :require => false + +puppet_version = ENV['PUPPET_GEM_VERSION'] +puppet_type = gem_type(puppet_version) +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +gems = {} + +gems['puppet'] = location_for(puppet_version) + +# If facter or hiera versions have been specified via the environment +# variables + +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version + +if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} + # If we're using a Puppet gem on Windows which handles its own win32-xxx gem + # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). + gems['win32-dir'] = ['<= 0.4.9', require: false] + gems['win32-eventlog'] = ['<= 0.6.5', require: false] + gems['win32-process'] = ['<= 0.7.5', require: false] + gems['win32-security'] = ['<= 0.2.5', require: false] + gems['win32-service'] = ['0.8.8', require: false] end -if facterversion = ENV['FACTER_GEM_VERSION'] - gem 'facter', facterversion.to_s, :require => false, :groups => [:test] -else -gem 'facter', :require => false, :groups => [:test] +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params end -ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 5.0' : puppetversion = ENV['PUPPET_VERSION'].to_s -gem 'puppet', puppetversion, :require => false, :groups => [:test] +# Evaluate Gemfile.local and ~/.gemfile if they exist +extra_gemfiles = [ + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] + +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end +end +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index e580aff..204fb18 100644 --- a/Rakefile +++ b/Rakefile @@ -1,44 +1,75 @@ require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint/tasks/puppet-lint' 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? -# These gems aren't always present, for instance on Travis -begin - require 'puppet_blacksmith/rake_tasks' -rescue LoadError +def changelog_user + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['author'] + raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator user:#{returnVal}" + returnVal end -Rake::Task[:lint].clear - -exclude_paths = %w( - pkg/**/* - vendor/**/* - .vendor/**/* - spec/**/* -) - -PuppetSyntax.exclude_paths = exclude_paths +def changelog_project + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['name'] + raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal +end -PuppetLint.configuration.relative = true -PuppetLint.configuration.fail_on_warnings = true -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.send('disable_140chars') -PuppetLint.configuration.send('disable_class_inherits_from_params_class') -PuppetLint.configuration.send('disable_legacy_facts') -PuppetLint.configuration.ignore_paths = exclude_paths -PuppetLint::RakeTask.new :lint do |config| - config.ignore_paths = exclude_paths +def changelog_future_release + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = JSON.load(File.read('metadata.json'))['version'] + raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator future_release:#{returnVal}" + returnVal end -desc "Populate CONTRIBUTORS file" -task :contributors do - system("git log --format='%aN' | sort -u > CONTRIBUTORS") +PuppetLint.configuration.send('disable_relative') + +if Bundler.rubygems.find_name('github_changelog_generator').any? + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? + config.user = "#{changelog_user}" + config.project = "#{changelog_project}" + config.future_release = "#{changelog_future_release}" + config.exclude_labels = ['maintenance'] + config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." + config.add_pr_wo_labels = true + config.issues = false + config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["feature", "enhancement"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise <= Gem::Version.new('2.2.2')" +EOM + end end -desc 'Run metadata_lint, syntax, lint, spec tests' -task test: [ - :metadata_lint, - :syntax, - :lint, - :spec, -] diff --git a/metadata.json b/metadata.json index 7c188e3..364f204 100644 --- a/metadata.json +++ b/metadata.json @@ -1,45 +1,87 @@ { - "name" : "claranet-varnish", - "version" : "5.0.0", - "source" : "https://github.com/claranet/puppet-varnish", - "author" : "Claranet", - "license" : "Apache-2.0", - "summary" : "Install and configure Varnish Cache", - "description" : "Install and configure Varnish Cache", - "project_page" : "https://github.com/claranet/puppet-varnish", - "issues_url" : "https://github.com/claranet/puppet-varnish/issues", - "tags" : [ "varnish", "cache", "http" ], + "name": "claranet-varnish", + "version": "5.0.0", + "author": "Claranet", + "summary": "Install and configure Varnish Cache", + "license": "Apache-2.0", + "source": "https://github.com/claranet/puppet-varnish", + "project_page": "https://github.com/claranet/puppet-varnish", + "issues_url": "https://github.com/claranet/puppet-varnish/issues", + "dependencies": [ + { + "name": "stahnma/epel", + "version_requirement": ">= 1.2.0 < 2.0.0" + }, + { + "name": "puppet/selinux", + "version_requirement": ">= 1.0.0 < 2.0.0" + }, + { + "name": "puppetlabs/apt", + "version_requirement": ">= 2.0.0 < 5.0.0" + }, + { + "name": "puppetlabs/stdlib", + "version_requirement": ">=4.6.0 < 6.0.0" + } + ], "operatingsystem_support": [ { "operatingsystem": "RedHat", - "operatingsystemrelease": [ "6", "7" ] + "operatingsystemrelease": [ + "6", + "7" + ] }, { "operatingsystem": "CentOS", - "operatingsystemrelease": [ "6", "7" ] + "operatingsystemrelease": [ + "6", + "7" + ] }, { "operatingsystem": "OracleLinux", - "operatingsystemrelease": [ "6", "7" ] + "operatingsystemrelease": [ + "6", + "7" + ] }, { "operatingsystem": "Scientific", - "operatingsystemrelease": [ "6", "7" ] + "operatingsystemrelease": [ + "6", + "7" + ] }, { "operatingsystem": "Ubuntu", - "operatingsystemrelease": [ "14.04", "16.04" ] + "operatingsystemrelease": [ + "14.04", + "16.04" + ] }, { "operatingsystem": "Debian", - "operatingsystemrelease": [ "7", "8" ] + "operatingsystemrelease": [ + "7", + "8" + ] } ], - "requirements": [ { "name": "puppet", "version_requirement": ">= 4.7.1 < 6.0.0" } ], - "dependencies": [ - { "name": "stahnma/epel", "version_requirement": ">= 1.2.0 < 2.0.0" }, - { "name": "puppet/selinux", "version_requirement": ">= 1.0.0 < 2.0.0" }, - { "name": "puppetlabs/apt", "version_requirement": ">= 2.0.0 < 5.0.0" }, - { "name": "puppetlabs/stdlib", "version_requirement": ">=4.6.0 < 6.0.0" } - ] + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.7.1 < 6.0.0" + } + ], + "description": "Install and configure Varnish Cache", + "tags": [ + "varnish", + "cache", + "http" + ], + "pdk-version": "1.7.0", + "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", + "template-ref": "1.7.0-0-g57412ed" } diff --git a/spec/classes/varnish_spec.rb b/spec/classes/varnish_spec.rb index 92d2b74..a2e3774 100644 --- a/spec/classes/varnish_spec.rb +++ b/spec/classes/varnish_spec.rb @@ -1,121 +1,120 @@ require 'spec_helper' -describe 'varnish', :type => :class do - +describe 'varnish', type: :class do ['3.0', '4.0', '4.1', '5.0', '5.1', '5.2'].each do |version| - on_supported_os.each do |os, facts| context "Varnish #{version} on #{os}" do - let(:facts) do - facts.merge({ - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', - }) + facts.merge(path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin') end - let (:params) {{ - :varnish_version => version, - }} + let(:params) do + { + varnish_version: version, + } + end should_fail = 0 case version when '3.0' if facts[:lsbdistcodename] == 'xenial' - it { is_expected.to raise_error(Puppet::Error, /Varnish 3 from Packagecloud is not supported on Ubuntu 16.04 \(Xenial\)/) } + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 3 from Packagecloud is not supported on Ubuntu 16.04 \(Xenial\)}) } should_fail = 1 end when '5.0' if facts[:osfamily] == 'RedHat' case facts[:operatingsystemmajrelease] when '6' - it { is_expected.to raise_error(Puppet::Error, /Varnish 5.0 from Packagecloud is not supported on RHEL\/CentOS 6/) } + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 from Packagecloud is not supported on RHEL\/CentOS 6}) } should_fail = 1 when '7' - it { is_expected.to raise_error(Puppet::Error, /Varnish 5.0 on RHEL\/CentOS 7 has a known packaging bug in the varnish_reload_vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message./) } + # rubocop:disable LineLength + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 on RHEL\/CentOS 7 has a known packaging bug in the varnish_reload_vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message.}) } + # rubocop:enable LineLength should_fail = 1 end elsif facts[:osfamily] == 'Debian' case facts[:lsbdistcodename] when 'wheezy' - it { is_expected.to raise_error(Puppet::Error, /Varnish 5.0 from Packagecloud is not supported on Debian 7 \(Wheezy\)/) } + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 from Packagecloud is not supported on Debian 7 \(Wheezy\)}) } should_fail = 1 when 'trusty' - it { is_expected.to raise_error(Puppet::Error, /Varnish 5.0 has a known packaging bug in the reload-vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message./) } + # rubocop:disable LineLength + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 has a known packaging bug in the reload-vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message.}) } + # rubocop:enable LineLength should_fail = 1 end end end if should_fail == 0 - it { should compile.with_all_deps } + it { is_expected.to compile.with_all_deps } + + if (facts[:osfamily] == 'RedHat' && facts[:operatingsystemmajrelease] == '7' && version != '3.0') || + (facts[:osfamily] == 'Debian' && (facts[:lsbdistcodename] == 'jessie' || facts[:lsbdistcodename] == 'xenial')) + it { is_expected.to contain_file('/etc/systemd/system/varnish.service') } + it { is_expected.to contain_exec('varnish_systemctl_daemon_reload') } + end case facts[:osfamily] when 'RedHat' - if facts[:operatingsystemmajrelease] == '7' and version != '3.0' - it { is_expected.to contain_file('/etc/systemd/system/varnish.service') } - it { is_expected.to contain_exec('varnish_systemctl_daemon_reload') } - end - - if facts[:operatingsystemmajrelease] == '6' and version != '3.0' + if facts[:operatingsystemmajrelease] == '6' && version != '3.0' it { is_expected.to contain_selinux__module('varnishpol') } end it { is_expected.to contain_file('/etc/sysconfig/varnish') } it { is_expected.to contain_yumrepo('varnish-cache') } it { is_expected.to contain_yumrepo('varnish-cache-source') } when 'Debian' - if facts[:lsbdistcodename] == 'jessie' or facts[:lsbdistcodename] == 'xenial' - it { is_expected.to contain_file('/etc/systemd/system/varnish.service') } - it { is_expected.to contain_exec('varnish_systemctl_daemon_reload') } - end - it { is_expected.to contain_file('/etc/default/varnish') } it { is_expected.to contain_package('apt-transport-https') } it { is_expected.to contain_apt__source('varnish-cache') } end end end end end context 'supported operating systems' do - - let(:facts) {{ - :osfamily => 'RedHat', - :operatingsystem => 'CentOS', - :operatingsystemmajrelease => '7', - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', - :lsbdistrelease => nil - }} + let(:facts) do + { + osfamily: 'RedHat', + operatingsystem: 'CentOS', + operatingsystemmajrelease: '7', + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', + lsbdistrelease: nil, + } + end it { is_expected.to contain_class('varnish::params') } it { is_expected.to contain_class('varnish::repo').that_comes_before('Class[varnish::install]') } it { is_expected.to contain_class('varnish::install').that_comes_before('Class[varnish::secret]') } it { is_expected.to contain_class('varnish::secret').that_comes_before('Class[varnish::config]') } it { is_expected.to contain_class('varnish::config').that_notifies('Class[varnish::service]') } it { is_expected.to contain_class('varnish::config').that_comes_before('Class[varnish::service]') } it { is_expected.to contain_class('varnish::service') } it { is_expected.to contain_file('/etc/varnish/secret') } it { is_expected.to contain_exec('Generate Varnish secret file') } it { is_expected.to contain_package('varnish') } it { is_expected.to contain_service('varnish') } it { is_expected.to contain_exec('vcl_reload') } end context 'unsupported operating systems' do - describe "varnish class fail on unsupported OS" do - let(:facts) {{ - :osfamily => 'Darwin', - :operatingsystem => 'Darwin', - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', - :lsbdistrelease => nil - }} + describe 'varnish class fail on unsupported OS' do + let(:facts) do + { + osfamily: 'Darwin', + operatingsystem: 'Darwin', + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', + lsbdistrelease: nil, + } + end - it { is_expected.to raise_error(Puppet::Error, /Darwin not supported/) } + it { is_expected.to raise_error(Puppet::Error, %r{Darwin not supported}) } end end - end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..3248be5 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,8 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +concat_basedir: "/tmp" +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/vcl_spec.rb b/spec/defines/vcl_spec.rb index e739dcc..5aa351b 100644 --- a/spec/defines/vcl_spec.rb +++ b/spec/defines/vcl_spec.rb @@ -1,28 +1,25 @@ require 'spec_helper' describe 'varnish::vcl' do - on_supported_os.each do |os, facts| - context "on #{os}" do let(:facts) do - facts.merge({ - :kernel => 'Linux', - :osreleasemaj => facts[:operatingsystemrelease].split('.').first, - :pygpgme_installed => true, - }) + facts.merge(kernel: 'Linux', + osreleasemaj: facts[:operatingsystemrelease].split('.').first, + pygpgme_installed: true) end - let(:title) { 'vcltest' } - let(:params) {{ - :content => 'return(lookup)\n', - :file => '/etc/varnish/default.vcl' - }} + let(:params) do + { + content: 'return(lookup)\n', + file: '/etc/varnish/default.vcl', + } + end - it { should compile.with_all_deps } - it { should contain_file('/etc/varnish/default.vcl').with_content('return(lookup)\n') } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file('/etc/varnish/default.vcl').with_content('return(lookup)\n') } end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 97e7975..5e721b7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,44 @@ require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' +begin + require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) +rescue LoadError => loaderror + warn "Could not require spec_helper_local: #{loaderror.message}" +end + include RspecPuppetFacts -fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')) +default_module_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')) + +if File.exist?(default_facts_path) && File.readable?(default_facts_path) + default_facts.merge!(YAML.safe_load(File.read(default_facts_path))) +end + +if File.exist?(default_module_facts_path) && File.readable?(default_module_facts_path) + default_facts.merge!(YAML.safe_load(File.read(default_module_facts_path))) +end RSpec.configure do |c| - c.template_dir = File.join(fixture_path, 'templates') + c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + end end + +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module) + last_module.const_get(next_module) + end +end + +# 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb index d32643d..3e9d37e 100644 --- a/spec/spec_helper_system.rb +++ b/spec/spec_helper_system.rb @@ -1,16 +1,16 @@ require 'rspec-system/spec_helper' require 'rspec-system-puppet/helpers' include RSpecSystemPuppet::Helpers RSpec.configure do |c| proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) c.tty = true c.include RSpecSystemPuppet::Helpers c.before :suite do puppet_install - puppet_module_install(:source => proj_root, :module_name => 'varnish') + puppet_module_install(source: proj_root, module_name: 'varnish') shell('puppet module install puppetlabs-stdlib') end end