diff --git a/.fixtures-previous.yml b/.fixtures-previous.yml new file mode 100644 index 0000000..fa7bf39 --- /dev/null +++ b/.fixtures-previous.yml @@ -0,0 +1,5 @@ +fixtures: + forge_modules: + stdlib: + repo: 'puppetlabs/stdlib' + ref: '9.7.0' diff --git a/.fixtures.yml b/.fixtures.yml index d4e209c..d9335bd 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,5 @@ fixtures: - repositories: - stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" - symlinks: - cpan: "#{source_dir}" + forge_modules: + stdlib: + repo: 'puppetlabs/stdlib' + ref: '10.1.1' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5a06711 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: CI + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # newest allowed dependency majors and the previous ones still allowed + fixtures: ['.fixtures.yml', '.fixtures-previous.yml'] + env: + FIXTURES_YML: ${{ matrix.fixtures }} + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + bundler-cache: true + - name: Run static and unit tests + run: bundle exec rake test rubocop diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index dd448e8..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -stages: - - syntax - - unit - -cache: - paths: - - vendor/bundle - -before_script: - - bundle -v - - rm Gemfile.lock || true - - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - - "# Set `rubygems_version` in the .sync.yml to set a value" - - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - - gem --version - - bundle -v - - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) - -syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.3-Puppet ~> 6: - stage: syntax - image: ruby:2.5.3 - script: - - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop - variables: - PUPPET_GEM_VERSION: '~> 6' - -parallel_spec-Ruby 2.5.3-Puppet ~> 6: - stage: unit - image: ruby:2.5.3 - script: - - bundle exec rake parallel_spec - variables: - PUPPET_GEM_VERSION: '~> 6' - -parallel_spec-Ruby 2.4.5-Puppet ~> 5: - stage: unit - image: ruby:2.4.5 - script: - - bundle exec rake parallel_spec - variables: - PUPPET_GEM_VERSION: '~> 5' - diff --git a/.pdkignore b/.pdkignore deleted file mode 100644 index e6215cd..0000000 --- a/.pdkignore +++ /dev/null @@ -1,42 +0,0 @@ -.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 -.project -.envrc -/inventory.yaml -/appveyor.yml -/.fixtures.yml -/Gemfile -/.gitattributes -/.gitignore -/.gitlab-ci.yml -/.pdkignore -/Rakefile -/rakelib/ -/.rspec -/.rubocop.yml -/.travis.yml -/.yardopts -/spec/ -/.vscode/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece..764bae2 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,4 @@ --relative +--no-parameter_types-check +--no-parameter_documentation-check +--no-anchor_resource-check diff --git a/.rubocop.yml b/.rubocop.yml index bab25db..e23f05e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,133 +1,5 @@ --- -require: -- rubocop-rspec -- rubocop-i18n -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 -GetText: - Enabled: false -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/**/* - Enabled: false -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 -GetText/DecorateFunctionMessage: - Enabled: false -GetText/DecorateStringFormattingUsingInterpolation: - Enabled: false -GetText/DecorateStringFormattingUsingPercent: - Enabled: false -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 +inherit_from: .rubocop_todo.yml + +inherit_gem: + voxpupuli-test: rubocop.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..560219d --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,40 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2026-11-05 16:13:40 UTC using RuboCop version 1.91.0. +# 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: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/BeEq: + Exclude: + - 'spec/types/cpan_spec.rb' + +# Offense count: 1 +RSpec/LeakyLocalVariable: + Exclude: + - 'spec/types/cpan_spec.rb' + +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Exclude: + - '**/*.arb' + - 'lib/puppet/provider/cpan/default.rb' + - 'lib/puppet/type/cpan.rb' + - 'spec/classes/config_spec.rb' + - 'spec/classes/cpan_spec.rb' + - 'spec/classes/install_spec.rb' + - 'spec/types/cpan_spec.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/puppet/provider/cpan/default.rb' diff --git a/.sync.yml b/.sync.yml deleted file mode 100644 index a5e7789..0000000 --- a/.sync.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -spec/spec_helper.rb: - mock_with: ':rspec' - coverage_report: true - minimum_code_coverage_percentage: 66 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cc78f7d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -dist: xenial -language: ruby -cache: bundler -before_install: - - bundle -v - - rm -f Gemfile.lock - - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - - gem --version - - bundle -v -script: - - 'bundle exec rake $CHECK' -bundler_args: --without system_tests -rvm: - - 2.5.3 -stages: - - static - - spec - - acceptance - - - if: tag =~ ^v\d - name: deploy -matrix: - fast_finish: true - include: - - - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" - stage: static - - - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec - rvm: 2.4.5 - stage: spec - - - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec - rvm: 2.5.3 - stage: spec - - - env: DEPLOY_TO_FORGE=yes - stage: deploy -branches: - only: - - master - - /^v\d/ -notifications: - email: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 48fce89..3062137 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## Unreleased + +**Changes** + +* Require OpenVox 8 and stdlib 9, support Debian 12/13, Ubuntu 22.04/24.04 and EL 8/9 +* Drop EL5 data + ## Release 2.3.0 **Features** diff --git a/Gemfile b/Gemfile index 8007ad0..02b6000 100644 --- a/Gemfile +++ b/Gemfile @@ -1,72 +1,6 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +source 'https://rubygems.org' -def location_for(place_or_version, fake_version = nil) - git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} - file_url_regex = %r{\Afile:\/\/(?.*)} - - if place_or_version && (git_url = place_or_version.match(git_url_regex)) - [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact - elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) - ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] - else - [place_or_version, { require: false }] - end -end - -ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments -minor_version = ruby_version_segments[0..1].join('.') - -group :development do - gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') - gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') - gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') - gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] -end - -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - -gems = {} - -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables - -gems['facter'] = location_for(facter_version) if facter_version -gems['hiera'] = location_for(hiera_version) if hiera_version - -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] -end - -gems.each do |gem_name, gem_params| - gem gem_name, *gem_params -end - -# Evaluate Gemfile.local and ~/.gemfile if they exist -extra_gemfiles = [ - "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), -] - -extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end -end -# vim: syntax=ruby +gem 'openvox', ENV.fetch('OPENVOX_GEM_VERSION', '~> 8.0'), require: false +gem 'voxpupuli-test', '~> 15.0', require: false +# jgrep (via facterdb) calls JSON.create_id=, removed in json 3.0 +gem 'json', '< 3', require: false diff --git a/README.md b/README.md index 60dafde..963c7c2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![Puppet Forge Version](http://img.shields.io/puppetforge/v/ccin2p3/cpan.svg)](https://forge.puppetlabs.com/ccin2p3/cpan) [![Puppet Forge Downloads](http://img.shields.io/puppetforge/dt/ccin2p3/cpan.svg)](https://forge.puppetlabs.com/ccin2p3/cpan) -[![Travis branch](https://img.shields.io/travis/ccin2p3/puppet-cpan/master.svg)](https://travis-ci.org/ccin2p3/puppet-cpan) [![By Meltwater](https://img.shields.io/badge/by-meltwater-28bbbb.svg)](http://underthehood.meltwater.com/) [![Maintenance](https://img.shields.io/maintenance/yes/2016.svg)](https://github.com/ccin2p3/puppet-cpan/commits/master) [![license](https://img.shields.io/github/license/ccin2p3/puppet-cpan.svg)](https://github.com/ccin2p3/puppet-cpan/blob/master/LICENSE) diff --git a/REFERENCE.md b/REFERENCE.md new file mode 100644 index 0000000..8950ba4 --- /dev/null +++ b/REFERENCE.md @@ -0,0 +1,259 @@ +# Reference + + + +## Table of Contents + +### Classes + +* [`cpan`](#cpan): == Class: cpan Installs cpan === Parameters [*manage_config*] [*manage_package*] [*installdirs*] [*local_lib*] [*config_template*] [* +* [`cpan::config`](#cpan--config): == Class: cpan::config Private class. Should not be called directly. +* [`cpan::install`](#cpan--install): == Class cpan::install Installs cpan. + +### Resource types + +* [`cpan`](#cpan): Install cpan modules + +## Classes + +### `cpan` + +== Class: cpan + +Installs cpan + +=== Parameters + +[*manage_config*] + +[*manage_package*] + +[*installdirs*] + +[*local_lib*] + +[*config_template*] + +[*config_hash*] + +[*package_ensure*] + +[*ftp_proxy*] + +[*http_proxy*] + +=== Examples + +class {'::cpan': + manage_config => true, + manage_package => true, + package_ensure => 'present', + installdirs => 'site', + local_lib => false, + config_hash => { 'build_requires_install_policy' => 'no' }, + ftp_proxy => 'http://your_ftp_proxy.com', + http_proxy => 'http://your_http_proxy.com', +} + +#### Parameters + +The following parameters are available in the `cpan` class: + +* [`manage_package`](#-cpan--manage_package) +* [`config_hash`](#-cpan--config_hash) +* [`package_name`](#-cpan--package_name) +* [`config_file`](#-cpan--config_file) +* [`config_dir`](#-cpan--config_dir) +* [`package_ensure`](#-cpan--package_ensure) +* [`manage_config`](#-cpan--manage_config) +* [`installdirs`](#-cpan--installdirs) +* [`local_lib`](#-cpan--local_lib) +* [`config_template`](#-cpan--config_template) +* [`ftp_proxy`](#-cpan--ftp_proxy) +* [`http_proxy`](#-cpan--http_proxy) +* [`urllist`](#-cpan--urllist) + +##### `manage_package` + +Data type: `Any` + + + +Default value: `false` + +##### `config_hash` + +Data type: `Any` + + + +Default value: `{ 'applypatch' => undef, 'auto_commit' => '0', 'build_cache' => '100', 'build_dir' => '/root/.cpan/build', 'build_dir_reuse' => '0', 'build_requires_install_policy' => 'no', 'bzip2' => '/bin/bzip2', 'cache_metadata' => '1', 'check_sigs' => '0', 'colorize_output' => '0', 'commandnumber_in_prompt' => '1', 'connect_to_internet_ok' => '1', 'cpan_home' => '/root/.cpan', 'curl' => '/usr/bin/curl', 'ftp' => '/usr/bin/ftp', 'ftp_passive' => '1', 'getcwd' => 'cwd', 'gpg' => '/usr/bin/gpg', 'gzip' => '/bin/gzip', 'halt_on_failure' => '0', 'histfile' => '/root/.cpan/histfile', 'histsize' => '100', 'inactivity_timeout' => '0', 'index_expire' => '1', 'inhibit_startup_message' => '0', 'keep_source_where' => '/root/.cpan/sources', 'load_module_verbosity' => 'v', 'lynx' => undef, 'make' => '/usr/bin/make', 'make_arg' => undef, 'make_install_arg' => undef, 'make_install_make_command' => undef, 'makepl_arg' => 'INSTALLDIRS=site', 'mbuild_arg' => undef, 'mbuild_install_arg' => undef, 'mbuild_install_build_command' => './Build', 'ncftp' => undef, 'ncftpget' => undef, 'no_proxy' => undef, 'pager' => '/usr/bin/less', 'patch' => '/usr/bin/patch', 'perl5lib_verbosity' => 'v', 'prefer_installer' => 'MB', 'prefs_dir' => '/root/.cpan/prefs', 'prerequisites_policy' => 'follow', 'scan_cache' => 'atstart', 'shell' => '/bin/bash', 'show_unparsable_versions' => '0', 'show_upload_date' => '0', 'show_zero_versions' => '0', 'tar' => '/bin/tar', 'tar_verbosity' => 'v', 'term_is_latin' => '1', 'term_ornaments' => '1', 'test_report' => '0', 'trust_test_report_history' => '0', 'unzip' => undef, 'use_sqlite' => '0', 'wget' => '/usr/bin/wget', 'yaml_load_code' => '0', 'yaml_module' => 'YAML' }` + +##### `package_name` + +Data type: `Any` + + + +Default value: `['gcc', 'make']` + +##### `config_file` + +Data type: `Optional[Array[String[1]]]` + + + +Default value: `undef` + +##### `config_dir` + +Data type: `Optional[Array[String[1]]]` + + + +Default value: `undef` + +##### `package_ensure` + +Data type: `Any` + + + +Default value: `'present'` + +##### `manage_config` + +Data type: `Any` + + + +Default value: `true` + +##### `installdirs` + +Data type: `Any` + + + +Default value: `'site'` + +##### `local_lib` + +Data type: `Any` + + + +Default value: `false` + +##### `config_template` + +Data type: `Any` + + + +Default value: `'cpan/cpan.conf.erb'` + +##### `ftp_proxy` + +Data type: `Any` + + + +Default value: `undef` + +##### `http_proxy` + +Data type: `Any` + + + +Default value: `undef` + +##### `urllist` + +Data type: `Any` + + + +Default value: `[]` + +### `cpan::config` + +== Class: cpan::config + +Private class. Should not be called directly. + +### `cpan::install` + +== Class cpan::install + +Installs cpan. + +## Resource types + +### `cpan` + +Install cpan modules + +#### Properties + +The following properties are available in the `cpan` type. + +##### `ensure` + +Valid values: `absent`, `present`, `installed`, `latest` + +Aliases: `"installed"=>"present"` + +The basic property that the resource should be in. + +#### Parameters + +The following parameters are available in the `cpan` type. + +* [`environment`](#-cpan--environment) +* [`exists_strategy`](#-cpan--exists_strategy) +* [`force`](#-cpan--force) +* [`local_lib`](#-cpan--local_lib) +* [`name`](#-cpan--name) +* [`provider`](#-cpan--provider) +* [`umask`](#-cpan--umask) + +##### `environment` + +List of environment variables in the form of a Hash + +##### `exists_strategy` + +Valid values: `include`, `find` + +Strategy to test for module existence + +Default value: `include` + +##### `force` + +Valid values: `true`, `false`, `yes`, `no` + +Enable/Disable to force the installation of the module. Disabled by default. + +Default value: `false` + +##### `local_lib` + +Destination directory or `false` + +##### `name` + +namevar + +The name of the module. + +##### `provider` + +The specific backend to use for this `cpan` resource. You will seldom need to specify this --- Puppet will usually +discover the appropriate provider for your platform. + +##### `umask` + +umask to run cpan with diff --git a/Rakefile b/Rakefile index cb7ed0c..dc7b8b1 100644 --- a/Rakefile +++ b/Rakefile @@ -1,88 +1 @@ -# frozen_string_literal: true - -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? - -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 - -def changelog_project - return unless Rake.application.top_level_tasks.include? "changelog" - - returnVal = nil - returnVal ||= begin - metadata_source = JSON.load(File.read('metadata.json'))['source'] - metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) - - metadata_source_match && metadata_source_match[1] - end - - raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? - - puts "GitHubChangelogGenerator project:#{returnVal}" - returnVal -end - -def changelog_future_release - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = "v%s" % 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 - -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 - +require 'voxpupuli/test/rake' diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index ec38949..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,56 +0,0 @@ ---- -version: 1.1.x.{build} -branches: - only: - - master - - release -skip_commits: - message: /^\(?doc\)?.*/ -clone_depth: 10 -init: - - SET - - 'mkdir C:\ProgramData\PuppetLabs\code && exit 0' - - 'mkdir C:\ProgramData\PuppetLabs\facter && exit 0' - - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0' - - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0' -environment: - matrix: - - - RUBY_VERSION: 24-x64 - CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop - - - PUPPET_GEM_VERSION: ~> 5.0 - RUBY_VERSION: 24 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 5.0 - RUBY_VERSION: 24-x64 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 6.0 - RUBY_VERSION: 25 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 6.0 - RUBY_VERSION: 25-x64 - CHECK: parallel_spec -matrix: - fast_finish: true -install: - - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% - - bundle install --jobs 4 --retry 2 --without system_tests - - type Gemfile.lock -build: off -test_script: - - bundle exec puppet -V - - ruby -v - - gem -v - - bundle -v - - bundle exec rake %CHECK% -notifications: - - provider: Email - to: - - nobody@nowhere.com - on_build_success: false - on_build_failure: false - on_build_status_changed: false diff --git a/data/os/RedHat/5.yaml b/data/os/RedHat/5.yaml deleted file mode 100644 index 5fe7284..0000000 --- a/data/os/RedHat/5.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -cpan::config_file: - - /usr/lib/perl5/5.8.8/CPAN/Config.pm diff --git a/lib/puppet/provider/cpan/default.rb b/lib/puppet/provider/cpan/default.rb index 3c8b64f..401d6b5 100644 --- a/lib/puppet/provider/cpan/default.rb +++ b/lib/puppet/provider/cpan/default.rb @@ -3,7 +3,7 @@ commands cpan: 'cpan' commands perl: 'perl' - confine osfamily: [:Debian, :RedHat, :Windows] + confine osfamily: %i[Debian RedHat Windows] ENV['PERL_MM_USE_DEFAULT'] = '1' def install; end @@ -11,18 +11,14 @@ def install; end def force; end def version - if resource[:local_lib] - ll = "-Mlocal::lib=#{resource[:local_lib]}" - end + ll = "-Mlocal::lib=#{resource[:local_lib]}" if resource[:local_lib] current_version = `perl #{ll} -M#{resource[:name]} -e 'print $#{resource[:name]}::VERSION'` current_version.chomp current_version end def latest - if resource[:local_lib] - ll = "-Mlocal::lib=#{resource[:local_lib]}" - end + ll = "-Mlocal::lib=#{resource[:local_lib]}" if resource[:local_lib] cpan_str = `perl #{ll} -e 'use CPAN; my $mod=CPAN::Shell->expand("Module","#{resource[:name]}"); \ printf("%s", $mod->cpan_version eq "undef" || !defined($mod->cpan_version) ? "-" : $mod->cpan_version);'` latest_version = cpan_str.match(%r{^[0-9]+.?[0-9]*$})[0] @@ -33,17 +29,14 @@ def latest def latest? current_version = version latest_version = latest - if current_version < latest_version - return false - end + return false if current_version < latest_version + true end def create Puppet.info("Installing cpan module #{resource[:name]}") - if resource[:local_lib] - ll = "-Mlocal::lib=#{resource[:local_lib]}" - end + ll = "-Mlocal::lib=#{resource[:local_lib]}" if resource[:local_lib] umask = "umask #{resource[:umask]};" if resource[:umask] if resource[:environment] @@ -81,9 +74,7 @@ def destroy; end def update Puppet.info("Upgrading cpan module #{resource[:name]}") Puppet.debug("cpan #{resource[:name]}") - if resource[:local_lib] - ll = "-Mlocal::lib=#{resource[:local_lib]}" - end + ll = "-Mlocal::lib=#{resource[:local_lib]}" if resource[:local_lib] umask = "umask #{resource[:umask]};" if resource[:umask] if resource[:environment] resource[:environment].each do |var, val| @@ -103,9 +94,7 @@ def update end def exists? - if resource[:local_lib] - ll = "-Mlocal::lib=#{resource[:local_lib]}" - end + ll = "-Mlocal::lib=#{resource[:local_lib]}" if resource[:local_lib] exists_command = case resource[:exists_strategy] when :find # stolen from pmtools/pmpath diff --git a/lib/puppet/type/cpan.rb b/lib/puppet/type/cpan.rb index a11d31b..4d9ce20 100644 --- a/lib/puppet/type/cpan.rb +++ b/lib/puppet/type/cpan.rb @@ -4,41 +4,28 @@ @doc = 'Install cpan modules' ensurable do newvalue(:absent) do - if provider.exists? - provider.destroy - end + provider.destroy if provider.exists? end newvalue(:present) do - unless provider.exists? - provider.create - end + provider.create unless provider.exists? end aliasvalue(:installed, :present) newvalue(:latest) do - unless provider.latest? - provider.update - end + provider.update unless provider.latest? end def insync?(is) @should ||= [] - if is == :absent - provider.create - end + provider.create if is == :absent case should when :present - return true unless [:absent, :purged, :held].include?(is) + true unless %i[absent purged held].include?(is) when :latest return true if provider.latest? - debug 'CPAN Module %s version is out of date, installed version: %s, latest version: %s' % - [ - @resource.name, - provider.version, - provider.latest, - ] + debug format('CPAN Module %s version is out of date, installed version: %s, latest version: %s', @resource.name, provider.version, provider.latest) false end end diff --git a/manifests/config.pp b/manifests/config.pp index 51d3f10..dc2c35a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -3,7 +3,7 @@ # Private class. Should not be called directly. # class cpan::config inherits cpan { - if $::cpan::manage_config { + if $cpan::manage_config { unless $cpan::config_dir =~ Undef { file { $cpan::config_dir: ensure => directory, @@ -13,11 +13,11 @@ } } file { $cpan::config_file: - ensure => present, + ensure => file, owner => root, group => root, mode => '0644', - content => template($::cpan::config_template), + content => template($cpan::config_template), } } } diff --git a/manifests/init.pp b/manifests/init.pp index 302904c..31fd2c7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -50,24 +50,22 @@ $http_proxy = undef, $urllist = [], ) { - - validate_bool($manage_config) - validate_bool($manage_package) - validate_string($installdirs) - validate_bool($local_lib) - validate_string($config_template) - validate_string($package_ensure) + assert_type(Boolean, $manage_config) + assert_type(Boolean, $manage_package) + assert_type(String, $installdirs) + assert_type(Boolean, $local_lib) + assert_type(String, $config_template) + assert_type(String, $package_ensure) if $ftp_proxy { - validate_string($ftp_proxy) + assert_type(String, $ftp_proxy) } if $http_proxy { - validate_string($http_proxy) + assert_type(String, $http_proxy) } - validate_array($urllist) + assert_type(Array, $urllist) anchor { 'cpan::begin': } - -> class { '::cpan::install': } - -> class { '::cpan::config': } + -> class { 'cpan::install': } + -> class { 'cpan::config': } -> anchor { 'cpan::end': } - } diff --git a/manifests/install.pp b/manifests/install.pp index 7be7525..2cafb6a 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -3,14 +3,13 @@ # Installs cpan. # class cpan::install inherits cpan { - - if $::cpan::manage_package { - package { $::cpan::package_name : - ensure => $::cpan::package_ensure, + if $cpan::manage_package { + package { $cpan::package_name : + ensure => $cpan::package_ensure, } - if $::cpan::local_lib { - package { $::cpan::local_lib_package_name : - ensure => $::cpan::local_lib_package_ensure, + if $cpan::local_lib { + package { $cpan::local_lib_package_name : + ensure => $cpan::local_lib_package_ensure, } } } diff --git a/metadata.json b/metadata.json index 4d8668c..3c990b3 100644 --- a/metadata.json +++ b/metadata.json @@ -1,5 +1,5 @@ { - "name": "ccin2p3-cpan", + "name": "meltwater-cpan", "version": "2.3.0", "author": "meltwater", "summary": "Provides a puppet type to easily install Perl CPAN modules.", @@ -10,32 +10,36 @@ "dependencies": [ { "name": "puppetlabs-stdlib", - "version_requirement": ">= 4.6.0 < 9.0.0" + "version_requirement": ">= 9.0.0 < 11.0.0" } ], "operatingsystem_support": [ { - "operatingsystem": "RedHat", + "operatingsystem": "Debian", "operatingsystemrelease": [ - "5", - "6", - "7", - "8", - "9" + "12", + "13" ] }, { - "operatingsystem": "Debian", + "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "6", - "7" + "22.04", + "24.04" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "8", + "9" ] } ], "requirements": [ { - "name": "puppet", - "version_requirement": ">= 4.10.0 < 8.0.0" + "name": "openvox", + "version_requirement": ">= 8.0.0 < 9.0.0" } ], "description": "Puppet module for installing and configuring the Marathon framework for Mesos.", @@ -45,8 +49,5 @@ "metacpan", "module", "lib" - ], - "pdk-version": "1.16.0", - "template-url": "pdk-default#1.16.0", - "template-ref": "tags/1.16.0-0-gaf44904" + ] } diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index f002bd5..76598f3 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -5,142 +5,57 @@ context "On #{os}" do let(:facts) { os_facts } + let(:config_file) do + case os_facts[:os]['family'] + when 'Debian' then '/etc/perl/CPAN/Config.pm' + when 'RedHat' then '/usr/share/perl5/vendor_perl/CPAN/Config.pm' + end + end + context 'With default ::cpan parameters' do + let(:pre_condition) { 'include cpan' } + + it { is_expected.to contain_file(config_file).with_owner('root').with_group('root').with_mode('0644') } + it { is_expected.to contain_file(config_file).with_content(%r{^ 'http_proxy' => q\[\],$}) } + it { is_expected.to contain_file(config_file).with_content(%r{^ 'ftp_proxy' => q\[\],$}) } + + it { is_expected.to contain_file(config_file).with_content(%r{^ 'urllist' => \[\n\n \],$}) } + + it { is_expected.to contain_file('/etc/perl/CPAN').with_ensure('directory') } if os_facts[:os]['family'] == 'Debian' + end + + context 'with proxies set' do let(:pre_condition) do - [ - 'include cpan', - ] + 'class { "cpan": + ftp_proxy => "http://your_ftp_proxy.com", + http_proxy => "http://your_http_proxy.com", + }' end - case os_facts[:osfamily] - when 'Debian' - it { is_expected.to contain_file('/etc/perl/CPAN/Config.pm').with_owner('root') } - it { is_expected.to contain_file('/etc/perl/CPAN/Config.pm').with_group('root') } - it { is_expected.to contain_file('/etc/perl/CPAN/Config.pm').with_mode('0644') } - when 'RedHat' - case os_facts[:os]['release']['major'] - when '5' - it { - is_expected.to contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_owner('root') - is_expected.to contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_group('root') - is_expected.to contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_mode('0644') - } - when '6' - it { - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_owner('root') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_group('root') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_mode('0644') - } - when '7' - it { - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_owner('root') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_group('root') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_mode('0644') - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'http_proxy' => q\[\],$}) - is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'ftp_proxy' => q\[\],$}) - } - it 'has empty urlist' do - verify_contents(catalogue, '/usr/share/perl5/CPAN/Config.pm', [ - " 'urllist' => [", - ' ],', - ]) - end - when '8' - it { - is_expected.to contain_file('/usr/share/perl5/vendor_perl/CPAN/Config.pm').with_owner('root') - is_expected.to contain_file('/usr/share/perl5/vendor_perl/CPAN/Config.pm').with_group('root') - is_expected.to contain_file('/usr/share/perl5/vendor_perl/CPAN/Config.pm').with_mode('0644') - } - end - end + it { is_expected.to contain_file(config_file).with_content(%r{^ 'ftp_proxy' => q\[http://your_ftp_proxy\.com\],$}) } + it { is_expected.to contain_file(config_file).with_content(%r{^ 'http_proxy' => q\[http://your_http_proxy\.com\],$}) } end - context 'With custom ::cpan parameters' do - case os_facts[:osfamily] - when 'RedHat' - case os_facts[:os]['release']['major'] - when '7' - context 'with proxies set' do - let(:pre_condition) do - [ - 'class { "cpan": - ftp_proxy => "http://your_ftp_proxy.com", - http_proxy => "http://your_http_proxy.com", - } - ', - ] - end - it { is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'ftp_proxy' => q\[http://your_ftp_proxy\.com\],$}) } - it { is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'http_proxy' => q\[http://your_http_proxy\.com\],$}) } - end - context 'with custom param set' do - describe 'string' do - let(:pre_condition) do - [ - 'class { "cpan": - config_hash => { "foo" => "bar" } - }', - ] - end + context 'with a custom string in config_hash' do + let(:pre_condition) { 'class { "cpan": config_hash => { "foo" => "bar" } }' } - it { is_expected.to contain_file('/usr/share/perl5/CPAN/Config.pm').with_content(%r{^ 'foo' => q\[bar],$}) } - end - describe 'array' do - let(:pre_condition) do - [ - 'class {"cpan": - config_hash => { "foo" => ["baz","bar"] } - }', - ] - end + it { is_expected.to contain_file(config_file).with_content(%r{^ 'foo' => q\[bar\],$}) } + end - it do - verify_contents(catalogue, '/usr/share/perl5/CPAN/Config.pm', [ - " 'foo' => [", - ' q[baz],', - ' q[bar]', - ]) - end - end - end - context 'with urllist set' do - describe 'single url' do - let(:pre_condition) do - 'class { "cpan": - urllist => ["http://httpupdate3.cpanel.net/CPAN/"], - }' - end + context 'with a custom array in config_hash' do + let(:pre_condition) { 'class { "cpan": config_hash => { "foo" => ["baz", "bar"] } }' } - it do - verify_contents(catalogue, '/usr/share/perl5/CPAN/Config.pm', [ - " 'urllist' => [", - ' q[http://httpupdate3.cpanel.net/CPAN/]', - ' ],', - ]) - end - end - describe 'two urls' do - let(:pre_condition) do - 'class { "::cpan": - urllist => [ - "http://httpupdate3.cpanel.net/CPAN/", - "ftp://cpan.cse.msu.edu/" - ], - }' - end + it { is_expected.to contain_file(config_file).with_content(%r{^ 'foo' => \[\n q\[baz\],\n q\[bar\]\n \],$}) } + end - it do - verify_contents(catalogue, '/usr/share/perl5/CPAN/Config.pm', [ - " 'urllist' => [", - ' q[http://httpupdate3.cpanel.net/CPAN/],', - ' q[ftp://cpan.cse.msu.edu/]', - ' ],', - ]) - end - end - end - end + context 'with two urls in urllist' do + let(:pre_condition) do + 'class { "cpan": + urllist => ["http://httpupdate3.cpanel.net/CPAN/", "ftp://cpan.cse.msu.edu/"], + }' end + + it { is_expected.to contain_file(config_file).with_content(%r{^ 'urllist' => \[\n q\[http://httpupdate3\.cpanel\.net/CPAN/\],\n q\[ftp://cpan\.cse\.msu\.edu/\]\n \],$}) } end end end diff --git a/spec/classes/cpan_spec.rb b/spec/classes/cpan_spec.rb index 6cdd07b..caa4e9b 100644 --- a/spec/classes/cpan_spec.rb +++ b/spec/classes/cpan_spec.rb @@ -14,7 +14,7 @@ it { is_expected.to contain_package('gcc').with(ensure: 'present') } it { is_expected.to contain_package('make').with(ensure: 'present') } - case os_facts[:osfamily] + case os_facts[:os]['family'] when 'Debian' it { is_expected.to contain_package('perl').with(ensure: 'present') } when 'RedHat' @@ -26,7 +26,8 @@ it { is_expected.to contain_package('gcc').with_ensure('latest') } it { is_expected.to contain_package('make').with_ensure('latest') } - case os_facts[:osfamily] + + case os_facts[:os]['family'] when 'Debian' it { is_expected.to contain_package('perl').with(ensure: 'latest') } when 'RedHat' diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index 2dac313..6966748 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -20,7 +20,7 @@ it { is_expected.to contain_package('gcc').with(ensure: 'present') } it { is_expected.to contain_package('make').with(ensure: 'present') } - case os_facts[:osfamily] + case os_facts[:os]['family'] when 'Debian' it { is_expected.to contain_package('perl').with(ensure: 'present') } it { is_expected.not_to contain_package('perl-CPAN').with(ensure: 'present') } @@ -29,6 +29,7 @@ it { is_expected.not_to contain_package('perl').with(ensure: 'present') } end end + describe 'should allow package ensure to be overridden' do let(:pre_condition) do [ @@ -42,7 +43,8 @@ it { is_expected.to contain_package('gcc').with_ensure('latest') } it { is_expected.to contain_package('make').with_ensure('latest') } - case os_facts[:osfamily] + + case os_facts[:os]['family'] when 'Debian' it { is_expected.to contain_package('perl').with(ensure: 'latest') } when 'RedHat' diff --git a/spec/default_facts.yml b/spec/default_facts.yml deleted file mode 100644 index f777abf..0000000 --- a/spec/default_facts.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Use default_module_facts.yml for module specific facts. -# -# Facts specified here will override the values provided by rspec-puppet-facts. ---- -ipaddress: "172.16.254.254" -ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" -is_pe: false -macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c485ebe..7be5142 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,61 +1,3 @@ # frozen_string_literal: true -RSpec.configure do |c| - c.mock_with :rspec -end - -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' - -require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) - -include RspecPuppetFacts - -default_facts = { - puppetversion: Puppet.version, - facterversion: Facter.version, -} - -default_fact_files = [ - File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), - File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), -] - -default_fact_files.each do |f| - next unless File.exist?(f) && File.readable?(f) && File.size?(f) - - begin - default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e - RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" - end -end - -# read default_facts and merge them over what is provided by facterdb -default_facts.each do |fact, value| - add_custom_fact fact, value -end - -RSpec.configure do |c| - 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 - c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] - c.after(:suite) do - RSpec::Puppet::Coverage.report!(66) - end -end - -# Ensures that a module is defined -# @param module_name Name of the module -def ensure_module_defined(module_name) - module_name.split('::').reduce(Object) do |last_module, next_module| - last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) - last_module.const_get(next_module, false) - end -end - -# 'spec_overrides' from sync.yml will appear below this line +require 'voxpupuli/test/spec_helper' diff --git a/spec/types/cpan_spec.rb b/spec/types/cpan_spec.rb index 2346dc0..f1a2dc5 100644 --- a/spec/types/cpan_spec.rb +++ b/spec/types/cpan_spec.rb @@ -8,8 +8,9 @@ describe 'valid type' do it { is_expected.to be_valid_type } end + describe 'ensure' do - [:present, :absent, :installed, :latest].each do |value| + %i[present absent installed latest].each do |value| it "accepts #{value} as a value" do is_expected.to be_valid_type.with_set_attributes(ensure: value) end @@ -29,6 +30,7 @@ it 'accepts an absolute path' do is_expected.to be_valid_type.with_set_attributes(local_lib: '/path/to/file') end + it 'accepts false' do is_expected.to be_valid_type.with_set_attributes(local_lib: false) end @@ -43,12 +45,15 @@ it 'rejects other values' do expect { is_expected.to be_valid_type.with_set_attributes(force: 'nope') }.to raise_error(Puppet::ResourceError) end + it 'defaults to false' do expect(described_type.new(name: 'test')[:force]).to eq(false) end + it 'munges \'false\' to false' do expect(described_type.new(name: 'test', force: 'false')[:force]).to eq(false) end + it 'munges \'true\' to true' do expect(described_type.new(name: 'test', force: 'true')[:force]).to eq(true) end @@ -56,12 +61,13 @@ describe 'umask' do describe 'valid values' do - ['0022', '022', '0027', '027'].each do |value| + %w[0022 022 0027 027].each do |value| it "accepts #{value}" do is_expected.to be_valid_type.with_set_attributes(umask: value) end end end + describe 'invalid values' do [true, false, 220, '0', '888', 'invalid'].each do |value| it "rejects #{value}" do diff --git a/test/environment.pp b/test/environment.pp index 02ae029..045f15c 100644 --- a/test/environment.pp +++ b/test/environment.pp @@ -1,16 +1,16 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => false, } Cpan { - local_lib => '/tmp/CPAN' + local_lib => '/tmp/CPAN', } cpan { 'DBD::DB2': ensure => present, environment => { - 'DB2_HOME' => '/tmp/db2' - } + 'DB2_HOME' => '/tmp/db2', + }, } diff --git a/test/exists_command.pp b/test/exists_command.pp index 93ac13d..cd962c6 100644 --- a/test/exists_command.pp +++ b/test/exists_command.pp @@ -1,5 +1,5 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => false, } diff --git a/test/ftp_proxy.pp b/test/ftp_proxy.pp index ee62149..575a8a7 100644 --- a/test/ftp_proxy.pp +++ b/test/ftp_proxy.pp @@ -1,6 +1,6 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => true, - ftp_proxy => 'http://your_ftp_proxy.com' + ftp_proxy => 'http://your_ftp_proxy.com', } diff --git a/test/http_proxy.pp b/test/http_proxy.pp index 7500d09..b11d59d 100644 --- a/test/http_proxy.pp +++ b/test/http_proxy.pp @@ -1,6 +1,6 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => true, - http_proxy => 'http://your_ftp_proxy.com' + http_proxy => 'http://your_ftp_proxy.com', } diff --git a/test/local_lib.pp b/test/local_lib.pp index f65e125..cfe32ef 100644 --- a/test/local_lib.pp +++ b/test/local_lib.pp @@ -1,10 +1,10 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => false, } cpan { 'Riemann::Client': ensure => present, - local_lib => '/tmp/cpan' + local_lib => '/tmp/cpan', } diff --git a/test/local_lib_default.pp b/test/local_lib_default.pp index 8b0a716..5de02f7 100644 --- a/test/local_lib_default.pp +++ b/test/local_lib_default.pp @@ -1,13 +1,13 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => false, } Cpan { - local_lib => '/tmp/CPAN' + local_lib => '/tmp/CPAN', } cpan { 'Riemann::Client': - ensure => present, + ensure => present, } diff --git a/test/no_ftp_proxy.pp b/test/no_ftp_proxy.pp index 16a2b71..6b695b1 100644 --- a/test/no_ftp_proxy.pp +++ b/test/no_ftp_proxy.pp @@ -1,6 +1,6 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => true, - ftp_proxy => undef + ftp_proxy => undef, } diff --git a/test/no_http_proxy.pp b/test/no_http_proxy.pp index 1b3ff4d..70fa44a 100644 --- a/test/no_http_proxy.pp +++ b/test/no_http_proxy.pp @@ -1,6 +1,6 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => true, - http_proxy => undef + http_proxy => undef, } diff --git a/test/no_local_lib.pp b/test/no_local_lib.pp index 7e670b5..9a5bb5c 100644 --- a/test/no_local_lib.pp +++ b/test/no_local_lib.pp @@ -1,10 +1,10 @@ # -class { '::cpan': +class { 'cpan': manage_package => false, manage_config => false, } cpan { 'Riemann::Client': ensure => present, - local_lib => false + local_lib => false, }