puppet-check 2.3.1 → 2.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d04c10fa6bc7d10b70113b7d93ab7be0d0f5cc1e65e0976e2e40e3edcc561ff8
4
- data.tar.gz: 5e0fc0e541f9aa21bc65015cc0bc5958a8d44b3aaf36b8d1ce5e69f3942b9221
3
+ metadata.gz: c5c74c1af6aee54ad5dcfd3eeefa459ed9fd5eaaafdc847f346a8e3674ffb362
4
+ data.tar.gz: c11db9238470434a489608d62360d12fe1ff10dda29627a05cdded940785b992
5
5
  SHA512:
6
- metadata.gz: d762b4386dc42703ffea264872629684f35a98ddbf69b2eb3fb82f9039a614e146a9a6d6961c51086c33dffd80e8d192a973f4025adc355d355d1d20e442d039
7
- data.tar.gz: 90cea3c4ebc6a20d48793276f3563f7d82e8067b94ab3f3ff0c6e51bbbe8de00333c34b157baec92ed919d110eb9eb29065d90e04c01c1e7a287ae2ce3ed78fc
6
+ metadata.gz: 12416f0a0d2d2615c467645cb238e0b14be8f42c9172e5adf7acf3bfbdddbdae1d5b08ccd2a967dcb7b6af41a8149f2e30e22ed5d0db97c5f05e586e384c4a61
7
+ data.tar.gz: 053f4f90842f2d71ccbc82a3b05cd5ef1347af5399686fc3ed4a7cbf824baeee63ad412c1d6261f3640929bdcba789db7e2fe46d7f3e529cf3cd6b1c8b9690d8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 2.4.0
2
+ - Minimum Ruby version increased to 3.0.
3
+ - Fix `rubocop-performance` inclusion warning.
4
+ - Improve recognition of Ruby support files during filesystem parsing.
5
+ - Fix `file` task for no settings override usage.
6
+ - Add `rubocop-rspec` plugin to Ruby checks.
7
+ - Fix `--fail-on-warnings` functionality.
8
+ - Improve safety of Ruby syntax checks.
9
+ - Safely load Puppet data files.
10
+
1
11
  ### 2.3.1
2
12
  - No input target paths now defaults to current working directory instead of error.
3
13
  - Additionally check `Vagrantfile` and `gemspec` files.
@@ -15,8 +15,7 @@ class PuppetCheck::CLI
15
15
  end
16
16
 
17
17
  # parse the user arguments
18
- def self.parse(args)
19
- private_class_method :method
18
+ private_class_method def self.parse(args)
20
19
  require 'optparse'
21
20
 
22
21
  # show help message if no args specified
@@ -8,7 +8,7 @@ class DataParser
8
8
  def self.yaml(files)
9
9
  files.each do |file|
10
10
  # check yaml syntax
11
- parsed = YAML.load_file(file)
11
+ parsed = YAML.safe_load_file(file, permitted_classes: [Symbol], permitted_symbols: [], aliases: true)
12
12
  rescue StandardError => err
13
13
  PuppetCheck.files[:errors][file] = err.to_s.gsub("(#{file}): ", '').split("\n")
14
14
  else
@@ -44,7 +44,7 @@ class DataParser
44
44
 
45
45
  files.each do |file|
46
46
  # check encoded yaml syntax
47
- parsed = YAML.load_file(file)
47
+ parsed = YAML.safe_load_file(file, permitted_classes: [Symbol], permitted_symbols: [], aliases: true)
48
48
 
49
49
  # extract encoded values
50
50
  # ENC[PKCS7]
@@ -205,8 +205,7 @@ class DataParser
205
205
  end
206
206
 
207
207
  # checks hieradata
208
- def self.hiera(data, file)
209
- private_class_method :method
208
+ private_class_method def self.hiera(data, file)
210
209
  warnings = []
211
210
 
212
211
  # disregard nil/undef value data check if default values (common)
@@ -32,9 +32,7 @@ class OutputResults
32
32
  end
33
33
 
34
34
  # output the results as text
35
- def self.text(files)
36
- private_class_method :method
37
-
35
+ private_class_method def self.text(files)
38
36
  # output text for each of four file categories
39
37
  %i[errors warnings clean ignored].each do |category|
40
38
  # immediately return if category is empty
@@ -23,8 +23,7 @@ begin
23
23
  # end
24
24
 
25
25
  # config file loading
26
- def self.config(octoconfig)
27
- private_class_method :method
26
+ private_class_method def self.config(octoconfig)
28
27
  OctocatalogDiff::API::V1.config(filename: octoconfig)
29
28
  end
