From 3b32b6326eafb92f46fde09b149fe21b92878ac0 Mon Sep 17 00:00:00 2001 From: Elfranne Date: Fri, 7 Dec 2018 12:53:34 +0100 Subject: [PATCH] PDK Convert --- .fixtures.yml | 8 +- .gitignore | 43 +-- .gitlab-ci.yml | 41 +++ .pdkignore | 24 ++ .rspec | 2 + .rubocop.yml | 122 ++++++++ .travis.yml | 52 +++- .yardopts | 1 + Gemfile | 78 ++++- README.md | 3 +- Rakefile | 82 +++++- appveyor.yml | 60 ++++ examples/init.pp | 12 + manifests/api.pp | 6 +- manifests/init.pp | 48 ++-- manifests/mirror.pp | 52 ++-- manifests/repo.pp | 13 +- metadata.json | 41 ++- spec/classes/api_spec.rb | 328 +++++++++++++-------- spec/classes/init_spec.rb | 167 +++++++---- spec/default_facts.yml | 8 + spec/defines/mirror_spec.rb | 516 ++++++++++++++++++++-------------- spec/defines/repo_spec.rb | 152 ++++++---- spec/defines/snapshot_spec.rb | 95 ++++--- spec/spec_helper.rb | 52 +++- spec/spec_helper_system.rb | 4 +- spec/system/basic_spec.rb | 8 +- spec/system/mirror_spec.rb | 10 +- 28 files changed, 1386 insertions(+), 642 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 .pdkignore create mode 100644 .rspec create mode 100644 .rubocop.yml create mode 100644 .yardopts create mode 100644 appveyor.yml create mode 100644 examples/init.pp create mode 100644 spec/default_facts.yml diff --git a/.fixtures.yml b/.fixtures.yml index b9cd97f..d5eba00 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,10 @@ fixtures: repositories: stdlib: - repo: "git://github.com/puppetlabs/puppetlabs-stdlib.git" - ref: "4.12.0" + repo: "https://github.com/puppetlabs/puppetlabs-stdlib.git" + ref: "4.25.1" apt: - repo: "git://github.com/puppetlabs/puppetlabs-apt.git" - ref: "2.2.0" + repo: "https://github.com/puppetlabs/puppetlabs-apt.git" + ref: "4.5.0" symlinks: aptly: "#{source_dir}" diff --git a/.gitignore b/.gitignore index eab7fe7..baff38c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1,25 @@ -pkg/ -modules/ -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ -.vagrant/ -.bundle/ -coverage/ -log/ -.idea/ -.dependencies/ -.librarian/ -Puppetfile.lock +.vscode/ +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns *.iml -*.bak -.*.sw? -.yardoc/ +/.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/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..e369e3c --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,41 @@ +--- +stages: + - syntax + - unit + +cache: + paths: + - vendor/bundle + +before_script: + - bundle -v + - rm Gemfile.lock || true + - gem update --system + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + +parallel_spec-Ruby 2.1.9-Puppet ~> 4.0: + stage: unit + image: ruby:2.1.9 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 4.0' + +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.4.4-Puppet ~> 5.5: + stage: syntax + image: ruby:2.4.4 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 5.5' + +parallel_spec-Ruby 2.4.4-Puppet ~> 5.5: + stage: unit + image: ruby:2.4.4 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 5.5' + 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 new file mode 100644 index 0000000..16f9cdb --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..7e5c5fb --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,122 @@ +--- +require: rubocop-rspec +AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.4' + Include: + - "./**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Metrics/LineLength: + Description: People have wide screens, use them. + Max: 250 +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/TrailingCommaInArrayLiteral: + Description: Prefer always trailing comma on multiline arrays. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInHashLiteral: + Description: Prefer always trailing comma on multiline hashes. 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/.travis.yml b/.travis.yml index f018749..c948f3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,47 @@ --- +sudo: false +dist: trusty language: ruby -before_install: rm Gemfile.lock || true -bundler_args: --without functional_tests -script: bundle exec rake test +cache: bundler +before_install: + - bundle -v + - rm -f Gemfile.lock + - gem update --system + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests +rvm: + - 2.5.0 +env: + global: + - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" matrix: fast_finish: true include: - - rvm: 1.9.3 - env: PUPPET_VERSION="~> 3.8.0" - - rvm: 2.4.0 - env: PUPPET_VERSION="~> 5.3.0" - allow_failures: - - rvm: 2.4.0 - env: PUPPET_VERSION="~> 5.3.0" + - + 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="~> 5.0" CHECK=parallel_spec + rvm: 2.4.4 + - + 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/.yardopts b/.yardopts new file mode 100644 index 0000000..29c933b --- /dev/null +++ b/.yardopts @@ -0,0 +1 @@ +--markup markdown diff --git a/Gemfile b/Gemfile index adac2b5..626d661 100644 --- a/Gemfile +++ b/Gemfile @@ -1,16 +1,70 @@ -source 'https://rubygems.org' +source ENV['GEM_SOURCE'] || 'https://rubygems.org' -gem 'puppet', ENV['PUPPET_VERSION'] || '~> 3.8.0' +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} -gem 'rake', '~> 12.1.0' -gem 'puppet-lint', '~> 2.3.3' -gem 'rspec-puppet', '~> 2.6.9' -gem 'puppetlabs_spec_helper', '~> 2.3.2' -gem 'puppet-syntax', '~> 2.4.1' + 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::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 + +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'), +] -group :functional_tests do - gem 'test-kitchen' - gem 'kitchen-docker' - gem 'kitchen-inspec' - gem 'kitchen-puppet' +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/README.md b/README.md index 27c9914..35c9719 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -# aptly - +# aptly Puppet module for [aptly](http://www.aptly.info/). ## Example usage diff --git a/Rakefile b/Rakefile index 45d3245..204fb18 100644 --- a/Rakefile +++ b/Rakefile @@ -1,17 +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? -# Boilerplated from existing modules. TODO -PuppetLint.configuration.log_format = "%{path}:%{line}:%{check}:%{KIND}:%{message}" -PuppetLint.configuration.send('disable_class_parameter_defaults') -PuppetLint.configuration.send('disable_class_inherits_from_params_class') +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 -PuppetLint.configuration.fail_on_warnings = true +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 + +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 + +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 syntax, lint, and spec tests." -task :test => [ - :syntax, - :lint, - :spec, -] diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..bb60864 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,60 @@ +--- +version: 1.1.x.{build} +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: ~> 4.0 + RUBY_VERSION: 21 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 4.0 + RUBY_VERSION: 21-x64 + CHECK: parallel_spec + - + 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/examples/init.pp b/examples/init.pp new file mode 100644 index 0000000..8f49bac --- /dev/null +++ b/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# http://docs.puppetlabs.com/guides/tests_smoke.html +# +include aptly diff --git a/manifests/api.pp b/manifests/api.pp index 6ab0520..073d691 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -37,13 +37,13 @@ $enable_cli_and_http = false, ) { - validate_re($ensure, ['^stopped|running$'], 'Valid values for $ensure: stopped, running') + validate_re($ensure, ['^(stopped|running)$'], 'Valid values for $ensure: stopped, running') validate_string($user, $group) - validate_re($listen, ['^[0-9.]*:[0-9]+$'], 'Valid values for $listen: :port, :') + validate_re($listen, ['^([0-9.]*:[0-9]+$|unix:)'], 'Valid values for $listen: :port, :, unix:///path') - validate_re($log, ['^none|log$'], 'Valid values for $log: none, log') + validate_re($log, ['^(none|log)$'], 'Valid values for $log: none, log') if $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '15.04') < 0 { file { 'aptly-upstart': diff --git a/manifests/init.pp b/manifests/init.pp index d4d23a5..c5a4431 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -6,12 +6,12 @@ # # [*package_ensure*] # Ensure parameter to pass to the package resource. -# Default: present +# Default: 'present' # # [*config_file*] # Absolute path to the configuration file. Defaults to # `/etc/aptly.conf`. -# + # [*config_contents*] # Contents of the config file. # Default: undef @@ -27,9 +27,8 @@ # Default: true # # [*key_server*] -# Key server to use when `$repo` is true. Uses the default of -# `apt::source` if not specified. -# Default: undef +# Key server to use when `$repo` is true. +# Default: keyserver.ubuntu.com # # [*user*] # The user to use when performing an aptly command @@ -44,38 +43,25 @@ # Default: {} # class aptly ( - $package_ensure = present, - $config_file = '/etc/aptly.conf', - $config = {}, - $config_contents = undef, - $repo = true, - $key_server = undef, - $user = 'root', - $aptly_repos = {}, - $aptly_mirrors = {}, + String $package_ensure = 'present', + Stdlib::Absolutepath $config_file = '/etc/aptly.conf', + Hash $config = {}, + Optional[String] $config_contents = undef, + Boolean $repo = true, + String $key_server = 'keyserver.ubuntu.com', + String $user = 'root', + Hash $aptly_repos = {}, + Hash $aptly_mirrors = {}, ) { - - validate_absolute_path($config_file) - validate_hash($config) - validate_hash($aptly_repos) - validate_hash($aptly_mirrors) - validate_bool($repo) - validate_string($key_server) - validate_string($user) - - if $config_contents { - validate_string($config_contents) - } - if $repo { apt::source { 'aptly': location => 'http://repo.aptly.info', release => 'squeeze', repos => 'main', - key => { - 'server' => $key_server, - 'id' => '26DA9D8630302E0B86A7A2CBED75B5A4483DA07C', - }, + key => { + server => $key_server, + id => 'DF32BC15E2145B3FA151AED19E3E53F19C7DE460', + } } Apt::Source['aptly'] -> Class['apt::update'] -> Package['aptly'] diff --git a/manifests/mirror.pp b/manifests/mirror.pp index f906414..592d0f1 100644 --- a/manifests/mirror.pp +++ b/manifests/mirror.pp @@ -58,30 +58,21 @@ # Example: ['http_proxy=http://127.0.0.2:3128'] # Default: [] define aptly::mirror ( - $location, - $key = undef, - $keyserver = 'keyserver.ubuntu.com', - $filter = '', - $release = $::lsbdistcodename, - $architectures = [], - $repos = [], - $with_sources = false, - $with_udebs = false, - $filter_with_deps = false, - $environment = [], + String $location, + Hash $key = {}, + String $keyring = '/etc/apt/trusted.gpg', + String $filter = '', + String $release = $::lsbdistcodename, + Array $architectures = [], + Array $repos = [], + Boolean $with_sources = false, + Boolean $with_udebs = false, + Boolean $filter_with_deps = false, + Array $environment = [], ) { - validate_string($keyserver) - validate_string($filter) - validate_array($repos) - validate_array($architectures) - validate_bool($filter_with_deps) - validate_bool($with_sources) - validate_bool($with_udebs) - validate_array($environment) - include ::aptly - $gpg_cmd = '/usr/bin/gpg --no-default-keyring --keyring trustedkeys.gpg' + $gpg_cmd = "/usr/bin/gpg --no-default-keyring --keyring ${keyring}" $aptly_cmd = "${::aptly::aptly_cmd} mirror" if empty($architectures) { @@ -110,18 +101,25 @@ $filter_with_deps_arg = '' } - if $key { - if is_array($key) { - $key_string = join($key, "' '") - } elsif is_string($key) or is_integer($key) { - $key_string = $key + if is_hash($key) and $key[id] and $key[server] { + + if is_array($key[id]) { + $key_string = join($key[id], "' '") + } elsif is_string($key[id]) or is_integer($key[id]) { + $key_string = $key[id] } else { fail('$key is neither a string nor an array!') } + if $key[server] { + $key_server = $key[server] + }else{ + $key_server = $::aptly::key_server + } + exec { "aptly_mirror_gpg-${title}": path => '/bin:/usr/bin', - command => "${gpg_cmd} --keyserver '${keyserver}' --recv-keys '${key_string}'", + command => "${gpg_cmd} --keyserver '${key_server}' --recv-keys '${key_string}'", unless => "echo '${key_string}' | xargs -n1 ${gpg_cmd} --list-keys", user => $::aptly::user, } diff --git a/manifests/repo.pp b/manifests/repo.pp index 9511257..692727e 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -21,16 +21,11 @@ # Specify the default distribution to be used when publishing this repository. define aptly::repo( - $architectures = [], - $comment = '', - $component = '', - $distribution = '', + Array $architectures = [], + String $comment = '', + String $component = '', + String $distribution = '', ){ - validate_array($architectures) - validate_string($comment) - validate_string($component) - validate_string($distribution) - include ::aptly $aptly_cmd = "${::aptly::aptly_cmd} repo" diff --git a/metadata.json b/metadata.json index 40de6cc..af6817c 100644 --- a/metadata.json +++ b/metadata.json @@ -2,21 +2,42 @@ "name": "gdsoperations-aptly", "version": "0.9.1", "author": "Government Digital Service", - "license": "MIT", "summary": "Module to manage aptly", - "source": "https://github.com/gds-operations/puppet-aptly", + "license": "MIT", + "source": "https://github.com/gds-operations/puppet-aptly", "project_page": "https://github.com/gds-operations/puppet-aptly", - "issues_url": "https://github.com/gds-operations/puppet-aptly/issues", - "tags": ["apt", "aptly"], + "issues_url": "https://github.com/gds-operations/puppet-aptly/issues", + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">=4.0.0 <5.0.0" + }, + { + "name": "puppetlabs/apt", + "version_requirement": ">=4.0.0 <5.0.0" + } + ], "operatingsystem_support": [ { "operatingsystem": "Ubuntu", - "operatingsystemrelease": ["12.04", "14.04", "16.04"] + "operatingsystemrelease": [ + "12.04", + "14.04", + "16.04" + ] } - ], - "dependencies": [ - {"name": "puppetlabs/stdlib", "version_requirement": ">=3.0.0 <4.25.2"}, - {"name": "puppetlabs/apt", "version_requirement": ">=2.0.0 <4.5.2"} ], - "project_page": "https://github.com/gds-operations/puppet-aptly" + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.7.0 < 7.0.0" + } + ], + "tags": [ + "apt", + "aptly" + ], + "pdk-version": "1.7.1", + "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", + "template-ref": "1.7.1-0-g810b982" } diff --git a/spec/classes/api_spec.rb b/spec/classes/api_spec.rb index 6c3263f..3df3611 100644 --- a/spec/classes/api_spec.rb +++ b/spec/classes/api_spec.rb @@ -1,11 +1,37 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'aptly::api' do context 'Using Systemd' do let(:facts) do { - :operatingsystem => 'Debian', - :operatingsystemrelease => '8.7', + operatingsystem: 'Debian', + operatingsystemrelease: '8.7', + os: { + architecture: 'amd64', + distro: { + codename: 'stretch', + description: 'Debian GNU/Linux 9.4 (stretch)', + id: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + } + }, + family: 'Debian', + hardware: 'x86_64', + name: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + }, + selinux: { + enabled: false + } + } } end @@ -13,128 +39,150 @@ let(:params) { {} } it do - should contain_file('aptly-systemd') - .with_path('/etc/systemd/system/aptly-api.service') - .without_content(/^\s*author /) - .with_content(/^User=root$/) - .with_content(/^Group=root$/) - .with_content(/^ExecStart=\/usr\/bin\/aptly api serve -listen=:8080$/) - .that_notifies('Service[aptly-api]') + is_expected.to contain_file('aptly-systemd') + .with_path('/etc/systemd/system/aptly-api.service') + .without_content(%r{^\s*author }) + .with_content(%r{^User=root$}) + .with_content(%r{^Group=root$}) + .with_content(%r{^ExecStart=\/usr\/bin\/aptly api serve -listen=:8080$}) + .that_notifies('Service[aptly-api]') end it do - should contain_service('aptly-api') - .with_ensure('running') - .with_enable(true) + is_expected.to contain_service('aptly-api') + .with_ensure('running') + .with_enable(true) end end describe 'ensure' do context 'present (default)' do - let(:params) {{ }} + let(:params) { {} } - it { should contain_service('aptly-api').with_ensure('running') } + it { is_expected.to contain_service('aptly-api').with_ensure('running') } end context 'stopped' do - let(:params) {{ - :ensure => 'stopped' - }} + let(:params) do + { + ensure: 'stopped' + } + end - it { should contain_service('aptly-api').with_ensure('stopped') } + it { is_expected.to contain_service('aptly-api').with_ensure('stopped') } end context 'invalid value' do - let(:params) {{ - :ensure => 'yolo' - }} + let(:params) do + { + ensure: 'yolo' + } + end - it { should raise_error(Puppet::Error, /Valid values for \$ensure: stopped, running/) } + it { is_expected.to raise_error(Puppet::Error, %r{Valid values for \$ensure: stopped, running}) } end end describe 'user' do context 'custom' do - let(:params) {{ - :user => 'yolo' - }} + let(:params) do + { + user: 'yolo' + } + end - it { should contain_file('aptly-systemd').with_content(/^User=yolo$/) } + it { is_expected.to contain_file('aptly-systemd').with_content(%r{^User=yolo$}) } end context 'not a string' do - let(:params) {{ - :user => false - }} + let(:params) do + { + user: false + } + end - it { should raise_error(Puppet::Error, /is not a string/) } + it { is_expected.to raise_error(Puppet::Error, %r{is not a string}) } end end describe 'group' do context 'custom' do - let(:params) {{ - :group => 'yolo' - }} + let(:params) do + { + group: 'yolo' + } + end - it { should contain_file('aptly-systemd').with_content(/^Group=yolo$/) } + it { is_expected.to contain_file('aptly-systemd').with_content(%r{^Group=yolo$}) } end context 'not a string' do - let(:params) {{ - :group => false - }} + let(:params) do + { + group: false + } + end - it { should raise_error(Puppet::Error, /is not a string/) } + it { is_expected.to raise_error(Puppet::Error, %r{is not a string}) } end end describe 'listen' do context 'custom' do - let(:params) {{ - :listen => '127.0.0.1:9090' - }} + let(:params) do + { + listen: '127.0.0.1:9090' + } + end - it { should contain_file('aptly-systemd').with_content(/^ExecStart=\/usr\/bin\/aptly api serve -listen=127.0.0.1:9090$/) } + it { is_expected.to contain_file('aptly-systemd').with_content(%r{^ExecStart=\/usr\/bin\/aptly api serve -listen=127.0.0.1:9090$}) } end context 'not a string' do - let(:params) {{ - :listen => false - }} + let(:params) do + { + listen: false + } + end - it { should raise_error(Puppet::Error, /input needs to be a String/) } + it { is_expected.to raise_error(Puppet::Error, %r{input needs to be a String}) } end context 'invalid format' do - let(:params) {{ - :listen => 'yolo' - }} + let(:params) do + { + listen: 'yolo' + } + end - it { should raise_error(Puppet::Error, /Valid values for \$listen: :port, :/) } + it { is_expected.to raise_error(Puppet::Error, %r{Valid values for \$listen: :port, :}) } end end describe 'log' do context 'invalid value' do - let(:params) {{ - :log => 'yolo' - }} + let(:params) do + { + log: 'yolo' + } + end - it { should raise_error(Puppet::Error, /Valid values for \$log: none, log/) } + it { is_expected.to raise_error(Puppet::Error, %r{Valid values for \$log: none, log}) } end end describe 'enable_cli_and_http' do context 'false (default)' do - it { should contain_file('aptly-systemd').without_content(/ -no-lock/) } + it { is_expected.to contain_file('aptly-systemd').without_content(%r{ -no-lock}) } end context 'true' do - let(:params) {{ - :enable_cli_and_http => true - }} + let(:params) do + { + enable_cli_and_http: true + } + end - it { should contain_file('aptly-systemd').with_content(/ -no-lock/) } + it { is_expected.to contain_file('aptly-systemd').with_content(%r{ -no-lock}) } end end end @@ -142,152 +190,182 @@ context 'Using Upstart' do let(:facts) do { - :operatingsystem => 'Ubuntu', - :operatingsystemrelease => '15.03', + operatingsystem: 'Ubuntu', + operatingsystemrelease: '15.03', + os: { + name: 'Ubuntu', + release: { + full: '15.03' + } + } } end context 'param defaults' do - let(:params) {{ }} + let(:params) { {} } it do - should contain_file('aptly-upstart') - .with_path('/etc/init/aptly-api.conf') - .without_content(/^\s*author /) - .with_content(/^setuid root$/) - .with_content(/^setgid root$/) - .with_content(/^exec \/usr\/bin\/aptly api serve -listen=:8080$/) - .that_notifies('Service[aptly-api]') + is_expected.to contain_file('aptly-upstart') + .with_path('/etc/init/aptly-api.conf') + .without_content(%r{^\s*author }) + .with_content(%r{^setuid root$}) + .with_content(%r{^setgid root$}) + .with_content(%r{^exec \/usr\/bin\/aptly api serve -listen=:8080$}) + .that_notifies('Service[aptly-api]') end it do - should contain_service('aptly-api') - .with_ensure('running') - .with_enable(true) + is_expected.to contain_service('aptly-api') + .with_ensure('running') + .with_enable(true) end end describe 'ensure' do context 'present (default)' do - let(:params) {{ }} + let(:params) { {} } - it { should contain_service('aptly-api').with_ensure('running') } + it { is_expected.to contain_service('aptly-api').with_ensure('running') } end context 'stopped' do - let(:params) {{ - :ensure => 'stopped' - }} + let(:params) do + { + ensure: 'stopped' + } + end - it { should contain_service('aptly-api').with_ensure('stopped') } + it { is_expected.to contain_service('aptly-api').with_ensure('stopped') } end context 'invalid value' do - let(:params) {{ - :ensure => 'yolo' - }} + let(:params) do + { + ensure: 'yolo' + } + end - it { should raise_error(Puppet::Error, /Valid values for \$ensure: stopped, running/) } + it { is_expected.to raise_error(Puppet::Error, %r{Valid values for \$ensure: stopped, running}) } end end describe 'user' do context 'custom' do - let(:params) {{ - :user => 'yolo' - }} + let(:params) do + { + user: 'yolo' + } + end - it { should contain_file('aptly-upstart').with_content(/^setuid yolo$/) } + it { is_expected.to contain_file('aptly-upstart').with_content(%r{^setuid yolo$}) } end context 'not a string' do - let(:params) {{ - :user => false - }} + let(:params) do + { + user: false + } + end - it { should raise_error(Puppet::Error, /is not a string/) } + it { is_expected.to raise_error(Puppet::Error, %r{is not a string}) } end end describe 'group' do context 'custom' do - let(:params) {{ - :group => 'yolo' - }} + let(:params) do + { + group: 'yolo' + } + end - it { should contain_file('aptly-upstart').with_content(/^setgid yolo$/) } + it { is_expected.to contain_file('aptly-upstart').with_content(%r{^setgid yolo$}) } end context 'not a string' do - let(:params) {{ - :group => false - }} + let(:params) do + { + group: false + } + end - it { should raise_error(Puppet::Error, /is not a string/) } + it { is_expected.to raise_error(Puppet::Error, %r{is not a string}) } end end describe 'listen' do context 'custom' do - let(:params) {{ - :listen => '127.0.0.1:9090' - }} + let(:params) do + { + listen: '127.0.0.1:9090' + } + end - it { should contain_file('aptly-upstart').with_content(/^exec \/usr\/bin\/aptly api serve -listen=127.0.0.1:9090$/) } + it { is_expected.to contain_file('aptly-upstart').with_content(%r{^exec \/usr\/bin\/aptly api serve -listen=127.0.0.1:9090$}) } end context 'not a string' do - let(:params) {{ - :listen => false - }} + let(:params) do + { + listen: false + } + end - it { should raise_error(Puppet::Error, /input needs to be a String/) } + it { is_expected.to raise_error(Puppet::Error, %r{input needs to be a String}) } end context 'invalid format' do - let(:params) {{ - :listen => 'yolo' - }} + let(:params) do + { + listen: 'yolo' + } + end - it { should raise_error(Puppet::Error, /Valid values for \$listen: :port, :/) } + it { is_expected.to raise_error(Puppet::Error, %r{Valid values for \$listen: :port, :}) } end end describe 'log' do context 'none (default)' do - let(:params) {{ }} + let(:params) { {} } - it { should contain_file('aptly-upstart').with_content(/^console none$/) } + it { is_expected.to contain_file('aptly-upstart').with_content(%r{^console none$}) } end context 'log' do - let(:params) {{ - :log => 'log' - }} + let(:params) do + { + log: 'log' + } + end - it { should contain_file('aptly-upstart').with_content(/^console log$/) } + it { is_expected.to contain_file('aptly-upstart').with_content(%r{^console log$}) } end context 'invalid value' do - let(:params) {{ - :log => 'yolo' - }} + let(:params) do + { + log: 'yolo' + } + end - it { should raise_error(Puppet::Error, /Valid values for \$log: none, log/) } + it { is_expected.to raise_error(Puppet::Error, %r{Valid values for \$log: none, log}) } end end describe 'enable_cli_and_http' do context 'false (default)' do - it { should contain_file('aptly-upstart').without_content(/ -no-lock/) } + it { is_expected.to contain_file('aptly-upstart').without_content(%r{ -no-lock}) } end context 'true' do - let(:params) {{ - :enable_cli_and_http => true - }} + let(:params) do + { + enable_cli_and_http: true + } + end - it { should contain_file('aptly-upstart').with_content(/ -no-lock/) } + it { is_expected.to contain_file('aptly-upstart').with_content(%r{ -no-lock}) } end end end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index c44365e..07a172d 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,46 +1,78 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'aptly' do - let(:facts) {{ - :lsbdistid => 'Debian', - :osfamily => 'Debian', - }} + let(:facts) do + { + lsbdistid: 'Debian', + osfamily: 'Debian', + os: { + architecture: 'amd64', + distro: { + codename: 'stretch', + description: 'Debian GNU/Linux 9.4 (stretch)', + id: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + } + }, + family: 'Debian', + hardware: 'x86_64', + name: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + }, + selinux: { + enabled: false + } + } + } + end context 'param defaults' do - let(:params) {{ }} + let(:params) { {} } - it { should contain_apt__source('aptly') } - it { should contain_package('aptly').that_requires('Class[Apt::Update]') } - it { should contain_file('/etc/aptly.conf').with_content("{}\n") } + it { is_expected.to contain_apt__source('aptly') } + it { is_expected.to contain_package('aptly').that_requires('Class[Apt::Update]') } + it { is_expected.to contain_file('/etc/aptly.conf').with_content("{}\n") } end describe '#package_ensure' do context 'present (default)' do - let(:params) {{ }} + let(:params) { {} } - it { should contain_package('aptly').with_ensure('present') } + it { is_expected.to contain_package('aptly').with_ensure('present') } end context '1.2.3' do - let(:params) {{ - :package_ensure => '1.2.3', - }} + let(:params) do + { + package_ensure: '1.2.3' + } + end - it { should contain_package('aptly').with_ensure('1.2.3') } + it { is_expected.to contain_package('aptly').with_ensure('1.2.3') } end end describe '#key_server (with #repo default to true)' do context 'custom key_server' do - let(:params) {{ - :key_server => 'somekeyserver.com', - }} - - it "should override apt::source (somekeyserver.com)" do - should contain_apt__source('aptly').with( - :key => { - 'server' => 'somekeyserver.com', - 'id' => '26DA9D8630302E0B86A7A2CBED75B5A4483DA07C' + let(:params) do + { + key_server: 'keyserver.ubuntu.com' + } + end + + it 'overrides apt::source (somekeyserver.com)' do + is_expected.to contain_apt__source('aptly').with( + key: { + 'server' => 'keyserver.ubuntu.com', + 'id' => 'DF32BC15E2145B3FA151AED19E3E53F19C7DE460' }, ) end @@ -49,92 +81,109 @@ describe '#config_file' do context 'not an absolute path' do - let(:params) {{ - :config_file => 'relativepath/aptly.conf', - }} + let(:params) do + { + config_file: 'relativepath/aptly.conf' + } + end it { - should raise_error(Puppet::Error, /is not an absolute path/) + is_expected.to raise_error(Puppet::PreformattedError, %r{parameter 'config_file' expects a .*Stdlib::{Absolute|Windows|Unix}path}) } end context 'custom config path' do - let(:params) {{ - :config_file => '/etc/aptly/aptly.conf', - }} + let(:params) do + { + config_file: '/etc/aptly/aptly.conf' + } + end it { - should contain_file('/etc/aptly/aptly.conf') + is_expected.to contain_file('/etc/aptly/aptly.conf') } end end describe '#config' do context 'not a hash' do - let(:params) {{ - :config => 'this is a string', - }} + let(:params) do + { + config: 'this is a string' + } + end it { - should raise_error(Puppet::Error, /is not a Hash/) + is_expected.to raise_error(Puppet::PreformattedError, %r{parameter 'config' expects a Hash value, got String}) } end context 'rootDir and architectures' do - let(:params) {{ - :config => { - 'rootDir' => '/srv/aptly', - 'architectures' => ['i386', 'amd64'], - }, - }} + let(:params) do + { + config: { + 'rootDir' => '/srv/aptly', + 'architectures' => ['i386', 'amd64'] + } + } + end it { - should contain_file('/etc/aptly.conf').with_content(< { 'a' => 1 } - }} + let(:params) do + { + config_contents: { 'a' => 1 } + } + end + it { - should raise_error(Puppet::Error, /is not a string/) + is_expected.to raise_error(Puppet::PreformattedError, %r{parameter 'config_contents' expects a value of type Undef or String, got Struct}) } end context 'rootDir and architectures' do - let(:params) {{ - :config_contents => '{"rootDir":"/srv/aptly", "architectures":["i386", "amd64"]}' - }} + let(:params) do + { + config_contents: '{"rootDir":"/srv/aptly", "architectures":["i386", "amd64"]}' + } + end it { - should contain_file('/etc/aptly.conf').with_content(params[:config_contents]) + is_expected.to contain_file('/etc/aptly.conf').with_content(params[:config_contents]) } end end describe '#repo' do context 'not a bool' do - let(:params) {{ - :repo => 'this is a string', - }} + let(:params) do + { + repo: 'this is a string' + } + end it { - should raise_error(Puppet::Error, /is not a boolean/) + is_expected.to raise_error(Puppet::PreformattedError, %r{parameter 'repo' expects a Boolean value, got String}) } end context 'false' do - let(:params) {{ - :repo => false, - }} + let(:params) do + { + repo: false + } + end - it { should_not contain_apt__source('aptly') } + it { is_expected.not_to contain_apt__source('aptly') } end end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..e10d991 --- /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: "" +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/mirror_spec.rb b/spec/defines/mirror_spec.rb index 1b58a66..df6bd61 100644 --- a/spec/defines/mirror_spec.rb +++ b/spec/defines/mirror_spec.rb @@ -1,242 +1,295 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'aptly::mirror' do let(:title) { 'example' } - let(:facts) {{ - :lsbdistid => 'Debian', - :lsbdistcodename => 'precise', - :osfamily => 'Debian', - }} + let(:facts) do + { + lsbdistid: 'Debian', + lsbdistcodename: 'precise', + osfamily: 'Debian', + os: { + name: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + } + } + } + end describe 'param defaults and mandatory' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + } + } + end it { - should contain_exec('aptly_mirror_gpg-example').with({ - :command => / --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$/, - :unless => /^echo 'ABC123' |/, - :user => 'root', - }) + is_expected.to contain_exec('aptly_mirror_gpg-example').with(command: %r{ --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$}, + unless: %r{^echo 'ABC123' |}, + user: 'root') } it { - should contain_exec('aptly_mirror_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise$/, - :unless => /aptly -config \/etc\/aptly.conf mirror show example >\/dev\/null$/, - :user => 'root', - :require => [ - 'Package[aptly]', - 'File[/etc/aptly.conf]', - 'Exec[aptly_mirror_gpg-example]' - ], - }) + is_expected.to contain_exec('aptly_mirror_create-example').with(command: %r{aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise$}, + unless: %r{aptly -config \/etc\/aptly.conf mirror show example >\/dev\/null$}, + user: 'root', + require: [ + 'Package[aptly]', + 'File[/etc/aptly.conf]', + 'Exec[aptly_mirror_gpg-example]' + ]) } context 'two repos with same key' do - let(:pre_condition) { <<-EOS + let(:pre_condition) do + <<-EOS aptly::mirror { 'example-lucid': location => 'http://lucid.example.com/', - key => 'ABC123', + key => {id: 'ABC123', server: 'keyserver.ubuntu.com'} } EOS - } + end - it { should contain_exec('aptly_mirror_gpg-example-lucid') } + it { is_expected.to contain_exec('aptly_mirror_gpg-example-lucid') } end end describe '#user' do context 'with custom user' do - let(:pre_condition) { <<-EOS + let(:pre_condition) do + <<-EOS class { 'aptly': user => 'custom_user', } EOS - } + end - let(:params){{ - :location => 'http://repo.example.com', - :key => 'ABC123', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + } + } + end it { - should contain_exec('aptly_mirror_gpg-example').with({ - :command => / --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$/, - :unless => /^echo 'ABC123' |/, - :user => 'custom_user', - }) + is_expected.to contain_exec('aptly_mirror_gpg-example').with(command: %r{ --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$}, + unless: %r{^echo 'ABC123' |}, + user: 'custom_user') } it { - should contain_exec('aptly_mirror_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise$/, - :unless => /aptly -config \/etc\/aptly.conf mirror show example >\/dev\/null$/, - :user => 'custom_user', - :require => [ - 'Package[aptly]', - 'File[/etc/aptly.conf]', - 'Exec[aptly_mirror_gpg-example]' - ], - }) + is_expected.to contain_exec('aptly_mirror_create-example').with(command: %r{aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise$}, + unless: %r{aptly -config \/etc\/aptly.conf mirror show example >\/dev\/null$}, + user: 'custom_user', + require: [ + 'Package[aptly]', + 'File[/etc/aptly.conf]', + 'Exec[aptly_mirror_gpg-example]' + ]) } end end describe '#keyserver' do context 'with custom keyserver' do - let(:params){{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :keyserver => 'hkp://repo.keyserver.com:80', - }} - - it{ - should contain_exec('aptly_mirror_gpg-example').with({ - :command => / --keyserver 'hkp:\/\/repo.keyserver.com:80' --recv-keys 'ABC123'$/, - :unless => /^echo 'ABC123' |/, - :user => 'root', - }) + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + } + } + end + + it { + is_expected.to contain_exec('aptly_mirror_gpg-example').with(command: %r{ --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$}, + unless: %r{^echo 'ABC123' |}, + user: 'root') } end end describe '#environment' do context 'not an array' do - let(:params){{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :environment => 'FOO=bar', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + environment: 'FOO=bar' + } + end it { - should raise_error(Puppet::Error, /is not an Array/) + is_expected.to raise_error(Puppet::Error, %r{expects an Array value}) } end context 'defaults to empty array' do - let(:params){{ - :location => 'http://repo.example.com', - :key => 'ABC123', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + } + } + end it { - should contain_exec('aptly_mirror_create-example').with({ - :environment => [], - }) + is_expected.to contain_exec('aptly_mirror_create-example').with(environment: []) } end context 'with FOO set to bar' do - let(:params){{ - :location => 'http://repo.example.com', - :key => [ 'ABC123' ], - :environment => ['FOO=bar'], - }} - - it{ - should contain_exec('aptly_mirror_create-example').with({ - :environment => ['FOO=bar'], - }) + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + environment: ['FOO=bar'] + } + end + + it { + is_expected.to contain_exec('aptly_mirror_create-example').with(environment: ['FOO=bar']) } end end describe '#key' do context 'single item not in an array' do - let(:params){{ - :location => 'http://repo.example.com', - :key => 'ABC123', - }} - - it{ - should contain_exec('aptly_mirror_gpg-example').with({ - :command => / --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$/, - :unless => /^echo 'ABC123' |/, - }) + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + } + } + end + + it { + is_expected.to contain_exec('aptly_mirror_gpg-example').with(command: %r{ --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$}, + unless: %r{^echo 'ABC123' |}) } end context 'single item in an array' do - let(:params){{ - :location => 'http://repo.example.com', - :key => [ 'ABC123' ], - }} - - it{ - should contain_exec('aptly_mirror_gpg-example').with({ - :command => / --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$/, - :unless => /^echo 'ABC123' |/, - }) + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + } + } + end + + it { + is_expected.to contain_exec('aptly_mirror_gpg-example').with(command: %r{ --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123'$}, + unless: %r{^echo 'ABC123' |}) } end context 'multiple items' do - let(:params){{ - :location => 'http://repo.example.com', - :key => [ 'ABC123', 'DEF456', 'GHI789' ], - }} - - it{ - should contain_exec('aptly_mirror_gpg-example').with({ - :command => / --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123' 'DEF456' 'GHI789'$/, - :unless => /^echo 'ABC123' 'DEF456' 'GHI789' |/, - }) + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: ['ABC123', 'DEF456', 'GHI789'], + server: 'keyserver.ubuntu.com' + } + } + end + + it { + is_expected.to contain_exec('aptly_mirror_gpg-example').with(command: %r{ --keyserver 'keyserver.ubuntu.com' --recv-keys 'ABC123' 'DEF456' 'GHI789'$}, + unless: %r{^echo 'ABC123' 'DEF456' 'GHI789' |}) } end context 'no key passed' do - let(:params) { + let(:params) do { - :location => 'http://repo.example.com', + location: 'http://repo.example.com' } - } + end it { - should_not contain_exec('aptly_mirror_gpg-example') + is_expected.not_to contain_exec('aptly_mirror_gpg-example') } end end describe '#repos' do context 'not an array' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :repos => 'this is a string', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + repos: 'this is a string' + } + end it { - should raise_error(Puppet::Error, /is not an Array/) + is_expected.to raise_error(Puppet::Error, %r{expects an Array value}) } end context 'single item' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :repos => ['main'], - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + repos: ['main'] + } + end it { - should contain_exec('aptly_mirror_create-example').with_command( - /aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise main$/ + is_expected.to contain_exec('aptly_mirror_create-example').with_command( + %r{aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise main}, ) } end context 'multiple items' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :repos => ['main', 'contrib', 'non-free'], - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + repos: ['main', 'contrib', 'non-free'] + } + end it { - should contain_exec('aptly_mirror_create-example').with_command( - /aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise main contrib non-free$/ + is_expected.to contain_exec('aptly_mirror_create-example').with_command( + %r{aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise main contrib non-free}, ) } end @@ -244,41 +297,56 @@ class { 'aptly': describe '#architectures' do context 'not an array' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :architectures => 'this is a string', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + architectures: 'this is a string' + } + end it { - should raise_error(Puppet::Error, /is not an Array/) + is_expected.to raise_error(Puppet::Error, %r{expects an Array value}) } end context 'single item' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :architectures => ['amd64'], - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + architectures: ['amd64'] + } + end it { - should contain_exec('aptly_mirror_create-example').with_command( - /aptly -config \/etc\/aptly.conf mirror create -architectures="amd64" -with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise$/ - ) + is_expected.to contain_exec('aptly_mirror_create-example').with_command( + %r{aptly -config \/etc\/aptly.conf mirror create -architectures="amd64" -with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise}, + ) } end context 'multiple items' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :architectures => ['i386', 'amd64','armhf'], - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + architectures: ['i386', 'amd64', 'armhf'] + } + end it { - should contain_exec('aptly_mirror_create-example').with_command( - /aptly -config \/etc\/aptly.conf mirror create -architectures="i386,amd64,armhf" -with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise$/ + is_expected.to contain_exec('aptly_mirror_create-example').with_command( + %r{aptly -config \/etc\/aptly.conf mirror create -architectures="i386,amd64,armhf" -with-sources=false -with-udebs=false example http:\/\/repo\.example\.com precise}, ) } end @@ -286,27 +354,37 @@ class { 'aptly': describe '#with_sources' do context 'not a boolean' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :with_sources => 'this is a string', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + with_sources: 'this is a string' + } + end it { - should raise_error(Puppet::Error, /is not a boolean/) + is_expected.to raise_error(Puppet::Error, %r{expects a Boolean value}) } end context 'with boolean true' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :with_sources => true, - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + with_sources: true + } + end it { - should contain_exec('aptly_mirror_create-example').with_command( - /aptly -config \/etc\/aptly.conf mirror create *-with-sources=true -with-udebs=false example http:\/\/repo\.example\.com precise$/ + is_expected.to contain_exec('aptly_mirror_create-example').with_command( + %r{aptly -config \/etc\/aptly.conf mirror create *-with-sources=true -with-udebs=false example http:\/\/repo\.example\.com precise}, ) } end @@ -314,55 +392,73 @@ class { 'aptly': describe '#with_udebs' do context 'not a boolean' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :with_udebs => 'this is a string', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + with_udebs: 'this is a string' + } + end it { - should raise_error(Puppet::Error, /is not a boolean/) + is_expected.to raise_error(Puppet::Error, %r{expects a Boolean value}) } end context 'with boolean true' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :with_udebs => true, - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + with_udebs: true + } + end it { - should contain_exec('aptly_mirror_create-example').with_command( - /aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=true example http:\/\/repo\.example\.com precise$/ - ) + is_expected.to contain_exec('aptly_mirror_create-example').with_command(%r{aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=true example http:\/\/repo\.example\.com precise}) } end end describe '#filter_with_deps' do context 'not a boolean' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :filter_with_deps => 'this is a string', - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + filter_with_deps: 'this is a string' + } + end it { - should raise_error(Puppet::Error, /is not a boolean/) + is_expected.to raise_error(Puppet::Error, %r{expects a Boolean value}) } end context 'with boolean true' do - let(:params) {{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :filter_with_deps => true, - }} + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + filter_with_deps: true + } + end it { - should contain_exec('aptly_mirror_create-example').with_command( - /aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false -filter-with-deps example http:\/\/repo\.example\.com precise$/ + is_expected.to contain_exec('aptly_mirror_create-example').with_command( + %r{aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false -filter-with-deps example http:\/\/repo\.example\.com precise}, ) } end @@ -370,18 +466,22 @@ class { 'aptly': describe '#filter' do context 'with filter' do - let(:params){{ - :location => 'http://repo.example.com', - :key => 'ABC123', - :filter => 'this is a string', - }} - + let(:params) do + { + location: 'http://repo.example.com', + key: { + id: 'ABC123', + server: 'keyserver.ubuntu.com' + }, + filter: 'this is a string' + } + end + it { - should contain_exec('aptly_mirror_create-example').with_command( - /aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false -filter="this is a string" example http:\/\/repo\.example\.com precise$/ + is_expected.to contain_exec('aptly_mirror_create-example').with_command( + %r{aptly -config \/etc\/aptly.conf mirror create *-with-sources=false -with-udebs=false -filter="this is a string" example http:\/\/repo\.example\.com precise}, ) } end end - end diff --git a/spec/defines/repo_spec.rb b/spec/defines/repo_spec.rb index 4f45205..bee3493 100644 --- a/spec/defines/repo_spec.rb +++ b/spec/defines/repo_spec.rb @@ -1,116 +1,144 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'aptly::repo' do let(:title) { 'example' } - let(:facts){{ - :lsbdistid => 'ubuntu', - :osfamily => 'Debian', - }} + let(:facts) do + { + lsbdistid: 'ubuntu', + osfamily: 'Debian', + os: { + architecture: 'amd64', + distro: { + codename: 'stretch', + description: 'Debian GNU/Linux 9.4 (stretch)', + id: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + } + }, + family: 'Debian', + hardware: 'x86_64', + name: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + }, + selinux: { + enabled: false + } + } + } + end describe 'param defaults' do it { - should contain_exec('aptly_repo_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf repo create *example$/, - :unless => /aptly -config \/etc\/aptly.conf repo show example >\/dev\/null$/, - :user => 'root', - :require => [ 'Package[aptly]','File[/etc/aptly.conf]' ], - }) + is_expected.to contain_exec('aptly_repo_create-example').with(command: %r{aptly -config \/etc\/aptly.conf repo create *example}, + unless: %r{aptly -config \/etc\/aptly.conf repo show example >\/dev\/null}, + user: 'root', + require: ['Package[aptly]', 'File[/etc/aptly.conf]']) } end describe 'user defined component' do - let(:params){{ - :component => 'third-party', - }} + let(:params) do + { + component: 'third-party' + } + end it { - should contain_exec('aptly_repo_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf repo create *-component="third-party" *example$/, - :unless => /aptly -config \/etc\/aptly.conf repo show example >\/dev\/null$/, - :user => 'root', - :require => [ 'Package[aptly]','File[/etc/aptly.conf]' ], - }) + is_expected.to contain_exec('aptly_repo_create-example').with(command: %r{aptly -config \/etc\/aptly.conf repo create *-component="third-party" *example}, + unless: %r{aptly -config \/etc\/aptly.conf repo show example >\/dev\/null}, + user: 'root', + require: ['Package[aptly]', 'File[/etc/aptly.conf]']) } context 'custom user' do - let(:pre_condition) { <<-EOS + let(:pre_condition) do + <<-EOS class { 'aptly': user => 'custom_user', } EOS - } + end - let(:params){{ - :component => 'third-party', - }} + let(:params) do + { + component: 'third-party' + } + end it { - should contain_exec('aptly_repo_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf repo create *-component="third-party" *example$/, - :unless => /aptly -config \/etc\/aptly.conf repo show example >\/dev\/null$/, - :user => 'custom_user', - :require => [ 'Package[aptly]','File[/etc/aptly.conf]' ], - }) + is_expected.to contain_exec('aptly_repo_create-example').with(command: %r{aptly -config \/etc\/aptly.conf repo create *-component="third-party" *example}, + unless: %r{aptly -config \/etc\/aptly.conf repo show example >\/dev\/null}, + user: 'custom_user', + require: ['Package[aptly]', 'File[/etc/aptly.conf]']) } end end describe 'user defined architectures' do context 'passing valid values' do - let(:params){{ - :architectures => ['i386','amd64'], - }} + let(:params) do + { + architectures: ['i386', 'amd64'] + } + end it { - should contain_exec('aptly_repo_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf repo create *-architectures="i386,amd64" *example$/, - :unless => /aptly -config \/etc\/aptly.conf repo show example >\/dev\/null$/, - :user => 'root', - :require => [ 'Package[aptly]','File[/etc/aptly.conf]' ], - }) + is_expected.to contain_exec('aptly_repo_create-example').with(command: %r{aptly -config \/etc\/aptly.conf repo create *-architectures="i386,amd64" *example}, + unless: %r{aptly -config \/etc\/aptly.conf repo show example >\/dev\/null}, + user: 'root', + require: ['Package[aptly]', 'File[/etc/aptly.conf]']) } end context 'passing invalid values' do - let(:params){{ - :architectures => 'amd64' - }} + let(:params) do + { + architectures: 'amd64' + } + end it { - should raise_error(Puppet::Error, /is not an Array/) + is_expected.to raise_error(Puppet::PreformattedError, %r{parameter 'architectures' expects an Array value, got String}) } end end describe 'user defined comment' do - let(:params){{ - :comment => 'example comment', - }} + let(:params) do + { + comment: 'example comment' + } + end it { - should contain_exec('aptly_repo_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf repo create *-comment="example comment" *example$/, - :unless => /aptly -config \/etc\/aptly.conf repo show example >\/dev\/null$/, - :user => 'root', - :require => [ 'Package[aptly]','File[/etc/aptly.conf]' ], - }) + is_expected.to contain_exec('aptly_repo_create-example').with(command: %r{aptly -config \/etc\/aptly.conf repo create *-comment="example comment" *example}, + unless: %r{aptly -config \/etc\/aptly.conf repo show example >\/dev\/null}, + user: 'root', + require: ['Package[aptly]', 'File[/etc/aptly.conf]']) } end describe 'user defined distribution' do - let(:params){{ - :distribution => 'example_distribution', - }} + let(:params) do + { + distribution: 'example_distribution' + } + end it { - should contain_exec('aptly_repo_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf repo create *-distribution="example_distribution" *example$/, - :unless => /aptly -config \/etc\/aptly.conf repo show example >\/dev\/null$/, - :user => 'root', - :require => [ 'Package[aptly]','File[/etc/aptly.conf]' ], - }) + is_expected.to contain_exec('aptly_repo_create-example').with(command: %r{aptly -config \/etc\/aptly.conf repo create *-distribution="example_distribution" *example}, + unless: %r{aptly -config \/etc\/aptly.conf repo show example >\/dev\/null}, + user: 'root', + require: ['Package[aptly]', 'File[/etc/aptly.conf]']) } end - end diff --git a/spec/defines/snapshot_spec.rb b/spec/defines/snapshot_spec.rb index 659cbba..e71947a 100644 --- a/spec/defines/snapshot_spec.rb +++ b/spec/defines/snapshot_spec.rb @@ -1,65 +1,92 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'aptly::snapshot' do let(:title) { 'example' } - let(:facts){{ - :lsbdistid => 'ubuntu', - :osfamily => 'Debian', - }} + let(:facts) do + { + lsbdistid: 'ubuntu', + osfamily: 'Debian', + os: { + architecture: 'amd64', + distro: { + codename: 'stretch', + description: 'Debian GNU/Linux 9.4 (stretch)', + id: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + } + }, + family: 'Debian', + hardware: 'x86_64', + name: 'Debian', + release: { + full: '9.4', + major: '9', + minor: '4' + }, + selinux: { + enabled: false + } + } + } + end describe 'param defaults' do it { - should contain_exec('aptly_snapshot_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf snapshot create example empty$/, - :unless => /aptly -config \/etc\/aptly.conf snapshot show example >\/dev\/null$/, - :user => 'root', - :require => 'Class[Aptly]', - }) + is_expected.to contain_exec('aptly_snapshot_create-example').with(command: %r{aptly -config \/etc\/aptly.conf snapshot create example empty}, + unless: %r{aptly -config \/etc\/aptly.conf snapshot show example >\/dev\/null}, + user: 'root', + require: 'Class[Aptly]') } end describe 'user defined params' do context 'passing both params' do - let(:params){{ - :repo => 'example_repo', - :mirror => 'example_mirror', - }} + let(:params) do + { + repo: 'example_repo', + mirror: 'example_mirror' + } + end it { - should raise_error(Puppet::Error, /mutually exclusive/) + is_expected.to raise_error(Puppet::Error, %r{mutually exclusive}) } end context 'passing repo param' do - let(:params){{ - :repo => 'example_repo', - }} + let(:params) do + { + repo: 'example_repo' + } + end it { - should contain_exec('aptly_snapshot_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf snapshot create example from repo example_repo$/, - :unless => /aptly -config \/etc\/aptly.conf snapshot show example >\/dev\/null$/, - :user => 'root', - :require => 'Class[Aptly]', - }) + is_expected.to contain_exec('aptly_snapshot_create-example').with(command: %r{aptly -config \/etc\/aptly.conf snapshot create example from repo example_repo}, + unless: %r{aptly -config \/etc\/aptly.conf snapshot show example >\/dev\/null}, + user: 'root', + require: 'Class[Aptly]') } end context 'passing mirror param' do - let(:params){{ - :mirror => 'example_mirror', - }} + let(:params) do + { + mirror: 'example_mirror' + } + end it { - should contain_exec('aptly_snapshot_create-example').with({ - :command => /aptly -config \/etc\/aptly.conf snapshot create example from mirror example_mirror$/, - :unless => /aptly -config \/etc\/aptly.conf snapshot show example >\/dev\/null$/, - :user => 'root', - :require => 'Class[Aptly]', - }) + is_expected.to contain_exec('aptly_snapshot_create-example').with(command: %r{aptly -config \/etc\/aptly.conf snapshot create example from mirror example_mirror}, + unless: %r{aptly -config \/etc\/aptly.conf snapshot show example >\/dev\/null}, + user: 'root', + require: 'Class[Aptly]') } end - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a72e78e..f5e9148 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,50 @@ -require 'puppetlabs_spec_helper/module_spec_helper' +# 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 'rubygems' + +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 - c.default_facts = { - :operatingsystem => 'Ubuntu', - :operatingsystemrelease => 'trusty', - :osfamily => 'Debian', - :lsbmajdistrelease => 14, - } +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.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 a7a641c..6d6da4a 100644 --- a/spec/spec_helper_system.rb +++ b/spec/spec_helper_system.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rspec-system/spec_helper' require 'rspec-system-puppet/helpers' @@ -10,7 +12,7 @@ c.before :suite do puppet_install - puppet_module_install(:source => proj_root, :module_name => 'aptly') + puppet_module_install(source: proj_root, module_name: 'aptly') shell('puppet module install puppetlabs-stdlib') shell('puppet module install puppetlabs-apt --version 2.2.0') end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb index 62798f6..949bee2 100644 --- a/spec/system/basic_spec.rb +++ b/spec/system/basic_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_system' describe 'basic tests' do @@ -8,15 +10,15 @@ class { 'aptly': } EOS puppet_apply(pp) do |r| - r.exit_code.should == 2 + r.exit_code.should eq 2 r.refresh r.exit_code.should be_zero end end - it 'should have installed aptly' do + it 'has installed aptly' do shell 'aptly version' do |r| - r.stdout.should =~ /^aptly version:/ + r.stdout.should =~ %r{^aptly version:} r.stderr.should be_empty r.exit_code.should be_zero end diff --git a/spec/system/mirror_spec.rb b/spec/system/mirror_spec.rb index 353089f..28272cf 100644 --- a/spec/system/mirror_spec.rb +++ b/spec/system/mirror_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_system' describe 'mirror tests' do @@ -15,18 +17,18 @@ class { 'aptly': } EOS puppet_apply(pp) do |r| - r.exit_code.should == 2 + r.exit_code.should eq 2 r.refresh r.exit_code.should be_zero end end - it 'should have installed aptly' do + it 'has installed aptly' do shell 'aptly mirror show puppetlabs' do |r| - r.stdout.should =~ /^Name: puppetlabs + r.stdout.should =~ %r{^Name: puppetlabs Archive Root URL: http:\/\/apt\.puppetlabs\.com\/ Distribution: precise -Components: main, dependencies$/ +Components: main, dependencies$} r.stderr.should be_empty r.exit_code.should be_zero end