diff --git a/.msync.yml b/.msync.yml index 5cef8c2..5519891 100644 --- a/.msync.yml +++ b/.msync.yml @@ -1 +1 @@ -modulesync_config_version: '2.6.0' +modulesync_config_version: '2.7.0' diff --git a/.travis.yml b/.travis.yml index 9fa0271..4445627 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,71 +1,63 @@ --- dist: xenial language: ruby cache: bundler before_install: - gem update --system - gem update bundler - bundle --version script: - 'bundle exec rake $CHECK' matrix: fast_finish: true include: - rvm: 2.4.4 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 5.0" CHECK=test - rvm: 2.5.3 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls - rvm: 2.5.3 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 6.0" CHECK=rubocop - rvm: 2.4.4 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes - rvm: 2.5.3 bundler_args: --without development release env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker - services: docker - rvm: 2.5.3 bundler_args: --without development release env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker - services: docker branches: only: - master - /^v\d/ notifications: email: false irc: on_success: always on_failure: always channels: - "chat.freenode.org#voxpupuli-notifications" deploy: provider: puppetforge user: puppet password: secure: "C+dXd27/doW1JnKqv+UDHL6/HBI5Te+xGsaoPkqhpO4iXfMxJrTi6sBWaEuyNTeHIwN8wOWHaW9qKEqTuYZ0/k+k3SWFmZpi3jSh79Y8WDoYK7+DsbKQ6xZy54Sh56YIYXfkaLQYYYrqKKksZ57h/NYU/hzu9h8oH+PnXfGT6i/KH9C4z8IR9qTxIiErrJHUMni9CryTTbtGV9pIj0QTZP+OQLoE660J8/uMsfTQDK9/NqQ2nsTaQ12SS9xg6MmmOX7W4NhRrOyIi0sd7eR0dRIoVf0TwfYhw8Yi4aDuTZIHNtcHiyfAVsvh3RpAr5d01GjXEr5lj0XyBOu8t1U3BzPU7LrJRrwE+ZmP72L39vrT7rmDRz9pDU7fVIOiRtqRLEJRDIW4I2ISkwBdzFKX8UTozTkPEmt9Iy+uKX5n2y8re2KFaseXWxTeVJbHh+DsJQ/hWsUNrHcl2dKmtgo7xHSonmevnATVV1vUbwvswm1oEiAFRdhF4gNdC8I6OGlVzmzwMbwqiGUk/nRBQeMEbyeRQV54QV3zteuBiHc8neQPR+QiD7diR2d4JhmDbr6xop+Bat2SVQqLg2IdAJ/Qu1Aor7mxhmPqiz35SWkbaaoDJYbWrCBeQ+jos4s2jCDY7OJEXW8ng9gPO71W/lcybMWzihUw6fA9w/riHe37Ez0=" on: tags: true # all_branches is required to use tags all_branches: true # Only publish the build marked with "DEPLOY_TO_FORGE" condition: "$DEPLOY_TO_FORGE = yes" diff --git a/Gemfile b/Gemfile index 953604c..cdd2077 100644 --- a/Gemfile +++ b/Gemfile @@ -1,83 +1,83 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" def location_for(place, fake_version = nil) if place =~ /^(git[:@][^#]*)#(.*)/ [fake_version, { :git => $1, :branch => $2, :require => false }].compact elsif place =~ /^file:\/\/(.*)/ ['>= 0', { :path => File.expand_path($1), :require => false }] else [place, { :require => false }] end end group :test do - gem 'puppetlabs_spec_helper', '>= 2.11.0', :require => false + gem 'puppetlabs_spec_helper', '>= 2.14.0', :require => false gem 'rspec-puppet-facts', '>= 1.8.0', :require => false gem 'rspec-puppet-utils', :require => false gem 'puppet-lint-leading_zero-check', :require => false gem 'puppet-lint-trailing_comma-check', :require => false gem 'puppet-lint-version_comparison-check', :require => false gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false gem 'puppet-lint-unquoted_string-check', :require => false gem 'puppet-lint-variable_contains_upcase', :require => false gem 'puppet-lint-absolute_classname-check', :require => false gem 'metadata-json-lint', :require => false gem 'redcarpet', :require => false gem 'rubocop', '~> 0.49.1', :require => false gem 'rubocop-rspec', '~> 1.15.0', :require => false gem 'mocha', '~> 1.4.0', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false gem 'parallel_tests', :require => false gem 'toml', :require => false end group :development do gem 'travis', :require => false gem 'travis-lint', :require => false gem 'guard-rake', :require => false gem 'overcommit', '>= 0.39.1', :require => false end group :system_tests do gem 'winrm', :require => false if beaker_version = ENV['BEAKER_VERSION'] gem 'beaker', *location_for(beaker_version) else gem 'beaker', '>= 4.2.0', :require => false end if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] gem 'beaker-rspec', *location_for(beaker_rspec_version) else gem 'beaker-rspec', :require => false end gem 'serverspec', :require => false gem 'beaker-hostgenerator', '>= 1.1.22', :require => false gem 'beaker-docker', :require => false gem 'beaker-puppet', :require => false gem 'beaker-puppet_install_helper', :require => false gem 'beaker-module_install_helper', :require => false gem 'rbnacl', '>= 4', :require => false gem 'rbnacl-libsodium', :require => false gem 'bcrypt_pbkdf', :require => false end group :release do gem 'github_changelog_generator', :require => false, :git => 'https://github.com/github-changelog-generator/github-changelog-generator' gem 'puppet-blacksmith', :require => false gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem' - gem 'puppet-strings', '>= 1.0', :require => false + gem 'puppet-strings', '>= 2.2', :require => false end if facterversion = ENV['FACTER_GEM_VERSION'] gem 'facter', facterversion.to_s, :require => false, :groups => [:test] else gem 'facter', :require => false, :groups => [:test] end ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 6.0' : puppetversion = ENV['PUPPET_VERSION'].to_s gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index a6cf0ac..09701d0 100644 --- a/Rakefile +++ b/Rakefile @@ -1,108 +1,82 @@ require 'puppetlabs_spec_helper/rake_tasks' # load optional tasks for releases # only available if gem group releases is installed begin - require 'puppet_blacksmith/rake_tasks' require 'voxpupuli/release/rake_tasks' - require 'puppet-strings/tasks' rescue LoadError end PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' -PuppetLint.configuration.fail_on_warnings = true PuppetLint.configuration.absolute_classname_reverse = true -PuppetLint.configuration.send('relative') -PuppetLint.configuration.send('disable_140chars') -PuppetLint.configuration.send('disable_class_inherits_from_params_class') -PuppetLint.configuration.send('disable_documentation') -PuppetLint.configuration.send('disable_single_quote_string_with_variables') exclude_paths = %w( pkg/**/* vendor/**/* .vendor/**/* spec/**/* ) PuppetLint.configuration.ignore_paths = exclude_paths PuppetSyntax.exclude_paths = exclude_paths desc 'Auto-correct puppet-lint offenses' task 'lint:auto_correct' do - PuppetLint.configuration.fix = true - Rake::Task[:lint].invoke + Rake::Task[:lint_fix].invoke end desc 'Run acceptance tests' RSpec::Core::RakeTask.new(:acceptance) do |t| t.pattern = 'spec/acceptance' end -desc 'Run tests release_checks' -task test: [ - :release_checks, -] +desc 'Run tests' +task test: [:release_checks] namespace :check do desc 'Check for trailing whitespace' task :trailing_whitespace do Dir.glob('**/*.md', File::FNM_DOTMATCH).sort.each do |filename| next if filename =~ %r{^((modules|acceptance|\.?vendor|spec/fixtures|pkg)/|REFERENCE.md)} File.foreach(filename).each_with_index do |line, index| if line =~ %r{\s\n$} puts "#{filename} has trailing whitespace on line #{index + 1}" exit 1 end end end end end Rake::Task[:release_checks].enhance ['check:trailing_whitespace'] desc "Run main 'test' task and report merged results to coveralls" task test_with_coveralls: [:test] do if Dir.exist?(File.expand_path('../lib', __FILE__)) require 'coveralls/rake/task' Coveralls::RakeTask.new Rake::Task['coveralls:push'].invoke else puts 'Skipping reporting to coveralls. Module has no lib dir' end end -desc "Print supported beaker sets" -task 'beaker_sets', [:directory] do |t, args| - directory = args[:directory] - - metadata = JSON.load(File.read('metadata.json')) - - (metadata['operatingsystem_support'] || []).each do |os| - (os['operatingsystemrelease'] || []).each do |release| - if directory - beaker_set = "#{directory}/#{os['operatingsystem'].downcase}-#{release}" - else - beaker_set = "#{os['operatingsystem'].downcase}-#{release}-x64" - end - - filename = "spec/acceptance/nodesets/#{beaker_set}.yml" - - puts beaker_set if File.exists? filename - end - end +desc 'Generate REFERENCE.md' +task :reference, [:debug, :backtrace] do |t, args| + patterns = '' + Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) end begin require 'github_changelog_generator/task' GitHubChangelogGenerator::RakeTask.new :changelog do |config| version = (Blacksmith::Modulefile.new).version config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/ config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} config.user = 'voxpupuli' metadata_json = File.join(File.dirname(__FILE__), 'metadata.json') metadata = JSON.load(File.read(metadata_json)) config.project = metadata['name'] end rescue LoadError end # vim: syntax=ruby diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2f2279d..c53e703 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,38 +1,42 @@ # This file is managed via modulesync # https://github.com/voxpupuli/modulesync # https://github.com/voxpupuli/modulesync_config +RSpec.configure do |c| + c.mock_with :rspec +end + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' include RspecPuppetFacts if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml'))) if facts facts.each do |name, value| add_custom_fact name.to_sym, value end end end if Dir.exist?(File.expand_path('../../lib', __FILE__)) require 'coveralls' require 'simplecov' require 'simplecov-console' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Console ] SimpleCov.start do track_files 'lib/**/*.rb' add_filter '/spec' add_filter '/vendor' add_filter '/.vendor' end end RSpec.configure do |c| # Coverage generation c.after(:suite) do RSpec::Puppet::Coverage.report! end end diff --git a/spec/unit/puppet/provider/grafana_plugin/grafana_cli_spec.rb b/spec/unit/puppet/provider/grafana_plugin/grafana_cli_spec.rb index e19ea2a..a2a59fb 100644 --- a/spec/unit/puppet/provider/grafana_plugin/grafana_cli_spec.rb +++ b/spec/unit/puppet/provider/grafana_plugin/grafana_cli_spec.rb @@ -1,67 +1,74 @@ require 'spec_helper' provider_class = Puppet::Type.type(:grafana_plugin).provider(:grafana_cli) describe provider_class do let(:resource) do Puppet::Type::Grafana_plugin.new( name: 'grafana-wizzle' ) end let(:provider) { provider_class.new(resource) } describe '#instances' do - # rubocop:disable Layout/TrailingWhitespace - provider_class.expects(:grafana_cli).with('plugins', 'ls').returns <<-EOT + let(:plugins_ls_two) do + # rubocop:disable Layout/TrailingWhitespace + <<-PLUGINS installed plugins: grafana-simple-json-datasource @ 1.3.4 jdbranham-diagram-panel @ 1.4.0 +Restart grafana after installing plugins . + PLUGINS + # rubocop:enable Layout/TrailingWhitespace + end + let(:plugins_ls_none) do + <<-PLUGINS + Restart grafana after installing plugins . -EOT - # rubocop:enable Layout/TrailingWhitespace - instances = provider_class.instances - it 'has the right number of instances' do - expect(instances.size).to eq(2) + PLUGINS end + # rubocop:disable RSpec/MultipleExpectations it 'has the correct names' do - names = instances.map(&:name) - expect(names).to include('grafana-simple-json-datasource', 'jdbranham-diagram-panel') + allow(provider_class).to receive(:grafana_cli).with('plugins', 'ls').and_return(plugins_ls_two) + expect(provider_class.instances.map(&:name)).to match_array(['grafana-simple-json-datasource', 'jdbranham-diagram-panel']) + expect(provider_class).to have_received(:grafana_cli) end it 'does not match if there are no plugins' do - provider_class.expects(:grafana_cli).with('plugins', 'ls').returns <<-EOT - -Restart grafana after installing plugins . - -EOT - instances = provider_class.instances + allow(provider_class).to receive(:grafana_cli).with('plugins', 'ls').and_return(plugins_ls_none) + expect(provider_class.instances.size).to eq(0) expect(provider.exists?).to eq(false) + expect(provider_class).to have_received(:grafana_cli) end + # rubocop:enable RSpec/MultipleExpectations end it '#create' do - provider.expects(:grafana_cli).with('plugins', 'install', 'grafana-wizzle') + allow(provider).to receive(:grafana_cli) provider.create + expect(provider).to have_received(:grafana_cli).with('plugins', 'install', 'grafana-wizzle') end it '#destroy' do - provider.expects(:grafana_cli).with('plugins', 'uninstall', 'grafana-wizzle') + allow(provider).to receive(:grafana_cli) provider.destroy + expect(provider).to have_received(:grafana_cli).with('plugins', 'uninstall', 'grafana-wizzle') end describe 'create with repo' do let(:resource) do Puppet::Type::Grafana_plugin.new( name: 'grafana-plugin', repo: 'https://nexus.company.com/grafana/plugins' ) end it '#create with repo' do - provider.expects(:grafana_cli).with('--repo https://nexus.company.com/grafana/plugins', 'plugins', 'install', 'grafana-plugin') + allow(provider).to receive(:grafana_cli) provider.create + expect(provider).to have_received(:grafana_cli).with('--repo https://nexus.company.com/grafana/plugins', 'plugins', 'install', 'grafana-plugin') end end end