30
29
  end
@@ -29,8 +29,7 @@ class RSpecPuppetSupport
29
29
  end
30
30
 
31
31
  # setup the files, directories, and symlinks for rspec-puppet testing
32
- def self.file_setup(module_name)
33
- private_class_method :method
32
+ private_class_method def self.file_setup(module_name)
34
33
  # create all the necessary fixture dirs that are missing
35
34
  ['spec/fixtures', 'spec/fixtures/manifests', 'spec/fixtures/modules'].each do |dir|
36
35
  Dir.mkdir(dir) unless File.directory?(dir)
@@ -58,8 +57,7 @@ class RSpecPuppetSupport
58
57
  end
59
58
 
60
59
  # setup the module dependencies for rspec-puppet testing
61
- def self.dependency_setup
62
- private_class_method :method
60
+ private_class_method def self.dependency_setup
63
61
  require 'json'
64
62
 
65
63
  # parse the metadata.json (assumes DataParser.json has already given it a pass)
@@ -85,8 +83,7 @@ class RSpecPuppetSupport
85
83
  end
86
84
 
87
85
  # download external module dependency with git
88
- def self.git(git_url, args = '')
89
- private_class_method :method
86
+ private_class_method def self.git(git_url, args = '')
90
87
  # establish path to clone module to
91
88
  path = "spec/fixtures/modules/#{File.basename(git_url, '.git')}"
92
89
  # is the module present and already cloned with git? do a pull; otherwise, do a clone
@@ -98,16 +95,14 @@ class RSpecPuppetSupport
98
95
  end
99
96
 
100
97
  # download external module dependency with forge
101
- def self.forge(forge_name, args = '')
102
- private_class_method :method
98
+ private_class_method def self.forge(forge_name, args = '')
103
99
  # is the module present? do an upgrade; otherwise, do an install
104
100
  subcommand = File.directory?("spec/fixtures/modules/#{forge_name}") ? 'upgrade' : 'install'
105
101
  spawn("puppet module #{subcommand} --modulepath spec/fixtures/modules/ #{args} #{forge_name}")
106
102
  end
107
103
 
108
104
  # download external module dependency with svn
109
- def self.svn(svn_url, args = '')
110
- private_class_method :method
105
+ private_class_method def self.svn(svn_url, args = '')
111
106
  # establish path to checkout module to
112
107
  path = "spec/fixtures/modules/#{File.basename(svn_url)}"
113
108
  # is the module present and already checked out with svn? do an update; otherwise, do a checkout
@@ -119,8 +114,7 @@ class RSpecPuppetSupport
119
114
  end
120
115
 
121
116
  # download external module dependency with hg
122
- def self.hg(hg_url, args = '')
123
- private_class_method :method
117
+ private_class_method def self.hg(hg_url, args = '')
124
118
  # establish path to clone module to
125
119
  path = "spec/fixtures/modules/#{File.basename(hg_url)}"
126
120
  # is the module present and already cloned with hg? do a pull and update; otherwise do a clone
@@ -17,15 +17,14 @@ class RubyParser
17
17
 
18
18
  files.each do |file|
19
19
  # check ruby syntax
20
- # prevents ruby code from actually executing the input ruby file
21
- catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)} # BEGIN {throw :good}; ruby_file_content", file) }
20
+ RubyVM::InstructionSequence.compile_file(file)
22
21
  rescue ScriptError, StandardError => err
23
22
  PuppetCheck.files[:errors][file] = err.to_s.gsub("#{file}:", '').split("\n")
24
23
  else
25
24
  # check ruby style
26
25
  if style
27
26
  # check RuboCop and parse warnings' JSON output
28
- rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--require', 'rubocop-performance', '--format', 'json', file]) }
27
+ rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--plugin', 'rubocop-performance', '--plugin', 'rubocop-rspec', '--format', 'json', file]) }
29
28
  rubocop_offenses = JSON.parse(rubocop_warnings)['files'][0]['offenses'].map { |warning| "#{warning['location']['line']}:#{warning['location']['column']} #{warning['message']}" }
30
29
 
31
30
  # check Reek and parse warnings' JSON output
@@ -87,7 +86,7 @@ class RubyParser
87
86
  # check librarian puppet style
88
87
  else
89
88
  if style
90
- warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--require', 'rubocop-performance', '--format', 'json', file]) }
89
+ warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--plugin', 'rubocop-performance', '--format', 'json', file]) }
91
90
  offenses = JSON.parse(warnings)['files'][0]['offenses'].map { |warning| "#{warning['location']['line']}:#{warning['location']['column']} #{warning['message']}" }
