Skip to content

Commit

Permalink
Merge pull request #418 from voxpupuli/modulesync
Browse files Browse the repository at this point in the history
modulesync 2.12.0
  • Loading branch information
bastelfreak committed Apr 30, 2020
2 parents af1ba04 + 0587cc8 commit e80f45e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 109 deletions.
6 changes: 4 additions & 2 deletions .github/CONTRIBUTING.md
Expand Up @@ -256,18 +256,20 @@ Beaker also supports docker containers. We also use that in our automated CI
pipeline at [travis-ci](http://travis-ci.org). To use that instead of Vagrant:

```sh
PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian9-64{hypervisor=docker} BEAKER_destroy=yes bundle exec rake beaker
PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian10-64{hypervisor=docker} BEAKER_destroy=yes bundle exec rake beaker
```

You can replace the string `debian9` with any common operating system.
You can replace the string `debian10` with any common operating system.
The following strings are known to work:

* ubuntu1604
* ubuntu1804
* debian8
* debian9
* debian10
* centos6
* centos7
* centos8

The easiest way to debug in a docker container is to open a shell:

Expand Down
2 changes: 1 addition & 1 deletion .msync.yml
@@ -1 +1 @@
modulesync_config_version: '2.10.0'
modulesync_config_version: '2.12.0'
3 changes: 2 additions & 1 deletion .rubocop.yml
@@ -1,6 +1,7 @@
require: rubocop-rspec
AllCops:
TargetRubyVersion: 2.1
# Puppet Server 5 defaults to jruby 1.7 so TargetRubyVersion must stay at 1.9 until we drop support for puppet 5
TargetRubyVersion: 1.9
Include:
- ./**/*.rb
Exclude:
Expand Down
25 changes: 4 additions & 21 deletions Gemfile
Expand Up @@ -11,27 +11,9 @@ def location_for(place, fake_version = nil)
end

group :test do
gem 'puppetlabs_spec_helper', '>= 2.14.0', :require => false
gem 'rspec-puppet-facts', '>= 1.9.5', :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', '>= 2.0.0', :require => false
gem 'puppet-lint-topscope-variable-check', :require => false
gem 'puppet-lint-legacy_facts-check', :require => false
gem 'puppet-lint-anchor-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 'voxpupuli-test', '>= 1.0.0', :require => false
gem 'coveralls', :require => false
gem 'simplecov-console', :require => false
end

group :development do
Expand Down Expand Up @@ -62,6 +44,7 @@ group :system_tests do
gem 'rbnacl', '>= 4', :require => false
gem 'rbnacl-libsodium', :require => false
gem 'bcrypt_pbkdf', :require => false
gem 'ed25519', :require => false
end

group :release do
Expand Down
33 changes: 1 addition & 32 deletions Rakefile
@@ -1,4 +1,4 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'voxpupuli/test/rake'

# load optional tasks for releases
# only available if gem group releases is installed
Expand All @@ -7,37 +7,6 @@ begin
rescue LoadError
end

PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}'

desc 'Auto-correct puppet-lint offenses'
task 'lint:auto_correct' do
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'
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__))
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/package/npm.rb
Expand Up @@ -14,8 +14,8 @@

def self.npmlist
# Ignore non-zero exit codes as they can be minor, just try and parse JSON
output = execute([command(:npm), 'list', '--json', '--global'], combine: false)
Puppet.debug("Warning: npm list --json exited with code #{$CHILD_STATUS.exitstatus}") unless $CHILD_STATUS.success?
output = execute([command(:npm), 'list', '--json', '--global'], combine: false, failonfail: false)
Puppet.debug("Warning: npm list --json exited with code #{output.exitstatus}") if output.exitstatus != 0
begin
# ignore any npm output lines to be a bit more robust
output = PSON.parse(output.lines.select { |l| l =~ %r{^((?!^npm).*)$} }.join("\n"), max_nesting: 100)
Expand Down
49 changes: 5 additions & 44 deletions spec/spec_helper.rb
@@ -1,19 +1,16 @@
# This file is managed via modulesync
# https://github.com/voxpupuli/modulesync
# https://github.com/voxpupuli/modulesync_config

