puppetlabs_spec_helper 2.14.1 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: eb89bc7cd1c8a7ea79dd83f18fc2d15ad24f035c
4
- data.tar.gz: 67d56faf027cbbec8e0ffa0a32b4f2c0dd9134e1
2
+ SHA256:
3
+ metadata.gz: ef8655a96bfce5e47b0a0c1691cc79033fb8c0257ae329f1f133bcfcf950cb51
4
+ data.tar.gz: 6422a905001992ce256ce6102e59feffb1853c37f6997b5a2deb439e77721e98
5
5
  SHA512:
6
- metadata.gz: b7604f2bc60bd6e96722e89229e69b74e1cef4c45a67c377730b5e5eb2a23b525f5486772f7fa5dbcdc5904971caab232d845d506323deb435510fbf1411c7dd
7
- data.tar.gz: 00a4bcf65955310bbe0e9b5f3e71da39ee0a63f104ad764c3df7519edf42c13fc8dc5c6a8dfd176c602abf911c8a73b650118ffe0239f04e9567cf18fc0ba032
6
+ metadata.gz: 6b1ede292272b8999f9d0c2775dc9796cea623062dc482b1ed5f3c8e9d7b204b2c171b4a9c582eb0a72a0ef73c1c604c33255e7a234bfedc45435dc9a87f1a0e
7
+ data.tar.gz: d90acb664b74a454610637f5363ab6d975290272aff8f9b6dc0195104493a7d66c6e9c0d646d4d1f877d06244646dae95fa9e70a036f3f4f8a995c296444e1a4
@@ -136,3 +136,7 @@ Style/SymbolArray:
136
136
  Description: Using percent style obscures symbolic intent of array's contents.
137
137
  Enabled: true
138
138
  EnforcedStyle: brackets
139
+
140
+ # Enforce LF line endings, even when on Windows
141
+ Layout/EndOfLine:
142
+ EnforcedStyle: lf
@@ -1,12 +1,16 @@
1
- sudo: false
1
+ os: linux
2
+ dist: xenial
2
3
  language: ruby
3
4
  cache: bundler
4
- before_install:
5
- bundle -v
5
+ before_install: bundle -v
6
6
  script: env COVERAGE=yes bundle exec rake
7
- matrix:
7
+ jobs:
8
8
  fast_finish: true
9
9
  include:
10
+ - rvm: '2.7'
11
+ env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#master' # TODO: change to 7 once it becomes available
12
+ - rvm: '2.6'
13
+ env: PUPPET_GEM_VERSION='~> 6.0'
10
14
  - rvm: '2.5'
11
15
  env: PUPPET_GEM_VERSION='~> 6.0'
12
16
  - rvm: '2.4'
@@ -25,11 +29,5 @@ matrix:
25
29
  env: PUPPET_GEM_VERSION='~> 4.0'
26
30
  - rvm: '2.1'
27
31
  env: PUPPET_GEM_VERSION='~> 4.0'
28
- - rvm: '2.1'
29
- env: PUPPET_GEM_VERSION='~> 3.0'
30
- - rvm: '2.0'
31
- env: PUPPET_GEM_VERSION='~> 3.0'
32
- - rvm: '1.9'
33
- env: PUPPET_GEM_VERSION='~> 3.0'
34
32
  notifications:
35
33
  email: false
@@ -3,6 +3,31 @@
3
3
  All significant changes to this repo will be summarized in this file.
4
4
 
5
5
 