92
91
 
93
92
  # collect style warnings
@@ -16,7 +16,8 @@ class PuppetCheck::Tasks < Rake::TaskLib
16
16
  namespace :puppetcheck do
17
17
  desc 'Execute Puppet-Check file checks'
18
18
  task :file, [:settings] do |_, wrapped_settings|
19
- PuppetCheck.new.run(wrapped_settings[:settings], Dir.glob('*'))
19
+ wrapped_settings = wrapped_settings[:settings] || {}
20
+ PuppetCheck.new.run(wrapped_settings, Dir.glob('*'))
20
21
  end
21
22
 
22
23
  # rspec and rspec-puppet tasks
@@ -1,22 +1,26 @@
1
+ require 'stringio'
2
+
1
3
  # utility methods totally not edited from StackOverflow
2
4
  class Utils
3
5
  # captures stdout from a block: out = capture_stdout { code }
4
6
  def self.capture_stdout
5
- old_stdout = $stdout
7
+ Thread.current[:old_stdout] = $stdout
6
8
  $stdout = StringIO.new
7
9
  yield
8
10
  $stdout.string
9
11
  ensure
10
- $stdout = old_stdout
12
+ $stdout = Thread.current[:old_stdout] if Thread.current[:old_stdout]
13
+ Thread.current[:old_stdout] = nil
11
14
  end
12
15
 
13
16
  # captures stderr from a block: err = capture_stderr { code }
14
17
  def self.capture_stderr
15
- old_stderr = $stderr
18
+ Thread.current[:old_stderr] = $stderr
16
19
  $stderr = StringIO.new
17
20
  yield
18
21
  $stderr.string
19
22
  ensure
20
- $stderr = old_stderr
23
+ $stderr = Thread.current[:old_stderr] if Thread.current[:old_stderr]
24
+ Thread.current[:old_stderr] = nil
21
25
  end
22
26
  end
data/lib/puppet_check.rb CHANGED
@@ -33,7 +33,7 @@ class PuppetCheck
33
33
  OutputResults.run(parsed_files.clone, settings[:output_format])
34
34
 
35
35
  # progress to regression checks if no errors in file checks
36
- if parsed_files[:errors].empty? && (!settings[:fail_on_warning] || parsed_files[:warnings].empty?)
36
+ if parsed_files[:errors].empty? && (!settings[:fail_on_warnings] || parsed_files[:warnings].empty?)
37
37
  begin
38
38
  require_relative 'puppet-check/regression_check'
39
39
 
@@ -68,10 +68,10 @@ class PuppetCheck
68
68
  end
69
69
  end
70
70
 
71
+ private
72
+
71
73
  # establish default settings
72
74
  def self.defaults(settings = {})
73
- private_class_method :method
74
-
75
75
  # return settings with defaults where unspecified
76
76
  {
77
77
  # initialize fail on warning, style check, and regression check bools
@@ -95,7 +95,6 @@ class PuppetCheck
95
95
 
96
96
  # parse the paths and return the array of files
97
97
  def self.parse_paths(paths = [])
98
- private_class_method :method
99
98
  files = []
100
99
 
101
100
  # traverse the unique paths and return all files not explicitly in fixtures
@@ -115,8 +114,6 @@ class PuppetCheck
115
114
  files.map { |file| file.gsub('//', '/') }.uniq
116
115
  end
117
116
 
118
- private
119
-
120
117
  # categorize and pass the files out to the parsers to determine their status
121
118
  def execute_parsers(files, style, puppetlint_args, rubocop_args, public, private)
122
119
  # check manifests
@@ -141,7 +138,7 @@ class PuppetCheck
141
138
  eyamls, files = files.partition { |file| File.extname(file) =~ /\.eya?ml$/ }
142
139
  DataParser.eyaml(eyamls, public, private) unless eyamls.empty?
143
140
  # check misc ruby
144
- librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem|Vagrant)file|.gemspec$/ }
141
+ librarians, files = files.partition { |file| File.basename(file) =~ /^(?:Puppet|Module|Rake|Gem|Vagrant)file|\.gemspec$/ && File.extname(file) != '.lock' }
145
142
  RubyParser.librarian(librarians, style, rubocop_args) unless librarians.empty?
146
143
  # ignore everything else
147
144
  files.each { |file| self.class.files[:ignored].push(file.to_s) }
data/puppet-check.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'puppet-check'
3
- spec.version = '2.3.1'
3
+ spec.version = '2.4.0'
4
4
  spec.authors = ['Matt Schuchard']
5
5
  spec.description = 'Puppet Check is a gem that provides a comprehensive, streamlined, and efficient analysis of the syntax, style, and validity of your entire Puppet code and data.'
