puppetlabs_spec_helper 2.7.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec/core/rake_task'
2
4
 
3
5
  module PuppetlabsSpecHelper; end
@@ -10,9 +12,7 @@ module PuppetlabsSpecHelper::Tasks::BeakerHelpers
10
12
 
11
13
  # cache the repositories and return a hash object
12
14
  def repositories
13
- unless @repositories
14
- @repositories = fixtures('repositories')
15
- end
15
+ @repositories ||= fixtures('repositories')
16
16
  @repositories
17
17
  end
18
18
 
@@ -20,6 +20,7 @@ module PuppetlabsSpecHelper::Tasks::BeakerHelpers
20
20
  # @return [Array<String>]
21
21
  def beaker_node_sets
22
22
  return @beaker_nodes if @beaker_nodes
23
+
23
24
  @beaker_nodes = Dir['spec/acceptance/nodesets/*.yml'].sort.map do |node_set|
24
25
  node_set.slice!('.yml')
25
26
  File.basename(node_set)
@@ -42,43 +43,46 @@ module PuppetlabsSpecHelper::Tasks::BeakerHelpers
42
43
  # Vagrant is not distributed as a normal gem
43
44
  # and we should protect it from the current Ruby environment
44
45
  env = {
45
- 'RUBYLIB' => nil,
46
- 'GEM_PATH' => nil,
47
- 'BUNDLE_BIN_PATH' => nil,
46
+ 'RUBYLIB' => nil,
47
+ 'GEM_PATH' => nil,
48
+ 'BUNDLE_BIN_PATH' => nil,
48
49
  }
49
50
  system env, command
50
51
  end
51
52
  end
52
53
  end
53
- include PuppetlabsSpecHelper::Tasks::BeakerHelpers
54
+ include PuppetlabsSpecHelper::Tasks::BeakerHelpers # legacy support code # rubocop:disable Style/MixinUsage
54
55
 
55
- desc "Run beaker acceptance tests"
56
+ desc 'Run beaker acceptance tests'
56
57
  RSpec::Core::RakeTask.new(:beaker) do |t|
57
58
  SetupBeaker.setup_beaker(t)
58
59
  end
59
60
 
60
61
  class SetupBeaker
61
- def self.setup_beaker(t)
62
- t.rspec_opts = ['--color']
63
- t.pattern = 'spec/acceptance'
62
+ def self.setup_beaker(task)
63
+ task.rspec_opts = []
64
+ task.pattern = 'spec/acceptance'
64
65
  # TEST_TIERS env variable is a comma separated list of tiers to run. e.g. low, medium, high
65
66
  if ENV['TEST_TIERS']
66
67
  test_tiers = ENV['TEST_TIERS'].split(',')
67
- raise 'TEST_TIERS env variable must have at least 1 tier specified. low, medium or high (comma separated).' if test_tiers.count == 0
68
+ test_tiers_allowed = ENV.fetch('TEST_TIERS_ALLOWED', 'low,medium,high').split(',')
69
+ raise 'TEST_TIERS env variable must have at least 1 tier specified. Either low, medium or high or one of the tiers listed in TEST_TIERS_ALLOWED (comma separated).' if test_tiers.count == 0
70
+
68
71
  test_tiers.each do |tier|
69
72
  tier_to_add = tier.strip.downcase
70
- raise "#{tier_to_add} not a valid test tier." unless %w(low medium high).include?(tier_to_add)
73
+ raise "#{tier_to_add} not a valid test tier." unless test_tiers_allowed.include?(tier_to_add)
74
+
71
75
  tiers = "--tag tier_#{tier_to_add}"
72
- t.rspec_opts.push(tiers)
76
+ task.rspec_opts.push(tiers)
73
77
  end
74
78
  else
75
79
  puts 'TEST_TIERS env variable not defined. Defaulting to run all tests.'
76
80
  end
77
- return t
81
+ task
78
82
  end
79
83
  end
80
84
 
81
- desc "List available beaker nodesets"
85
+ desc 'List available beaker nodesets'
82
86
  task 'beaker:sets' do
83
87
  beaker_node_sets.each do |set|
84
88
  puts set
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathspec'
4
+
5
+ module PuppetlabsSpecHelper; end
6
+ module PuppetlabsSpecHelper::Tasks; end
7
+
8
+ class PuppetlabsSpecHelper::Tasks::CheckSymlinks
9
+ DEFAULT_IGNORED = [
10
+ '/.git/',
11
+ '/.bundle/',
12
+ '/vendor/',
13
+ ].freeze
14
+
15
+ IGNORE_LIST_FILES = [
16
+ '.pdkignore',
17
+ '.gitignore',
18
+ ].freeze
19
+
20
+ def check(dir = Dir.pwd)
21
+ dir = Pathname.new(dir) unless dir.is_a?(Pathname)
22
+ results = []
23
+
24
+ dir.each_child(true) do |child|
25
+ next if ignored?(child.to_s)
26
+
27
+ if child.symlink?
28
+ results << child
29
+ elsif child.directory? && child.basename.to_s !~ %r{^(\.git|\.?bundle)$}
30
+ results.concat(check(child))
31
+ end
32
+ end
33
+
34
+ results
35
+ end
36
+
37
+ def ignored?(path)
38
+ path = "#{path}/" if File.directory?(path)
39
+
40
+ !ignore_pathspec.match_paths([path], Dir.pwd).empty?
41
+ end
42
+
43
+ def ignore_pathspec
44
+ @ignore_pathspec ||= PathSpec.new(DEFAULT_IGNORED).tap do |pathspec|
45
+ IGNORE_LIST_FILES.each do |f|
46
+ next unless File.file?(f) && File.readable?(f)
47
+
48
+ File.open(f, 'r') { |fd| pathspec.add(fd) }
49
+ end
50
+ end
51
+ end
52
+ end