6
+ ## [v2.15.0](https://github.com/puppetlabs/puppetlabs_spec_helper/tree/v2.15.0) (2020-06-11)
7
+ [Full Changelog](https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.14.1...v2.15.0)
8
+
9
+ **Implemented enhancements:**
10
+
11
+ - Add Ruby 2.6/Puppet6 to CI matrix [\#311](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/311) ([bastelfreak](https://github.com/bastelfreak))
12
+ - \(GH-297\) Don't allow git refs with forward slashes [\#299](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/299) ([glennsarti](https://github.com/glennsarti))
13
+ - Accept `:tag` for consistency with r10k [\#296](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/296) ([binford2k](https://github.com/binford2k))
14
+ - \(maint\) migrate the changelog task from pdk-templates [\#278](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/278) ([DavidS](https://github.com/DavidS))
15
+
16
+ **Fixed bugs:**
17
+
18
+ - \(MAINT\) Fix initialize of Gettext call [\#292](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/292) ([ThoughtCrhyme](https://github.com/ThoughtCrhyme))
19
+
20
+ **Merged pull requests:**
21
+
22
+ - \(IAC-859\) Update all the gems and ruby to 2.7 [\#316](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/316) ([DavidS](https://github.com/DavidS))
23
+ - Support git fixture branches containing slashes [\#297](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/297) ([trevor-vaughan](https://github.com/trevor-vaughan))
24
+ - \(maint\) Require pdk/util in build:pdk rake task [\#295](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/295) ([rodjek](https://github.com/rodjek))
25
+ - Ignore plans folder and any subfolder [\#294](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/294) ([cyberious](https://github.com/cyberious))
26
+ - \(maint\) add codeowners file [\#293](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/293) ([tphoney](https://github.com/tphoney))
27
+ - \(MAINT\) Removes old rubies and puppet versions [\#290](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/290) ([logicminds](https://github.com/logicminds))
28
+ - Remove coveralls docs [\#289](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/289) ([DavidS](https://github.com/DavidS))
29
+ - Download forge modules in parallel [\#284](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/284) ([logicminds](https://github.com/logicminds))
30
+
6
31
  ## [v2.14.1](https://github.com/puppetlabs/puppetlabs_spec_helper/tree/v2.14.1) (2019-03-26)
7
32
  [Full Changelog](https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.14.0...v2.14.1)
8
33
 
@@ -10,6 +35,10 @@ All significant changes to this repo will be summarized in this file.
10
35
 
11
36
  - Revert "\(feat\) dont load the beaker if litmus is there" [\#286](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/286) ([pmcmaw](https://github.com/pmcmaw))
12
37
 
38
+ **Merged pull requests:**
39
+
40
+ - \(MODULES-8778\) - Release Prep 2.14.1 [\#287](https://github.com/puppetlabs/puppetlabs_spec_helper/pull/287) ([pmcmaw](https://github.com/pmcmaw))
41
+
13
42
  ## [v2.14.0](https://github.com/puppetlabs/puppetlabs_spec_helper/tree/v2.14.0) (2019-03-25)
14
43
  [Full Changelog](https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.13.1...v2.14.0)
15
44
 
@@ -0,0 +1,2 @@
1
+ # Default owners.
2
+ * @puppetlabs/pdk @puppetlabs/modules
data/Gemfile CHANGED
@@ -1,24 +1,46 @@
1
- source 'https://rubygems.org'
1
+ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
2
+
3
+ def location_for(place_or_version, fake_version = nil)
4
+ git_url_regex = %r{\A(?<url>(https?|git)[:@][^#]*)(#(?<branch>.*))?}
5
+ file_url_regex = %r{\Afile:\/\/(?<path>.*)}
6
+
7
+ if place_or_version && (git_url = place_or_version.match(git_url_regex))
8
+ [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact
9
+ elsif place_or_version && (file_url = place_or_version.match(file_url_regex))
10
+ ['>= 0', { path: File.expand_path(file_url[:path]), require: false }]
11
+ else
12
+ [place_or_version, { require: false }]
13
+ end
14
+ end
2
15
 
3
16
  # Specify the global dependencies in puppetlabs_spec_helper.gemspec
4
17
  # Note that only ruby 1.9 compatible dependencies may go there, everything else needs to be documented and pulled in manually, and optionally by everyone who wants to use the extended features.
5
18
  gemspec
6
19
 
20
+ def infer_puppet_version
21
+ # Infer the Puppet Gem version based on the Ruby Version
22
+ ruby_ver = Gem::Version.new(RUBY_VERSION.dup)
23
+ return '~> 6.0' if ruby_ver >= Gem::Version.new('2.5.0')
24
+ return '~> 5.0' if ruby_ver >= Gem::Version.new('2.4.0')
25
+ '~> 4.0'
26
+ end
27
+
7
28
  group :development do
8
29
  gem 'codecov'
9
30
  gem 'github_changelog_generator' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.0')
10
- gem 'puppet', ENV['PUPPET_GEM_VERSION'] || ENV['PUPPET_VERSION'] || '~> 4.0'
31
+ gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'] || ENV['PUPPET_VERSION'] || infer_puppet_version)
11
32
  gem 'simplecov', '~> 0'
12
33
  gem 'simplecov-console'
13
34
  if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
14
- gem 'rubocop', '< 0.50'
35
+ gem 'rubocop', '= 0.49'
15
36
  gem 'rubocop-rspec', '~> 1'
16
37
  end
17
38
  end
18
39
 
19
- # json_pure 2.0.2 added a requirement on ruby >= 2. We pin to json_pure 2.0.1
20
- # if using ruby 1.x
21
- gem 'json_pure', '<=2.0.1' if RUBY_VERSION =~ %r{^1\.}
22
- gem 'rack', '~> 1'
40
+ # pin some gems for older ruby versions
41
+ gem 'fakefs', '<= 0.13.3' if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.4.0')
42
+ gem 'json_pure', '<=2.0.1' if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
43
+ gem 'puppet-syntax', '<= 3' if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.4.0')
44
+ gem 'rack', '~> 1' if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.2.0')
23
45
 
24
46
  # vim:filetype=ruby
data/README.md CHANGED
@@ -59,7 +59,7 @@ Host github.com
59
59
 
60
60
  ```
61
61
 
62
- Note: parallel downloads is only available for repositories and not forge modules.
62
+ Note: parallel downloads are available for repositories and forge modules.
63
63
 
64
64
  ### Parallel tests
65
65
  It is also possible to use the `parallel_tests` Gem via the `:parallel_spec` Rake task to run rspec commands in parallel on groups of spec files.
@@ -156,7 +156,7 @@ variables for the spec run. These are:
156
156
  * ``TRUSTED_NODE_DATA`` _(Puppet 3.x, starting with 3.4)_ - set to "yes" to enable [the $facts hash and trusted node data](https://puppet.com/docs/puppet/3.8/lang_facts_and_builtin_vars.html#trusted-facts),
157
157
  which enabled ``$facts`` and ``$trusted`` hashes. This is equivalent to setting
158
158
  [trusted_node_data=true](https://puppet.com/docs/puppet/3.8/configuration.html#trustednodedata)
159
- in puppet.conf.
159
+ in puppet.conf.
160
160
  * ``STRINGIFY_FACTS`` _(Puppet 3.x, starting with 3.5)_ - set to "no" to enable [structured facts](http://docs.puppetlabs.com/facter/2.0/fact_overview.html#writing-structured-facts),
161
161
  otherwise leave unset to retain the current default behavior. This is equivalent to setting
162
162
  [stringify_facts=false](https://puppet.com/docs/puppet/3.8/configuration.html#stringifyfacts)
@@ -203,7 +203,7 @@ When specifying the repo source of the fixture you have a few options as to whic
203
203
 
204
204
  * `target` - the directory name to clone the repo into ie. `target: mymodule` defaults to the repo name (Optional)
205
205
  * `subdir` - directory to be removed from the cloned repo. Its contents will be moved to the root directory (Optional)
206
- * `ref` - used to specify the tag name like version hash of commit (Optional)
206
+ * `ref` - used to specify the tag name (like version) or commit hash to be checked out (Optional). Branch names should use the `branch` option instead.
207
207
 
208
208
  ```yaml
209
209
  ref: 1.0.0
@@ -389,7 +389,7 @@ environment variable``TEST_TIERS=high,medium``
389
389
 
390
390
  By default ``TEST_TIERS`` only accepts low, medium and high as valid tiers. If you would like to use your own keywords to set the environment variable ``TEST_TIERS_ALLOWED``.
391
391
 
392
- For example: to use the keywords dev, rnd, staging and production you can set
392
+ For example: to use the keywords dev, rnd, staging and production you can set
393
393
  ``TEST_TIERS_ALLOWED=dev,rnd,staging,production``. Then you would be able to run tests marked ``tier_dev => true``, ``tier_production => true`` with ``TEST_TIERS=dev,production``
394
394
 
395
395
  Note, if the ``TEST_TIERS`` environment variable is set to empty string or nil, all tiers will be executed.
@@ -416,34 +416,7 @@ You can enable it, set the following environment variable:s
416
416
 
417
417
  ``SIMPLECOV=yes``
418
418
 
419
- Remember to add the simplecov-console and codecov gems to your `Gemfile`.
420
-
421
- Using Coveralls
422
- ---------------
423
-
424
- You can also use [Coveralls](https://coveralls.io/) together with SimpleCov:
425
-
426
- ```Ruby
427
- # First line of spec/spec_helper.rb
428
- require 'simplecov'
429
- require 'coveralls'
430
-
431
- SimpleCov.formatters = [
432
- SimpleCov::Formatter::HTMLFormatter,
433
- Coveralls::SimpleCov::Formatter
434
- ]
435
-
436
- SimpleCov.start do
437
- add_filter '/spec/'
438
- # Exclude bundled Gems in `/.vendor/`
439
- add_filter '/.vendor/'
440
- end
441
-
442
- require 'puppetlabs_spec_helper/module_spec_helper'
443
- # Further content
444
- ```
445
-
446
- Remember to add `gem 'coveralls', require: false` to your `Gemfile`.
419
+ Remember to add the simplecov-console and codecov gems to your `Gemfile`. If you run `spec:simplecov` on Travis-CI or any of the other supported CI services, reports gets automatically uploaded to https://codecov.io/ .
447
420
 
448
421
  Some Notes for Windows Users
449
422
  ============================
@@ -142,6 +142,7 @@ namespace :build do
142
142
  desc 'Build Puppet module with PDK'
143
143
  task :pdk do
144
144
  begin
145
+ require 'pdk/util'
145
146
  require 'pdk/module/build'
146
147
 
147
148
  path = PDK::Module::Build.invoke(:force => true, :'target-dir' => File.join(Dir.pwd, 'pkg'))
@@ -220,7 +221,8 @@ PuppetSyntax.exclude_paths ||= []
220
221
  PuppetSyntax.exclude_paths << 'spec/fixtures/**/*'
221
222
  PuppetSyntax.exclude_paths << 'pkg/**/*'
222
223
  PuppetSyntax.exclude_paths << 'vendor/**/*'
223
- PuppetSyntax.exclude_paths << 'plans/*'
224
+ PuppetSyntax.exclude_paths << '.vendor/**/*'
225
+ PuppetSyntax.exclude_paths << 'plans/**/*'
224
226
  if Puppet.version.to_f < 4.0
225
227
  PuppetSyntax.exclude_paths << 'types/**/*'
226
228
  end
@@ -367,7 +369,7 @@ if File.exist? locales_dir
367
369
  spec = Gem::Specification.find_by_name 'gettext-setup'
368
370
  load "#{spec.gem_dir}/lib/tasks/gettext.rake"
369
371
  # Initialization requires a valid locales directory
370
- GettextSetup.initialize_config(locales_dir)
372
+ GettextSetup.initialize(locales_dir)
371
373
  namespace :module do
372
374
  desc 'Runs all tasks to build a modules POT file for internationalization'
373
375
  task :pot_gen do
@@ -379,3 +381,79 @@ if File.exist? locales_dir
379
381
  puts 'No gettext-setup gem found, skipping GettextSetup config initialization' if Rake.verbose == true
380
382
  end
381
383
  end
384
+
385
+ def create_gch_task(changelog_user = nil, changelog_project = nil, changelog_since_tag = nil, changelog_tag_pattern = 'v%s')
386
+ if Bundler.rubygems.find_name('github_changelog_generator').any?
387
+ # needed a place to hide these methods
388
+ # rubocop:disable Lint/NestedMethodDefinition
389
+ def changelog_user_from_metadata
390
+ result = JSON.parse(File.read('metadata.json'))['author']
391
+ raise 'unable to find the changelog_user in .sync.yml, or the author in metadata.json' if result.nil?
392
+ puts "GitHubChangelogGenerator user:#{result}"
393
+ result
394
+ end
395
+
396
+ def changelog_project_from_metadata
397
+ result = JSON.parse(File.read('metadata.json'))['name']
398
+ raise 'unable to find the changelog_project in .sync.yml or the name in metadata.json' if result.nil?
399
+ puts "GitHubChangelogGenerator project:#{result}"
400
+ result
401
+ end
402
+
403
+ def changelog_future_release
404
+ return unless Rake.application.top_level_tasks.include? 'changelog'
405
+ result = JSON.parse(File.read('metadata.json'))['version']
406
+ raise 'unable to find the future_release (version) in metadata.json' if result.nil?
407
+ puts "GitHubChangelogGenerator future_release:#{result}"
408
+ result
409
+ end
410
+ # rubocop:enable Lint/NestedMethodDefinition
411
+
412
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
413
+ if ENV['CHANGELOG_GITHUB_TOKEN'].nil?
414
+ raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'"
415
+ end
416
+ config.user = changelog_user || changelog_user_from_metadata
417
+ config.project = changelog_project || changelog_project_from_metadata
418
+ config.since_tag = changelog_since_tag if changelog_since_tag
419
+ config.future_release = changelog_tag_pattern % changelog_future_release.to_s
420
+ config.exclude_labels = ['maintenance']
421
+ config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. " \
422
+ 'The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres ' \
423
+ 'to [Semantic Versioning](https://semver.org).'
424
+ config.add_pr_wo_labels = true
425
+ config.issues = false
426
+ config.merge_prefix = '### UNCATEGORIZED PRS; GO LABEL THEM'
427
+ config.configure_sections = {
428
+ 'Changed' => {
429
+ 'prefix' => '### Changed',
430
+ 'labels' => ['backwards-incompatible'],
431
+ },
432
+ 'Added' => {
433
+ 'prefix' => '### Added',
434
+ 'labels' => %w[feature enhancement],
435
+ },
436
+ 'Fixed' => {
437
+ 'prefix' => '### Fixed',
438
+ 'labels' => ['bugfix'],
439
+ },
440
+ }
441
+ end
442
+ else
443
+ desc 'Generate a Changelog from GitHub'
444
+ task :changelog do
445
+ raise <<EOM
446
+ The changelog tasks depends on unreleased features of the github_changelog_generator gem.
447
+ Please manually add it to your .sync.yml for now, and run `pdk update`:
448
+ ---
449
+ Gemfile:
450
+ optional:
451
+ ':development':
452
+ - gem: 'github_changelog_generator'
453
+ git: 'https://github.com/skywinder/github-changelog-generator'
454
+ ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018'
455
+ condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')"
456
+ EOM
457
+ end
458
+ end
459
+ end
@@ -4,12 +4,14 @@ require 'json'
4
4
 
5
5
  module PuppetlabsSpecHelper; end
6
6
  module PuppetlabsSpecHelper::Tasks; end
7
+
7
8
  module PuppetlabsSpecHelper::Tasks::FixtureHelpers
8
9
  # This is a helper for the self-symlink entry of fixtures.yml
9
10
  def source_dir
10
11
  Dir.pwd
11
12
  end
12
13
 
14
+ # @return [String] - the name of current module
13
15
  def module_name
14
16
  raise ArgumentError unless File.file?('metadata.json') && File.readable?('metadata.json')
15
17
 
@@ -23,18 +25,39 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
23
25
  File.basename(Dir.pwd).split('-').last
24
26
  end
25
27
 
26
- # cache the repositories and return a hash object
28
+ # @return [Hash] - returns a hash of all the fixture repositories
29
+ # @example
30
+ # {"puppetlabs-stdlib"=>{"target"=>"https://gitlab.com/puppetlabs/puppet-stdlib.git",
31
+ # "ref"=>nil, "branch"=>"master", "scm"=>nil,
32
+ # }}
27
33
  def repositories
28
- unless @repositories
29
- @repositories = fixtures('repositories')
30
- end
31
- @repositories
34
+ @repositories ||= fixtures('repositories') || {}
35
+ end
36
+
37
+ # @return [Hash] - returns a hash of all the fixture forge modules
38
+ # @example
39
+ # {"puppetlabs-stdlib"=>{"target"=>"spec/fixtures/modules/stdlib",
40
+ # "ref"=>nil, "branch"=>nil, "scm"=>nil,
41
+ # "flags"=>"--module_repository=https://myforge.example.com/", "subdir"=>nil}}
42
+ def forge_modules
43
+ @forge_modules ||= fixtures('forge_modules') || {}
44
+ end
45
+
46
+ # @return [Hash] - a hash of symlinks specified in the fixtures file
47
+ def symlinks
48
+ @symlinks ||= fixtures('symlinks') || {}
32
49
  end
33
50
 
51
+ # @return [Hash] - returns a hash with the module name and the source directory
34
52
  def auto_symlink
35
53
  { module_name => '#{source_dir}' }
36
54
  end
37
55
 
56
+ # @return [Boolean] - true if the os is a windows system
57
+ def windows?
58
+ !!File::ALT_SEPARATOR
59
+ end
60
+
38
61
  def fixtures(category)
39
62
  fixtures_yaml = if ENV['FIXTURES_YML']
40
63
  ENV['FIXTURES_YML']
@@ -77,7 +100,6 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
77
100
 
78
101
  result = {}
79
102
  if fixtures.include?(category) && !fixtures[category].nil?
80
-
81
103
  defaults = { 'target' => 'spec/fixtures/modules' }
82
104
 
83
105
  # load defaults from the `.fixtures.yml` `defaults` section
@@ -103,19 +125,29 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
103
125
  real_target = eval('"' + opts['target'] + '"')
104
126
  real_source = eval('"' + opts['repo'] + '"')
105
127
 
106
- result[real_source] = {
128
+ result[real_source] = validate_fixture_hash!(
107
129
  'target' => File.join(real_target, fixture),
108
- 'ref' => opts['ref'],
130
+ 'ref' => opts['ref'] || opts['tag'],
109
131
  'branch' => opts['branch'],
110
- 'scm' => opts['scm'],
111
- 'flags' => opts['flags'],
132
+ 'scm' => opts['scm'],
133
+ 'flags' => opts['flags'],
112
134
  'subdir' => opts['subdir'],
113
- }
135
+ )
114
136
  end
115
137
  end
116
138
  result
117
139
  end
118
140
 
141
+ def validate_fixture_hash!(hash)
142
+ # Can only validate git based scm
143
+ return hash unless hash['scm'] == 'git'
144
+
145
+ # Forward slashes in the ref aren't allowed. And is probably a branch name.
146
+ raise ArgumentError, "The ref for #{hash['target']} is invalid (Contains a forward slash). If this is a branch name, please use the 'branch' setting instead." if hash['ref'] =~ %r{\/}
147
+
148
+ hash
149
+ end
150
+
119
151
  def include_repo?(version_range)
120
152
  if version_range && defined?(SemanticPuppet)
121
153
  puppet_spec = Gem::Specification.find_by_name('puppet')
@@ -235,6 +267,7 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
235
267
  # returns the current thread count that is currently active
236
268
  # a status of false or nil means the thread completed
237
269
  # so when anything else we count that as a active thread
270
+ # @return [Integer] - current thread count
238
271
  def current_thread_count(items)
239
272
  active_threads = items.find_all do |_item, opts|
240
273
  if opts[:thread]
@@ -247,79 +280,46 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
247
280
  active_threads.count
248
281
  end
249
282
 
250
- # returns the max_thread_count
251
- # because we may want to limit ssh or https connections
283
+ # @summary Set a limit on the amount threads used, defaults to 10
284
+ # MAX_FIXTURE_THREAD_COUNT can be used to set this limit
285
+ # @return [Integer] - returns the max_thread_count
252
286
  def max_thread_limit
253
- unless @max_thread_limit
254
- # the default thread count is 10 but can be
255
- # raised by using environment variable MAX_FIXTURE_THREAD_COUNT
256
- @max_thread_limit = if ENV['MAX_FIXTURE_THREAD_COUNT'].to_i > 0
257
- ENV['MAX_FIXTURE_THREAD_COUNT'].to_i
258
- else
259
- 10 # the default
260
- end
261
- end
262
- @max_thread_limit
287
+ @max_thread_limit ||= (ENV['MAX_FIXTURE_THREAD_COUNT'] || 10).to_i
263
288
  end
264
- end
265
- include PuppetlabsSpecHelper::Tasks::FixtureHelpers
266
289
 
267
- desc 'Create the fixtures directory'
268
- task :spec_prep do
269
- # Ruby only sets File::ALT_SEPARATOR on Windows and Rubys standard library
270
- # uses this to check for Windows
271
- is_windows = !!File::ALT_SEPARATOR
272
- if is_windows
273
- begin
274
- require 'win32/dir'
275
- rescue LoadError
276
- $stderr.puts 'win32-dir gem not installed, falling back to executing mklink directly'
277
- end
278
- end
279
-
280
- # git has a race condition creating that directory, that would lead to aborted clone operations
281
- FileUtils.mkdir_p('spec/fixtures/modules')
282
-
283
- repositories.each do |remote, opts|
284
- scm = 'git'
285
- target = opts['target']
286
- subdir = opts['subdir']
287
- ref = opts['ref']
288
- scm = opts['scm'] if opts['scm']
289
- branch = opts['branch'] if opts['branch']
290
- flags = opts['flags']
291
- # get the current active threads that are alive
292
- count = current_thread_count(repositories)
293
- if count < max_thread_limit
294
- logger.debug "New Thread started for #{remote}"
295
- # start up a new thread and store it in the opts hash
296
- opts[:thread] = Thread.new do
297
- if valid_repo?(scm, target, remote)
298
- update_repo(scm, target)
299
- else
300
- clone_repo(scm, remote, target, subdir, ref, branch, flags)
290
+ # @param items [Hash] - a hash of either repositories or forge modules
291
+ # @param [Block] - the method you wish to use to download the item
292
+ def download_items(items)
293
+ items.each do |remote, opts|
294
+ # get the current active threads that are alive
295
+ count = current_thread_count(items)
296
+ if count < max_thread_limit
297
+ logger.debug "New Thread started for #{remote}"
298
+ # start up a new thread and store it in the opts hash
299
+ opts[:thread] = Thread.new do
300
+ yield(remote, opts)
301
301
  end
302
- revision(scm, target, ref) if ref
303
- remove_subdirectory(target, subdir) if subdir
302
+ else
303
+ # the last thread started should be the longest wait
304
+ item, item_opts = items.find_all { |_i, o| o.key?(:thread) }.last
305
+ logger.debug "Waiting on #{item}"
306
+ item_opts[:thread].join # wait for the thread to finish
307
+ # now that we waited lets try again
308
+ redo
304
309
  end
305
- else
306
- # the last thread started should be the longest wait
307
- item, item_opts = repositories.find_all { |_i, o| o.key?(:thread) }.last
308
- logger.debug "Waiting on #{item}"
309
- item_opts[:thread].join # wait for the thread to finish
310
- # now that we waited lets try again
311
- redo
312
310
  end
311
+ # wait for all the threads to finish
312
+ items.each { |_remote, opts| opts[:thread].join }
313
313
  end
314
314
 
315
- # wait for all the threads to finish
316
- repositories.each { |_remote, opts| opts[:thread].join }
317
-
318
- fixtures('symlinks').each do |target, link|
315
+ # @param target [String] - the target directory
316
+ # @param link [String] - the name of the link you wish to create
317
+ # works on windows and linux
318
+ def setup_symlink(target, link)
319
319
  link = link['target']
320
- next if File.symlink?(link)
320
+ return if File.symlink?(link)
321
321
  logger.info("Creating symlink from #{link} to #{target}")
322
- if is_windows
322
+ if windows?
323
323
  target = File.join(File.dirname(link), target) unless Pathname.new(target).absolute?
324
324
  if Dir.respond_to?(:create_junction)
325
325
  Dir.create_junction(link, target)
@@ -331,7 +331,35 @@ task :spec_prep do
331
331
  end
332
332
  end
333
333
 
334
- fixtures('forge_modules').each do |remote, opts|
334
+ # @return [Boolean] - returns true if the module was downloaded successfully, false otherwise
335
+ # @param [String] - the remote url or namespace/name of the module to download
336
+ # @param [Hash] - list of options such as version, branch, ref
337
+ def download_repository(remote, opts)
338
+ scm = 'git'
339
+ target = opts['target']
340
+ subdir = opts['subdir']
341
+ ref = opts['ref']
342
+ scm = opts['scm'] if opts['scm']
343
+ branch = opts['branch'] if opts['branch']
344
+ flags = opts['flags']
345
+ if valid_repo?(scm, target, remote)
346
+ update_repo(scm, target)
347
+ else
348
+ clone_repo(scm, remote, target, subdir, ref, branch, flags)
349
+ end
350
+ revision(scm, target, ref) if ref
351
+ remove_subdirectory(target, subdir) if subdir
352
+ end
353
+
354
+ # @return [String] - the spec/fixtures/modules directory in the module root folder
355
+ def module_target_dir
356
+ @module_target_dir ||= File.expand_path('spec/fixtures/modules')
357
+ end
358
+
359
+ # @return [Boolean] - returns true if the module was downloaded successfully, false otherwise
360
+ # @param [String] - the remote url or namespace/name of the module to download
361
+ # @param [Hash] - list of options such as version
362
+ def download_module(remote, opts)
335
363
  ref = ''
336
364
  flags = ''
337
365
  if opts.instance_of?(String)
@@ -342,34 +370,60 @@ task :spec_prep do
342
370
  flags = " #{opts['flags']}" if opts['flags']
343
371
  end
344
372
 
345
- next if File.directory?(target)
373
+ return false if File.directory?(target)
346
374
 
347
- working_dir = module_working_directory
348
- target_dir = File.expand_path('spec/fixtures/modules')
375
+ # The PMT cannot handle multi threaded runs due to cache directory collisons
376
+ # so we randomize the directory instead.
377
+ # Does working_dir even need to be passed?
378
+ Dir.mktmpdir do |working_dir|
379
+ command = 'puppet module install' + ref + flags + ' --ignore-dependencies' \
380
+ ' --force' \
381
+ " --module_working_dir \"#{working_dir}\"" \
382
+ " --target-dir \"#{module_target_dir}\" \"#{remote}\""
383
+
384
+ unless system(command)
385
+ raise "Failed to install module #{remote} to #{module_target_dir}"
386
+ end
387
+ end
388
+ $CHILD_STATUS.success?
389
+ end
390
+ end
349
391
 
350
- command = 'puppet module install' + ref + flags + \
351
- ' --ignore-dependencies' \
352
- ' --force' \
353
- " --module_working_dir \"#{working_dir}\"" \
354
- " --target-dir \"#{target_dir}\" \"#{remote}\""
392
+ include PuppetlabsSpecHelper::Tasks::FixtureHelpers
355
393
 
356
- unless system(command)
357
- raise "Failed to install module #{remote} to #{target_dir}"
394
+ desc 'Create the fixtures directory'
395
+ task :spec_prep do
396
+ # Ruby only sets File::ALT_SEPARATOR on Windows and Rubys standard library
397
+ # uses this to check for Windows
398
+ if windows?
399
+ begin
400
+ require 'win32/dir'
401
+ rescue LoadError
402
+ $stderr.puts 'win32-dir gem not installed, falling back to executing mklink directly'
358
403
  end
359
404
  end
360
405
 
406
+ # git has a race condition creating that directory, that would lead to aborted clone operations
407
+ FileUtils.mkdir_p('spec/fixtures/modules')
408
+
409
+ symlinks.each { |target, link| setup_symlink(target, link) }
410
+
411
+ download_items(repositories) { |remote, opts| download_repository(remote, opts) }
412
+
413
+ download_items(forge_modules) { |remote, opts| download_module(remote, opts) }
414
+
361
415
  FileUtils.mkdir_p('spec/fixtures/manifests')
362
416
  FileUtils.touch('spec/fixtures/manifests/site.pp')
363
417
  end
364
418
 
365
419
  desc 'Clean up the fixtures directory'
366
420
  task :spec_clean do
367
- fixtures('repositories').each do |_remote, opts|
421
+ repositories.each do |_remote, opts|
368
422
  target = opts['target']
369
423
  FileUtils.rm_rf(target)
370
424
  end
371
425
 
372
- fixtures('forge_modules').each do |_remote, opts|
426
+ forge_modules.each do |_remote, opts|
373
427
  target = opts['target']
374
428
  FileUtils.rm_rf(target)
375
429
  end
@@ -1,5 +1,5 @@
1
1
  module PuppetlabsSpecHelper
2
- VERSION = '2.14.1'.freeze
2
+ VERSION = '2.15.0'.freeze
3
3
 
4
4
  # compat for pre-1.2.0 users; deprecated
5
5
  module Version
@@ -22,16 +22,16 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency 'mocha', '~> 1.0'
24
24
  spec.add_runtime_dependency 'puppet-lint', '~> 2.0'
25
- spec.add_runtime_dependency 'puppet-syntax', '~> 2.0'
25
+ spec.add_runtime_dependency 'puppet-syntax', ['>= 2.0', '< 4']
26
26
  spec.add_runtime_dependency 'rspec-puppet', '~> 2.0'
27
27
  spec.add_runtime_dependency 'pathspec', '~> 0.2.1'
28
28
 
29
29
  spec.add_development_dependency 'bundler'
30
30
  spec.add_development_dependency 'pry'
31
31
  spec.add_development_dependency 'puppet'
32
- spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rake', ['>= 10.0', '< 14']
33
33
  spec.add_development_dependency 'rspec', '~> 3.0'
34
34
  spec.add_development_dependency 'yard'
35
35
  spec.add_development_dependency 'gettext-setup', '~> 0.29'
36
- spec.add_development_dependency 'fakefs', '~> 0.13.3'
36
+ spec.add_development_dependency 'fakefs', ['>= 0.13.3', '< 2']
37
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetlabs_spec_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.1
4
+ version: 2.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-03-26 00:00:00.000000000 Z
12
+ date: 2020-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mocha
@@ -43,16 +43,22 @@ dependencies:
43
43
  name: puppet-syntax
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '2.0'
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: '4'
49
52
  type: :runtime
50
53
  prerelease: false
51
54
  version_requirements: !ruby/object:Gem::Requirement
52
55
  requirements:
53
- - - "~>"
56
+ - - ">="
54
57
  - !ruby/object:Gem::Version
55
58
  version: '2.0'
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: '4'
56
62
  - !ruby/object:Gem::Dependency
57
63
  name: rspec-puppet
58
64
  requirement: !ruby/object:Gem::Requirement
@@ -127,16 +133,22 @@ dependencies:
127
133
  name: rake
128
134
  requirement: !ruby/object:Gem::Requirement
129
135
  requirements:
130
- - - "~>"
136
+ - - ">="
131
137
  - !ruby/object:Gem::Version
132
138
  version: '10.0'
139
+ - - "<"
140
+ - !ruby/object:Gem::Version
141
+ version: '14'
133
142
  type: :development
134
143
  prerelease: false
135
144
  version_requirements: !ruby/object:Gem::Requirement
136
145
  requirements:
137
- - - "~>"
146
+ - - ">="
138
147
  - !ruby/object:Gem::Version
139
148
  version: '10.0'
149
+ - - "<"
150
+ - !ruby/object:Gem::Version
151
+ version: '14'
140
152
  - !ruby/object:Gem::Dependency
141
153
  name: rspec
142
154
  requirement: !ruby/object:Gem::Requirement
@@ -183,16 +195,22 @@ dependencies:
183
195
  name: fakefs
184
196
  requirement: !ruby/object:Gem::Requirement
185
197
  requirements:
186
- - - "~>"
198
+ - - ">="
187
199
  - !ruby/object:Gem::Version
188
200
  version: 0.13.3
201
+ - - "<"
202
+ - !ruby/object:Gem::Version
203
+ version: '2'
189
204
  type: :development
190
205
  prerelease: false
191
206
  version_requirements: !ruby/object:Gem::Requirement
192
207
  requirements:
193
- - - "~>"
208
+ - - ">="
194
209
  - !ruby/object:Gem::Version
195
210
  version: 0.13.3
211
+ - - "<"
212
+ - !ruby/object:Gem::Version
213
+ version: '2'
196
214
  description: Contains rake tasks and a standard spec_helper for running spec tests
197
215
  on puppet modules.
198
216
  email:
@@ -208,6 +226,7 @@ files:
208
226
  - ".rubocop_todo.yml"
209
227
  - ".travis.yml"
210
228
  - CHANGELOG.md
229
+ - CODEOWNERS
211
230
  - CONTRIBUTING.md
212
231
  - Gemfile
213
232
  - HISTORY.md
@@ -249,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
268
  version: '0'
250
269
  requirements: []
251
270
  rubyforge_project:
252
- rubygems_version: 2.6.14.1
271
+ rubygems_version: 2.7.8
253
272
  signing_key:
254
273
  specification_version: 4
255
274
  summary: Standard tasks and configuration for module spec tests.