6
6
  spec.summary = 'A streamlined comprehensive set of checks for your entire Puppet code and data'
@@ -11,12 +11,13 @@ Gem::Specification.new do |spec|
11
11
  spec.executables = spec.files.grep(%r{^bin/}) { |file| File.basename(file) }
12
12
  spec.require_paths = Dir['lib']
13
13
 
14
- spec.required_ruby_version = '>= 2.7.0'
14
+ spec.required_ruby_version = '>= 3.0.0'
15
15
  spec.add_dependency 'puppet', '>= 5.5', '< 9'
16
16
  spec.add_dependency 'puppet-lint', '~> 4.0'
17
17
  spec.add_dependency 'reek', '~> 6.0'
18
- spec.add_dependency 'rubocop', '~> 1.0'
18
+ spec.add_dependency 'rubocop', '~> 1.72'
19
19
  spec.add_dependency 'rubocop-performance', '~> 1.0'
20
+ spec.add_dependency 'rubocop-rspec', '~> 3.0'
20
21
  # spec.add_development_dependency 'octocatalog-diff', '~> 2.0'
21
22
  spec.add_development_dependency 'rake', '~> 13.0'
22
23
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -6,45 +6,49 @@ describe PuppetCheck::CLI do
6
6
  it 'targets the current working directory if no paths were specified' do
7
7
  expect { PuppetCheck::CLI.run(%w[--fail-on-warnings]) }.not_to raise_exception
8
8
  expect(PuppetCheck.files[:clean].length).to eql(30)
9
- expect(PuppetCheck.files[:ignored].length).to eql(7)
9
+ if ci_env
10
+ expect(PuppetCheck.files[:ignored].length).to eql(8)
11
+ else
12
+ expect(PuppetCheck.files[:ignored].length).to eql(7)
13
+ end
10
14
  end
11
15
  end
12
16
 
13
17
  context '.parse' do
14
18
  it 'raises an error if an invalid option was specified' do
15
- expect { PuppetCheck::CLI.parse(%w[-s -asdf foo]) }.to raise_error(OptionParser::InvalidOption)
19
+ expect { PuppetCheck::CLI.send(:parse, %w[-s -asdf foo]) }.to raise_error(OptionParser::InvalidOption)
16
20
  end
17
21
 
18
22
  it 'allows fail on warnings, style, smoke, and regression checks to be enabled' do
19
- expect(PuppetCheck::CLI.parse(%w[--fail-on-warnings -s -r --smoke foo])).to include(fail_on_warnings: true, style: true, smoke: true, regression: true)
23
+ expect(PuppetCheck::CLI.send(:parse, %w[--fail-on-warnings -s -r --smoke foo])).to include(fail_on_warnings: true, style: true, smoke: true, regression: true)
20
24
  end
21
25
 
22
26
  it 'correctly parser EYAML options' do
23
- expect(PuppetCheck::CLI.parse(%w[--public pub.pem --private priv.pem])).to include(public: 'pub.pem', private: 'priv.pem')
27
+ expect(PuppetCheck::CLI.send(:parse, %w[--public pub.pem --private priv.pem])).to include(public: 'pub.pem', private: 'priv.pem')
24
28
  end
25
29
 
26
30
  it 'correctly parses a formatting option' do
27
- expect(PuppetCheck::CLI.parse(%w[-o text])).to include(output_format: 'text')
31
+ expect(PuppetCheck::CLI.send(:parse, %w[-o text])).to include(output_format: 'text')
28
32
  end
29
33
 
30
34
  it 'correctly parses octocatalog-diff options' do
31
- expect(PuppetCheck::CLI.parse(%w[--octoconfig config.cfg.rb --octonodes server1,server2])).to include(octoconfig: 'config.cfg.rb', octonodes: %w[server1 server2])
35
+ expect(PuppetCheck::CLI.send(:parse, %w[--octoconfig config.cfg.rb --octonodes server1,server2])).to include(octoconfig: 'config.cfg.rb', octonodes: %w[server1 server2])
32
36
  end
33
37
 
34
38
  it 'correctly parses PuppetLint arguments' do