RSpec.configure do |c|
c.mock_with :mocha
end

require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
require 'bundler'
include RspecPuppetFacts
# puppetlabs_spec_helper will set up coverage if the env variable is set.
# We want to do this if lib exists and it hasn't been explicitly set.
ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__))

if ENV['DEBUG']
Puppet::Util::Log.level = :debug
Puppet::Util::Log.newdestination(:console)
end
require 'voxpupuli/test/spec_helper'

if File.exist?(File.join(__dir__, 'default_module_facts.yml'))
facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml')))
Expand All @@ -23,39 +20,3 @@
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'
add_filter Bundler.configured_bundle_path.path
end
end

RSpec.configure do |c|
# getting the correct facter version is tricky. We use facterdb as a source to mock facts
# see https://github.com/camptocamp/facterdb
# people might provide a specific facter version. In that case we use it.
# Otherwise we need to match the correct facter version to the used puppet version.
# as of 2019-10-31, puppet 5 ships facter 3.11 and puppet 6 ships facter 3.14
# https://puppet.com/docs/puppet/5.5/about_agent.html
c.default_facter_version = if ENV['FACTERDB_FACTS_VERSION']
ENV['FACTERDB_FACTS_VERSION']
else
Gem::Dependency.new('', ENV['PUPPET_VERSION']).match?('', '5') ? '3.11.0' : '3.14.0'
end

# Coverage generation
c.after(:suite) do
RSpec::Puppet::Coverage.report!
end
end
15 changes: 9 additions & 6 deletions spec/unit/puppet/provider/package/npm_spec.rb
Expand Up @@ -62,24 +62,27 @@ def self.it_should_respond_to(*actions)
end

it 'returns a list of npm packages installed globally' do
provider.class.expects(:execute).with(['/usr/local/bin/npm', 'list', '--json', '--global'], anything).returns(my_fixture_read('npm_global'))
provider.class.expects(:execute).
with(['/usr/local/bin/npm', 'list', '--json', '--global'], anything).
returns(Puppet::Util::Execution::ProcessOutput.new(my_fixture_read('npm_global'), 0))
expect(provider.class.instances.map(&:properties).sort_by { |res| res[:name] }).to eq([
{ ensure: '2.5.9', provider: 'npm', name: 'express' },
{ ensure: '1.1.15', provider: 'npm', name: 'npm' }
])
end

it 'logs and continue if the list command has a non-zero exit code' do
provider.class.expects(:execute).with(['/usr/local/bin/npm', 'list', '--json', '--global'], anything).returns(my_fixture_read('npm_global'))
Process::Status.any_instance.expects(:success?).returns(false) # rubocop:disable RSpec/AnyInstance
Process::Status.any_instance.expects(:exitstatus).returns(123) # rubocop:disable RSpec/AnyInstance
provider.class.expects(:execute).
with(['/usr/local/bin/npm', 'list', '--json', '--global'], anything).
returns(Puppet::Util::Execution::ProcessOutput.new(my_fixture_read('npm_global'), 123))
Puppet.expects(:debug).with(regexp_matches(%r{123}))
expect(provider.class.instances.map(&:properties)).not_to eq([])
end

it "logs and return no packages if JSON isn't output" do
provider.class.expects(:execute).with(['/usr/local/bin/npm', 'list', '--json', '--global'], anything).returns('failure!')
Process::Status.any_instance.expects(:success?).returns(true) # rubocop:disable RSpec/AnyInstance
provider.class.expects(:execute).
with(['/usr/local/bin/npm', 'list', '--json', '--global'], anything).
returns(Puppet::Util::Execution::ProcessOutput.new('failure!', 0))
Puppet.expects(:debug).with(regexp_matches(%r{npm list.*failure!}))
expect(provider.class.instances).to eq([])
end
Expand Down

0 comments on commit e80f45e

Please sign in to comment.