35
- expect(PuppetCheck::CLI.parse(%w[--puppet-lint puppetlint-arg-one,puppetlint-arg-two foo])).to include(puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'])
39
+ expect(PuppetCheck::CLI.send(:parse, %w[--puppet-lint puppetlint-arg-one,puppetlint-arg-two foo])).to include(puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'])
36
40
  end
37
41
 
38
42
  it 'correctly loads a .puppet-lint.rc' do
39
- expect(PuppetCheck::CLI.parse(%W[-c #{fixtures_dir}/manifests/.puppet-lint.rc])).to include(puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'])
43
+ expect(PuppetCheck::CLI.send(:parse, %W[-c #{fixtures_dir}/manifests/.puppet-lint.rc])).to include(puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'])
40
44
  end
41
45
 
42
46
  it 'correctly parses Rubocop arguments' do
43
- expect(PuppetCheck::CLI.parse(%w[--rubocop rubocop-arg-one,rubocop-arg-two foo])).to include(rubocop_args: ['--except', 'rubocop-arg-one,rubocop-arg-two'])
47
+ expect(PuppetCheck::CLI.send(:parse, %w[--rubocop rubocop-arg-one,rubocop-arg-two foo])).to include(rubocop_args: ['--except', 'rubocop-arg-one,rubocop-arg-two'])
44
48
  end
45
49
 
46
50
  it 'correctly parses multiple sets of arguments' do
47
- expect(PuppetCheck::CLI.parse(%w[-s --puppet-lint puppetlint-arg-one,puppetlint-arg-two --rubocop rubocop-arg-one,rubocop-arg-two foo])).to include(style: true, puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'], rubocop_args: ['--except', 'rubocop-arg-one,rubocop-arg-two'])
51
+ expect(PuppetCheck::CLI.send(:parse, %w[-s --puppet-lint puppet-lint-arg-one,puppet-lint-arg-two --rubocop rubocop-arg-one,rubocop-arg-two foo])).to include(style: true, puppetlint_args: ['--puppet-lint-arg-one', '--puppet-lint-arg-two'], rubocop_args: ['--except', 'rubocop-arg-one,rubocop-arg-two'])
48
52
  end
49
53
  end
50
54
  end
@@ -5,19 +5,19 @@ describe OutputResults do
5
5
  context '.text' do
6
6
  it 'outputs files with errors' do
7
7
  files = { errors: { 'foo' => ['i had an error'] } }
8
- expect { OutputResults.text(files) }.to output("\033[31mThe following files have errors:\033[0m\n-- foo:\ni had an error\n\n").to_stdout
8
+ expect { OutputResults.send(:text, files) }.to output("\033[31mThe following files have errors:\033[0m\n-- foo:\ni had an error\n\n").to_stdout
9
9
  end
10
10
  it 'outputs files with warnings' do
11
11
  files = { warnings: { 'foo' => ['i had a warning'] } }
12
- expect { OutputResults.text(files) }.to output("\033[33mThe following files have warnings:\033[0m\n-- foo:\ni had a warning\n\n").to_stdout
12
+ expect { OutputResults.send(:text, files) }.to output("\033[33mThe following files have warnings:\033[0m\n-- foo:\ni had a warning\n\n").to_stdout
13
13
  end
14
14
  it 'outputs files with no errors or warnings' do
15
15
  files = { clean: ['foo'] }
16
- expect { OutputResults.text(files) }.to output("\033[32mThe following files have no errors or warnings:\033[0m\n-- foo\n\n").to_stdout
16
+ expect { OutputResults.send(:text, files) }.to output("\033[32mThe following files have no errors or warnings:\033[0m\n-- foo\n\n").to_stdout
17
17
  end
18
18
  it 'outputs files that were not processed' do
19
19
  files = { ignored: ['foo'] }
20
- expect { OutputResults.text(files) }.to output("\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- foo\n\n").to_stdout
20
+ expect { OutputResults.send(:text, files) }.to output("\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- foo\n\n").to_stdout
21
21
  end
22
22
  end
23
23
 
@@ -7,10 +7,10 @@ begin
7
7
  context '.config' do
8
8
  # json gem is messed up for the EOL Ruby versions
9
9
  it 'raise an appropriate error if the file is malformed' do
10
- expect { RegressionCheck.config("#{fixtures_dir}metadata.json") }.to raise_error(OctocatalogDiff::Errors::ConfigurationFileContentError, 'Configuration must define OctocatalogDiff::Config!')
10
+ expect { RegressionCheck.send(:config, "#{fixtures_dir}metadata.json") }.to raise_error(OctocatalogDiff::Errors::ConfigurationFileContentError, 'Configuration must define OctocatalogDiff::Config!')
11
11
  end
12
12
  it 'loads in a good octocatalog-diff config file' do
13
- expect { RegressionCheck.config("#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
13
+ expect { RegressionCheck.send(:config, "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
14
14
  end
15
15
  it 'loads in the settings from the file correctly' do
16
16
  # TODO
@@ -19,7 +19,7 @@ begin
19
19
 
20
20
  context '.smoke' do
21
21
  # octocatalog-diff is returning a blank error for these tests
22
- unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
22
+ unless ci_env
23
23
  it 'returns a pass for a successful catalog compilation' do
24
24
  expect { RegressionCheck.smoke(['good.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
25
25
  end
@@ -15,7 +15,7 @@ describe RSpecPuppetSupport do
15
15
 
16
16
  it 'creates missing directories, missing site.pp, missing symlinks, and a missing spec_helper' do
17
17
  # circle ci and gh actions
18
- if ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
18
+ if ci_env
19
19
  expect { rspec_puppet_setup }.to output("git is not installed and cannot be used to retrieve dependency modules\nsubversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
20
20
  else
21
21
  expect { rspec_puppet_setup }.to output("subversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
@@ -29,7 +29,7 @@ describe RSpecPuppetSupport do
29
29
  expect(File.file?('spec/spec_helper.rb')).to be true
30
30
 
31
31
  # .dependency_setup
32
- expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
32
+ expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless ci_env
33
33
  expect(File.directory?('spec/fixtures/modules/stdlib')).to be true
34
34
  end
35
35
  end
@@ -23,7 +23,11 @@ describe RubyParser do
23
23
  RubyParser.ruby(["#{fixtures_dir}lib/style.rb"], true, [])
24
24
  expect(PuppetCheck.files[:errors]).to eql({})
25
25
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}lib/style.rb"])
26
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment/)
26
+ unless ci_env
27
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment/)
28
+ else
29
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty/)
30
+ end
27
31
  expect(PuppetCheck.files[:clean]).to eql([])
28
32
  end
29
33
  it 'puts a bad style ruby file in the clean files array when rubocop_args ignores its warnings' do
@@ -75,30 +79,30 @@ describe RubyParser do
75
79
 
76
80
  context '.librarian' do
77
81
  it 'puts a bad syntax librarian Puppet file in the error files hash' do
78
- RubyParser.librarian(["#{fixtures_dir}librarian_syntax/Puppetfile"], false, [])
79
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}librarian_syntax/Puppetfile"])
80
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}librarian_syntax/Puppetfile"].join("\n")).to match(/^.*syntax error/)
82
+ RubyParser.librarian(["#{fixtures_dir}librarian/Puppetfile_syntax"], false, [])
83
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}librarian/Puppetfile_syntax"])
84
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}librarian/Puppetfile_syntax"].join("\n")).to match(/^.*syntax error/)
81
85
  expect(PuppetCheck.files[:warnings]).to eql({})
82
86
  expect(PuppetCheck.files[:clean]).to eql([])
83
87
  end
84
88
  it 'puts a bad style librarian Puppet file in the warning files array' do
85
- RubyParser.librarian(["#{fixtures_dir}librarian_style/Puppetfile"], true, [])
89
+ RubyParser.librarian(["#{fixtures_dir}librarian/Puppetfile_style"], true, [])
86
90
  expect(PuppetCheck.files[:errors]).to eql({})
87
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}librarian_style/Puppetfile"])
88
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}librarian_style/Puppetfile"].join("\n")).to match(/Align the arguments.*\n.*Use the new/)
91
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}librarian/Puppetfile_style"])
92
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}librarian/Puppetfile_style"].join("\n")).to match(/Align the arguments.*\n.*Use the new/)
89
93
  expect(PuppetCheck.files[:clean]).to eql([])
90
94
  end
91
95
  it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
92
- RubyParser.librarian(["#{fixtures_dir}librarian_style/Puppetfile"], true, ['--except', 'Layout/ArgumentAlignment,Style/HashSyntax'])
96
+ RubyParser.librarian(["#{fixtures_dir}librarian/Puppetfile_style"], true, ['--except', 'Layout/ArgumentAlignment,Style/HashSyntax'])
93
97
  expect(PuppetCheck.files[:errors]).to eql({})
94
98
  expect(PuppetCheck.files[:warnings]).to eql({})
95
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}librarian_style/Puppetfile"])
99
+ expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}librarian/Puppetfile_style"])
96
100
  end
97
101
  it 'puts a good librarian Puppet file in the clean files array' do
98
- RubyParser.librarian(["#{fixtures_dir}librarian_good/Puppetfile"], true, [])
102
+ RubyParser.librarian(["#{fixtures_dir}librarian/Puppetfile_good"], true, [])
99
103
  expect(PuppetCheck.files[:errors]).to eql({})
100
104
  expect(PuppetCheck.files[:warnings]).to eql({})
101
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}librarian_good/Puppetfile"])
105
+ expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}librarian/Puppetfile_good"])
102
106
  end
103
107
  end
104
108
  end
@@ -33,7 +33,7 @@ describe PuppetCheck do
33
33
 
34
34
  context 'defaults' do
35
35
  it 'returns defaults correctly' do
36
- expect(PuppetCheck.defaults).to eql(
36
+ expect(PuppetCheck.send(:defaults)).to eql(
37
37
  {
38
38
  fail_on_warning: false,
39
39
  style: false,
@@ -64,18 +64,18 @@ describe PuppetCheck do
64
64
  puppetlint_args: %w[--puppetlint-arg-one --puppetlint-arg-two],
65
65
  rubocop_args: %w[--rubocop-arg-one --rubocop-arg-two]
66
66
  }
67
- expect(PuppetCheck.defaults(settings)).to eql(settings)
67
+ expect(PuppetCheck.send(:defaults, settings)).to eql(settings)
68
68
  end
69
69
  end
70
70
 
71
71
  context '.parse_paths' do
72
72
  before(:each) { Dir.chdir(fixtures_dir) }
73
73
 
74
- let(:no_files) { PuppetCheck.parse_paths(%w[foo bar baz]) }
75
- let(:file) { PuppetCheck.parse_paths(['lib/good.rb']) }
76
- let(:dir) { PuppetCheck.parse_paths(['.']) }
77
- let(:multi_dir) { PuppetCheck.parse_paths(%w[hieradata lib manifests]) }
78
- let(:repeats) { PuppetCheck.parse_paths(['hieradata', 'hieradata', 'lib', 'hieradata/good.json', 'manifests/good.pp', 'manifests/good.pp']) }
74
+ let(:no_files) { PuppetCheck.send(:parse_paths, %w[foo bar baz]) }
75
+ let(:file) { PuppetCheck.send(:parse_paths, ['lib/good.rb']) }
76
+ let(:dir) { PuppetCheck.send(:parse_paths, ['.']) }
77
+ let(:multi_dir) { PuppetCheck.send(:parse_paths, %w[hieradata lib manifests]) }
78
+ let(:repeats) { PuppetCheck.send(:parse_paths, ['hieradata', 'hieradata', 'lib', 'hieradata/good.json', 'manifests/good.pp', 'manifests/good.pp']) }
79
79
 
80
80
  it 'raises an error if no files were found' do
81
81
  expect { no_files }.to raise_error(RuntimeError, 'puppet-check: no files found in supplied paths \'foo, bar, baz\'.')
@@ -87,7 +87,7 @@ describe PuppetCheck do
87
87
 
88
88
  it 'correctly parses one directory and returns all of its files' do
89
89
  dir.each { |file| expect(File.file?(file)).to be true }
90
- if ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
90
+ if ci_env
91
91
  expect(dir.length).to eql(37)
92
92
  else
93
93
  expect(dir.length).to eql(40)
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,10 @@ module Variables
11
11
  def octocatalog_diff_dir
12
12
  @octocatalog_diff_dir = "#{File.dirname(__FILE__)}/octocatalog-diff/"
13
13
  end
14
+
15
+ def ci_env
16
+ @ci_env = ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
17
+ end
14
18
  end
15
19
 
16
20
  RSpec.configure do |config|
@@ -5,24 +5,20 @@ require_relative '../../lib/puppet-check/tasks'
5
5
 
6
6
  describe PuppetCheck do
7
7
  context 'executed as a system from the CLI with arguments and various files to be processed' do
8
- # see regression_check_spec
9
- if ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
10
- let(:cli) { PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --public keys/public_key.pkcs7.pem --private keys/private_key.pkcs7.pem .]) }
11
- else
12
- let(:cli) { PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --public keys/public_key.pkcs7.pem --private keys/private_key.pkcs7.pem --smoke -n good.example.com --octoconfig spec/octocatalog-diff/octocatalog-diff.cfg.rb .]) }
13
- end
14
-
15
8
  it 'outputs diagnostic results correctly after processing all of the files' do
16
9
  Dir.chdir(fixtures_dir)
17
10
 
18
- expect { cli }.not_to raise_exception
11
+ # see regression_check_spec
12
+ if ci_env
13
+ expect(PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --public keys/public_key.pkcs7.pem --private keys/private_key.pkcs7.pem .])).to eql(2)
14
+ else
15
+ expect(PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --public keys/public_key.pkcs7.pem --private keys/private_key.pkcs7.pem --smoke -n good.example.com --octoconfig spec/octocatalog-diff/octocatalog-diff.cfg.rb .])).to eql(2)
16
+ end
19
17
 
20
18
  expect(PuppetCheck.files[:errors].length).to eql(11)
21
- expect(PuppetCheck.files[:warnings].length).to eql(12)
22
- expect(PuppetCheck.files[:clean].length).to eql(14)
19
+ expect(PuppetCheck.files[:warnings].length).to eql(13)
20
+ expect(PuppetCheck.files[:clean].length).to eql(13)
23
21
  expect(PuppetCheck.files[:ignored].length).to eql(3)
24
-
25
- expect(cli).to eql(2)
26
22
  end
27
23
  end
28
24
 
@@ -38,16 +34,9 @@ describe PuppetCheck do
38
34
  clean: [],
39
35
  ignored: []
40
36
  }
41
- settings = { style: true }
42
- # see regression_check_spec
43
- unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
44
- settings[:smoke] = true
45
- settings[:octonodes] = %w[good.example.com]
46
- settings[:octoconfig] = 'spec/octocatalog-diff/octocatalog-diff.cfg.rb'
47
- end
48
37
 
49
38
  # cannot re-use plan fixture between system tests
50
- expect { Rake::Task[:'puppetcheck:file'].invoke(settings) }.to raise_error(ArgumentError, /Attempt to redefine entity/)
39
+ expect { Rake::Task[:'puppetcheck:file'].execute }.to raise_error(ArgumentError, /Attempt to redefine entity/)
51
40
 
52
41
  # current puppet pops limitations no longer allow testing this
53
42
  # expect(PuppetCheck.files[:errors].length).to eql(11)
@@ -55,5 +44,36 @@ describe PuppetCheck do
55
44
  # expect(PuppetCheck.files[:clean].length).to eql(14)
56
45
  # expect(PuppetCheck.files[:ignored].length).to eql(3)
57
46
  end
47
+
48
+ it 'uses override settings and outputs diagnostic results correctly after processing all of the files' do
49
+ # ensure rake only checks the files inside fixtures
50
+ Dir.chdir(fixtures_dir)
51
+
52
+ # clear out files member from previous system test
53
+ PuppetCheck.files = {
54
+ errors: {},
55
+ warnings: {},
56
+ clean: [],
57
+ ignored: []
58
+ }
59
+
60
+ # assign settings
61
+ settings = { style: true }
62
+ # see regression_check_spec
63
+ unless ci_env
64
+ settings[:smoke] = true
65
+ settings[:octonodes] = %w[good.example.com]
66
+ settings[:octoconfig] = 'spec/octocatalog-diff/octocatalog-diff.cfg.rb'
67
+ end
68
+
69
+ # cannot re-use plan fixture between system tests
70
+ expect { Rake::Task[:'puppetcheck:file'].invoke(settings) }.to raise_error(ArgumentError, /Attempt to redefine entity/)
71
+
72
+ # current puppet pops limitations no longer allow testing this
73
+ # expect(PuppetCheck.files[:errors].length).to eql(11)
74
+ # expect(PuppetCheck.files[:warnings].length).to eql(12)
75
+ # expect(PuppetCheck.files[:clean].length).to eql(14)
76
+ # expect(PuppetCheck.files[:ignored].length).to eql(3)
77
+ end
58
78
  end
59
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Schuchard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-09 00:00:00.000000000 Z
11
+ date: 2025-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '1.0'
67
+ version: '1.72'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '1.0'
74
+ version: '1.72'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rubocop-performance
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '1.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop-rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: rake
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -153,9 +167,9 @@ files:
153
167
  - spec/fixtures/lib/rubocop_style.rb
154
168
  - spec/fixtures/lib/style.rb
155
169
  - spec/fixtures/lib/syntax.rb
156
- - spec/fixtures/librarian_good/Puppetfile
157
- - spec/fixtures/librarian_style/Puppetfile
158
- - spec/fixtures/librarian_syntax/Puppetfile
170
+ - spec/fixtures/librarian/Puppetfile_good
171
+ - spec/fixtures/librarian/Puppetfile_style
172
+ - spec/fixtures/librarian/Puppetfile_syntax
159
173
  - spec/fixtures/manifests/eof_syntax.pp
160
174
  - spec/fixtures/manifests/good.pp
161
175
  - spec/fixtures/manifests/style_lint.pp
@@ -207,7 +221,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
221
  requirements:
208
222
  - - ">="
209
223
  - !ruby/object:Gem::Version
210
- version: 2.7.0
224
+ version: 3.0.0
211
225
  required_rubygems_version: !ruby/object:Gem::Requirement
212
226
  requirements:
213
227
  - - ">="