puppet-check 2.3.0 → 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: caea7da11b0b884512bc9e078c71caece3bfb2045f5798c55b41201b948e5d3f
4
- data.tar.gz: 6e4eae239a2cbbeda1709741c523161720dd8b28399d9e1e5cae6add54cef59b
3
+ metadata.gz: c5c74c1af6aee54ad5dcfd3eeefa459ed9fd5eaaafdc847f346a8e3674ffb362
4
+ data.tar.gz: c11db9238470434a489608d62360d12fe1ff10dda29627a05cdded940785b992
5
5
  SHA512:
6
- metadata.gz: 18d8d802b337a1b47de63aa25a4f0c2b7e6f6f6678047b2f941a28766ee7d1a18f07244b287faf37747170d170230dfb58073f67a63dce95513421acd125ca5a
7
- data.tar.gz: '09031de8c432747e7967241ff0abd4290d34d38892eb4df0443e3f7e88acd5d30c177fbabf811a6958874533fe951ea795965acea0617d21e0f2f28832987e17'
6
+ metadata.gz: 12416f0a0d2d2615c467645cb238e0b14be8f42c9172e5adf7acf3bfbdddbdae1d5b08ccd2a967dcb7b6af41a8149f2e30e22ed5d0db97c5f05e586e384c4a61
7
+ data.tar.gz: 053f4f90842f2d71ccbc82a3b05cd5ef1347af5399686fc3ed4a7cbf824baeee63ad412c1d6261f3640929bdcba789db7e2fe46d7f3e529cf3cd6b1c8b9690d8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
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
+
11
+ ### 2.3.1
12
+ - No input target paths now defaults to current working directory instead of error.
13
+ - Additionally check `Vagrantfile` and `gemspec` files.
14
+ - Fix and improve behavior for when optional dependency `octocatalog-diff` is absent.
15
+
1
16
  ### 2.3.0
2
17
  - Minimum Ruby version increased to 2.7.
3
18
  - Support Puppet 8.
@@ -6,15 +6,16 @@ class PuppetCheck::CLI
6
6
  def self.run(args)
7
7
  # gather the user arguments
8
8
  settings = parse(args)
9
- raise 'puppet-check: no file paths specified; try using --help' if args.empty?
9
+
10
+ # target cwd if no paths input as variadic
11
+ args = [Dir.pwd] if args.empty?
10
12
 
11
13
  # run PuppetCheck with specified paths
12
14
  PuppetCheck.new.run(settings, args)
13
15
  end
14
16
 
15
17
  # parse the user arguments
16
- def self.parse(args)
17
- private_class_method :method
18
+ private_class_method def self.parse(args)
18
19
  require 'optparse'
19
20
 
20
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)
@@ -2,6 +2,13 @@ require_relative '../puppet_check'
2
2
 
3
3
  # class to handle outputting diagnostic results in desired format
4
4
  class OutputResults
5
+ HEADER = {
6
+ errors: "\033[31mThe following files have errors:\033[0m\n",
7
+ warnings: "\033[33mThe following files have warnings:\033[0m\n",
8
+ clean: "\033[32mThe following files have no errors or warnings:\033[0m\n-- ",
9
+ ignored: "\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- "
10
+ }.freeze
11
+
5
12
  # output the results in various formats
6
13
  def self.run(files, format)
7
14
  # remove empty entries
@@ -25,34 +32,27 @@ class OutputResults
25
32
  end
26
33
 
27
34
  # output the results as text
28
- def self.text(files)
29
- private_class_method :method
30
-
31
- # errors
32
- category_info("\033[31mThe following files have errors:\033[0m\n", files[:errors]) if files.key?(:errors)
33
- # warnings
34
- category_info("\033[33mThe following files have warnings:\033[0m\n", files[:warnings]) if files.key?(:warnings)
35
- # cleans
36
- category_info("\033[32mThe following files have no errors or warnings:\033[0m\n-- ", files[:clean]) if files.key?(:clean)
37
- # ignores
38
- return unless files.key?(:ignored)
39
- category_info("\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- ", files[:ignored])
40
- end
35
+ private_class_method def self.text(files)
36
+ # output text for each of four file categories
37
+ %i[errors warnings clean ignored].each do |category|
38
+ # immediately return if category is empty
39
+ next unless files.key?(category)
41
40
 
42
- # display heading, files, and file messages per category for text formatting
43
- def self.category_info(heading, files)
44
- private_class_method :method
45
- # display category heading
46
- print heading
47
-
48
- # display files and optionally messages
49
- case files
50
- when Hash then files.each { |file, messages| puts "-- #{file}:\n#{messages.join("\n")}" }
51
- when Array then puts files.join("\n-- ")
52
- else raise "puppet-check: The category files were of unexpected type #{files.class}. Please file an issue with this log message, category heading, and information about the parsed files."
53
- end
41
+ # display heading, files, and file messages per category for text formatting
42
+ category_files = files[category]
54
43
 
55
- # newline between categories for easier visual parsing
56
- puts ''
44
+ # display category heading
45
+ print HEADER[category]
46
+
47
+ # display files and optionally messages
48
+ case category_files
49
+ when Hash then category_files.each { |file, messages| puts "-- #{file}:\n#{messages.join("\n")}" }
50
+ when Array then puts category_files.join("\n-- ")
51
+ else raise "puppet-check: The files category was of unexpected type #{category_files.class}. Please file an issue with this log message, category heading, and information about the parsed files."
52
+ end
53
+
54
+ # newline between categories for easier visual parsing
55
+ puts ''
56
+ end
57
57
  end
58
58
  end
@@ -1,29 +1,33 @@
1
- # temporarily supress warning messages for octocatalog-diff redefining puppet constants and then reactivate
2
- $VERBOSE = nil
3
- require 'octocatalog-diff'
4
- $VERBOSE = false
1
+ begin
2
+ # temporarily supress warning messages for octocatalog-diff redefining puppet constants and then reactivate
3
+ $VERBOSE = nil
4
+ require 'octocatalog-diff'
5
+ $VERBOSE = false
5
6
 
6
- # executes smoke and regression tests on catalogs
7
- class RegressionCheck
8
- # smoke testing
9
- def self.smoke(interface_nodes, octoconfig)
10
- options = config(octoconfig)
11
- nodes = options.key?(:node) ? [options[:node]] : interface_nodes
12
- nodes.each do |node|
13
- options[:node] = node
14
- OctocatalogDiff::API::V1.catalog(options)
7
+ # executes smoke and regression tests on catalogs
8
+ class RegressionCheck
9
+ # smoke testing
10
+ def self.smoke(interface_nodes, octoconfig)
11
+ options = config(octoconfig)
12
+ nodes = options.key?(:node) ? [options[:node]] : interface_nodes
13
+ nodes.each do |node|
14
+ options[:node] = node
15
+ OctocatalogDiff::API::V1.catalog(options)
16
+ end
15
17
  end
16
- end
17
18
 
18
- # regression testing
19
- # def self.regression(nodes, octoconfig)
20
- # options = RegressionCheck.config(octoconfig)
21
- # nodes.each { |node| stuff }
22
- # end
19
+ # regression testing
20
+ # def self.regression(nodes, octoconfig)
21
+ # options = RegressionCheck.config(octoconfig)
22
+ # nodes.each { |node| stuff }
23
+ # end
23
24
 
24
- # config file loading
25
- def self.config(octoconfig)
26
- private_class_method :method
27
- OctocatalogDiff::API::V1.config(filename: octoconfig)
25
+ # config file loading
26
+ private_class_method def self.config(octoconfig)
27
+ OctocatalogDiff::API::V1.config(filename: octoconfig)
28
+ end
28
29
  end
30
+ rescue LoadError
31
+ warn 'puppet-check: octocatalog-diff is not installed, and therefore the regression checks will be skipped'
32
+ $VERBOSE = false
29
33
  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
21
- catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)}", 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
@@ -80,14 +79,14 @@ class RubyParser
80
79
 
81
80
  files.each do |file|
82
81
  # check librarian puppet syntax
83
- # prevents ruby code from actually executing
84
- catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)}", file) }
82
+ # prevents ruby code from actually executing the input ruby file
83
+ catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)} # BEGIN {throw :good}; ruby_file_content", file) }
85
84
  rescue SyntaxError, LoadError, ArgumentError => err
86
85
  PuppetCheck.files[:errors][file] = err.to_s.gsub("#{file}:", '').split("\n")
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,18 +33,15 @@ 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
- # if octocatalog-diff is not installed then return immediately
40
- rescue LoadError
41
- warn 'octocatalog-diff is not installed, and therefore the regressions check will be skipped'
42
- return 0
43
- end
44
39
 
45
- # perform smoke checks if there were no errors and the user desires
46
- begin
40
+ # perform smoke checks if there were no errors and the user desires
47
41
  catalog = RegressionCheck.smoke(settings[:octonodes], settings[:octoconfig]) if settings[:smoke]
42
+ # if octocatalog-diff is not installed then continue immediately
43
+ rescue NameError
44
+ puts 'puppet-check: immediately continuing to results'
48
45
  # smoke check failure? output message and return 2
49
46
  rescue OctocatalogDiff::Errors::CatalogError => err
50
47
  puts 'There was a smoke check error:'
@@ -61,6 +58,7 @@ class PuppetCheck
61
58
  # puts catalog.error_message unless catalog.valid?
62
59
  # 2
63
60
  # end
61
+
64
62
  # code to output differences in catalog?
65
63
  # everything passed? return 0
66
64
  0
@@ -70,10 +68,10 @@ class PuppetCheck
70
68
  end
71
69
  end
72
70
 
71
+ private
72
+
73
73
  # establish default settings
74
74
  def self.defaults(settings = {})
75
- private_class_method :method
76
-
77
75
  # return settings with defaults where unspecified
78
76
  {
79
77
  # initialize fail on warning, style check, and regression check bools
@@ -97,7 +95,6 @@ class PuppetCheck
97
95
 
98
96
  # parse the paths and return the array of files
99
97
  def self.parse_paths(paths = [])
100
- private_class_method :method
101
98
  files = []
102
99
 
103
100
  # traverse the unique paths and return all files not explicitly in fixtures
@@ -117,8 +114,6 @@ class PuppetCheck
117
114
  files.map { |file| file.gsub('//', '/') }.uniq
118
115
  end
119
116
 
120
- private
121
-
122
117
  # categorize and pass the files out to the parsers to determine their status
123
118
  def execute_parsers(files, style, puppetlint_args, rubocop_args, public, private)
124
119
  # check manifests
@@ -143,7 +138,7 @@ class PuppetCheck
143
138
  eyamls, files = files.partition { |file| File.extname(file) =~ /\.eya?ml$/ }
144
139
  DataParser.eyaml(eyamls, public, private) unless eyamls.empty?
145
140
  # check misc ruby
146
- librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
141
+ librarians, files = files.partition { |file| File.basename(file) =~ /^(?:Puppet|Module|Rake|Gem|Vagrant)file|\.gemspec$/ && File.extname(file) != '.lock' }
147
142
  RubyParser.librarian(librarians, style, rubocop_args) unless librarians.empty?
148
143
  # ignore everything else
149
144
  files.each { |file| self.class.files[:ignored].push(file.to_s) }
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'puppet-check'
3
+ spec.version = '2.4.0'
4
+ spec.authors = ['Matt Schuchard']
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
+ spec.summary = 'A streamlined comprehensive set of checks for your entire Puppet code and data'
7
+ spec.homepage = 'https://www.github.com/mschuchard/puppet-check'
8
+ spec.license = 'MIT'
9
+
10
+ spec.files = Dir['bin/**/*', 'lib/**/*', 'spec/**/*', 'CHANGELOG.md', 'LICENSE.md', 'README.md', 'puppet-check.gemspec']
11
+ spec.executables = spec.files.grep(%r{^bin/}) { |file| File.basename(file) }
12
+ spec.require_paths = Dir['lib']
13
+
14
+ spec.required_ruby_version = '>= 3.0.0'
15
+ spec.add_dependency 'puppet', '>= 5.5', '< 9'
16
+ spec.add_dependency 'puppet-lint', '~> 4.0'
17
+ spec.add_dependency 'reek', '~> 6.0'
18
+ spec.add_dependency 'rubocop', '~> 1.72'
19
+ spec.add_dependency 'rubocop-performance', '~> 1.0'
20
+ spec.add_dependency 'rubocop-rspec', '~> 3.0'
21
+ # spec.add_development_dependency 'octocatalog-diff', '~> 2.0'
22
+ spec.add_development_dependency 'rake', '~> 13.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ end
@@ -3,46 +3,52 @@ require_relative '../../lib/puppet-check/cli'
3
3
 
4
4
  describe PuppetCheck::CLI do
5
5
  context '.run' do
6
- it 'raises an error if no paths were specified' do
7
- expect { PuppetCheck::CLI.run(%w[-s -f]) }.to raise_error(RuntimeError, 'puppet-check: no file paths specified; try using --help')
6
+ it 'targets the current working directory if no paths were specified' do
7
+ expect { PuppetCheck::CLI.run(%w[--fail-on-warnings]) }.not_to raise_exception
8
+ expect(PuppetCheck.files[:clean].length).to eql(30)
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
8
14
  end
9
15
  end
10
16
 
11
17
  context '.parse' do
12
18
  it 'raises an error if an invalid option was specified' do
13
- expect { PuppetCheck::CLI.parse(%w[-s -f -asdf foo]) }.to raise_error(OptionParser::InvalidOption)
19
+ expect { PuppetCheck::CLI.send(:parse, %w[-s -asdf foo]) }.to raise_error(OptionParser::InvalidOption)
14
20
  end
15
21
 
16
22
  it 'allows fail on warnings, style, smoke, and regression checks to be enabled' do
17
- 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)
18
24
  end
19
25
 
20
26
  it 'correctly parser EYAML options' do
21
- 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')
22
28
  end
23
29
 
24
30
  it 'correctly parses a formatting option' do
25
- 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')
26
32
  end
27
33
 
28
34
  it 'correctly parses octocatalog-diff options' do
29
- 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])
30
36
  end
31
37
 
32
38
  it 'correctly parses PuppetLint arguments' do
33
- 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'])
34
40
  end
35
41
 
36
42
  it 'correctly loads a .puppet-lint.rc' do
37
- 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'])
38
44
  end
39
45
 
40
46
  it 'correctly parses Rubocop arguments' do
41
- 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'])
42
48
  end
43
49
 
44
50
  it 'correctly parses multiple sets of arguments' do
45
- 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'])
46
52
  end
47
53
  end
48
54
  end
@@ -15,7 +15,7 @@ describe DataParser do
15
15
  it 'puts a bad syntax yaml file in the error files hash' do
16
16
  DataParser.yaml(["#{fixtures_dir}hieradata/syntax.yaml"])
17
17
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}hieradata/syntax.yaml"])
18
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.yaml"].join("\n")).to match(%r{^block sequence entries are not allowed})
18
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.yaml"].join("\n")).to match(/^block sequence entries are not allowed/)
19
19
  expect(PuppetCheck.files[:warnings]).to eql({})
20
20
  expect(PuppetCheck.files[:clean]).to eql([])
21
21
  end
@@ -23,7 +23,7 @@ describe DataParser do
23
23
  DataParser.yaml(["#{fixtures_dir}hieradata/style.yaml"])
24
24
  expect(PuppetCheck.files[:errors]).to eql({})
25
25
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}hieradata/style.yaml"])
26
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}hieradata/style.yaml"].join("\n")).to match(%r{^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly})
26
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}hieradata/style.yaml"].join("\n")).to match(/^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly/)
27
27
  expect(PuppetCheck.files[:clean]).to eql([])
28
28
  end
29
29
  it 'puts a good yaml file in the clean files array' do
@@ -47,7 +47,7 @@ describe DataParser do
47
47
  it 'puts a bad syntax eyaml file in the error files hash' do
48
48
  DataParser.eyaml(["#{fixtures_dir}hieradata/syntax.eyaml"], "#{fixtures_dir}keys/public_key.pkcs7.pem", "#{fixtures_dir}keys/private_key.pkcs7.pem")
49
49
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}hieradata/syntax.eyaml"])
50
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.eyaml"].join("\n")).to match(%r{^block sequence entries are not allowed})
50
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.eyaml"].join("\n")).to match(/^block sequence entries are not allowed/)
51
51
  expect(PuppetCheck.files[:warnings]).to eql({})
52
52
  expect(PuppetCheck.files[:clean]).to eql([])
53
53
  end
@@ -55,7 +55,7 @@ describe DataParser do
55
55
  DataParser.eyaml(["#{fixtures_dir}hieradata/style.eyaml"], "#{fixtures_dir}keys/public_key.pkcs7.pem", "#{fixtures_dir}keys/private_key.pkcs7.pem")
56
56
  expect(PuppetCheck.files[:errors]).to eql({})
57
57
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}hieradata/style.eyaml"])
58
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}hieradata/style.eyaml"].join("\n")).to match(%r{^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly})
58
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}hieradata/style.eyaml"].join("\n")).to match(/^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly/)
59
59
  expect(PuppetCheck.files[:clean]).to eql([])
60
60
  end
61
61
  it 'puts a good eyaml file in the clean files array' do
@@ -70,14 +70,14 @@ describe DataParser do
70
70
  it 'puts a bad syntax json file in the error files hash' do
71
71
  DataParser.json(["#{fixtures_dir}hieradata/syntax.json"])
72
72
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}hieradata/syntax.json"])
73
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.json"].join("\n")).to match(%r{^.*unexpected token})
73
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.json"].join("\n")).to match(/after object value, got.*at line 2 column 3/)
74
74
  expect(PuppetCheck.files[:warnings]).to eql({})
75
75
  expect(PuppetCheck.files[:clean]).to eql([])
76
76
  end
77
77
  it 'puts a bad metadata json file in the error files hash' do
78
78
  DataParser.json(["#{fixtures_dir}metadata_syntax/metadata.json"])
79
79
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}metadata_syntax/metadata.json"])
80
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}metadata_syntax/metadata.json"].join("\n")).to match(%r{^Required field.*\nField 'requirements'.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds})
80
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}metadata_syntax/metadata.json"].join("\n")).to match(/^Required field.*\nField 'requirements'.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds/)
81
81
  expect(PuppetCheck.files[:warnings]).to eql({})
82
82
  expect(PuppetCheck.files[:clean]).to eql([])
83
83
  end
@@ -85,7 +85,7 @@ describe DataParser do
85
85
  DataParser.json(["#{fixtures_dir}metadata_style/metadata.json"])
86
86
  expect(PuppetCheck.files[:errors]).to eql({})
87
87
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}metadata_style/metadata.json"])
88
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}metadata_style/metadata.json"].join("\n")).to match(%r{^'pe' is missing an upper bound.\n.*operatingsystem_support.*\nLicense identifier})
88
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}metadata_style/metadata.json"].join("\n")).to match(/^'pe' is missing an upper bound.\n.*operatingsystem_support.*\nLicense identifier/)
89
89
  expect(PuppetCheck.files[:clean]).to eql([])
90
90
  end
91
91
  it 'puts another bad style metadata json file in the warning files array' do
@@ -99,7 +99,7 @@ describe DataParser do
99
99
  DataParser.json(["#{fixtures_dir}task_metadata/task_bad.json"])
100
100
  expect(PuppetCheck.files[:errors]).to eql({})
101
101
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}task_metadata/task_bad.json"])
102
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}task_metadata/task_bad.json"].join("\n")).to match(%r{^description value is not a String\ninput_method value is not one of environment, stdin, or powershell\nparameters value is not a Hash\npuppet_task_version value is not an Integer\nsupports_noop value is not a Boolean})
102
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}task_metadata/task_bad.json"].join("\n")).to match(/^description value is not a String\ninput_method value is not one of environment, stdin, or powershell\nparameters value is not a Hash\npuppet_task_version value is not an Integer\nsupports_noop value is not a Boolean/)
103
103
  expect(PuppetCheck.files[:clean]).to eql([])
104
104
  end
105
105
  it 'puts a good json file in the clean files array' do
@@ -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
 
@@ -16,9 +16,9 @@ describe PuppetParser do
16
16
  PuppetParser.manifest(["#{fixtures_dir}manifests/syntax.pp"], false, [])
17
17
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}manifests/syntax.pp"])
18
18
  if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0')
19
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}manifests/syntax.pp"].join("\n")).to match(%r{^Language validation logged 2 errors})
19
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}manifests/syntax.pp"].join("\n")).to match(/^Language validation logged 2 errors/)
20
20
  else
21
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.yaml"].join("\n")).to match(%r{^This Variable has no effect.*\nIllegal variable name})
21
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.yaml"].join("\n")).to match(/^This Variable has no effect.*\nIllegal variable name/)
22
22
  end
23
23
  expect(PuppetCheck.files[:warnings]).to eql({})
24
24
  expect(PuppetCheck.files[:clean]).to eql([])
@@ -28,7 +28,7 @@ describe PuppetParser do
28
28
  it 'puts a bad syntax at eof Puppet manifest in the error files hash' do
29
29
  PuppetParser.manifest(["#{fixtures_dir}manifests/eof_syntax.pp"], false, [])
30
30
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}manifests/eof_syntax.pp"])
31
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}manifests/eof_syntax.pp"].join("\n")).to match(%r{^Syntax error at end of input})
31
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}manifests/eof_syntax.pp"].join("\n")).to match(/^Syntax error at end of input/)
32
32
  expect(PuppetCheck.files[:warnings]).to eql({})
33
33
  expect(PuppetCheck.files[:clean]).to eql([])
34
34
  end
@@ -36,7 +36,7 @@ describe PuppetParser do
36
36
  it 'puts a bad syntax Puppet plan in the error files hash' do
37
37
  PuppetParser.manifest(["#{fixtures_dir}plans/syntax.pp"], false, [])
38
38
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}plans/syntax.pp"])
39
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}plans/syntax.pp"].join("\n")).to match(%r{^Syntax error at '\)'})
39
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}plans/syntax.pp"].join("\n")).to match(/^Syntax error at '\)'/)
40
40
  expect(PuppetCheck.files[:warnings]).to eql({})
41
41
  expect(PuppetCheck.files[:clean]).to eql([])
42
42
  end
@@ -44,14 +44,14 @@ describe PuppetParser do
44
44
  PuppetParser.manifest(["#{fixtures_dir}manifests/style_parser.pp"], true, [])
45
45
  expect(PuppetCheck.files[:errors]).to eql({})
46
46
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}manifests/style_parser.pp"])
47
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}manifests/style_parser.pp"].join("\n")).to match(%r{^Unrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing})
47
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}manifests/style_parser.pp"].join("\n")).to match(/^Unrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing/)
48
48
  expect(PuppetCheck.files[:clean]).to eql([])
49
49
  end
50
50
  it 'puts a bad lint style Puppet manifest in the warning files array' do
51
51
  PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, [])
52
52
  expect(PuppetCheck.files[:errors]).to eql({})
53
53
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
54
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}manifests/style_lint.pp"].join("\n")).to match(%r{(?:indentation of|double quoted string containing).*\n.*(?:indentation of|double quoted string containing)})
54
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}manifests/style_lint.pp"].join("\n")).to match(/(?:indentation of|double quoted string containing).*\n.*(?:indentation of|double quoted string containing)/)
55
55
  expect(PuppetCheck.files[:clean]).to eql([])
56
56
  end
57
57
  it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
@@ -64,7 +64,7 @@ describe PuppetParser do
64
64
  PuppetParser.manifest(["#{fixtures_dir}plans/style.pp"], true, [])
65
65
  expect(PuppetCheck.files[:errors]).to eql({})
66
66
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}plans/style.pp"])
67
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}plans/style.pp"].join("\n")).to match(%r{variable not enclosed in {}})
67
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}plans/style.pp"].join("\n")).to match(/variable not enclosed in {}/)
68
68
  expect(PuppetCheck.files[:clean]).to eql([])
69
69
  end
70
70
  it 'puts a good Puppet manifest in the clean files array' do
@@ -88,7 +88,7 @@ describe PuppetParser do
88
88
  it 'puts a bad syntax Puppet template in the error files hash' do
89
89
  PuppetParser.template(["#{fixtures_dir}templates/syntax.epp"])
90
90
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}templates/syntax.epp"])
91
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.epp"].join("\n")).to match(%r{^This Name has no effect})
91
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.epp"].join("\n")).to match(/^This Name has no effect/)
92
92
  expect(PuppetCheck.files[:warnings]).to eql({})
93
93
  expect(PuppetCheck.files[:clean]).to eql([])
94
94
  end
@@ -1,35 +1,41 @@
1
1
  require_relative '../spec_helper'
2
- require_relative '../../lib/puppet-check/regression_check'
2
+ begin
3
+ require_relative '../../lib/puppet-check/regression_check'
3
4
 
4
- # once a good config is loaded, bad configs would have no effect so failures are tested first; config is also tested before compilation so that the good config can be loaded at the end and used for compilation and regression tests
5
- describe RegressionCheck do
6
- context '.config' do
7
- # json gem got messed up for the EOL Ruby versions
8
- it 'raise an appropriate error if the file is malformed' do
9
- expect { RegressionCheck.config("#{fixtures_dir}metadata.json") }.to raise_error(OctocatalogDiff::Errors::ConfigurationFileContentError, 'Configuration must define OctocatalogDiff::Config!')
10
- end
11
- it 'loads in a good octocatalog-diff config file' do
12
- expect { RegressionCheck.config("#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
13
- end
14
- it 'loads in the settings from the file correctly' do
5
+ # once a good config is loaded, bad configs would have no effect so failures are tested first; config is also tested before compilation so that the good config can be loaded at the end and used for compilation and regression tests
6
+ describe RegressionCheck do
7
+ context '.config' do
8
+ # json gem is messed up for the EOL Ruby versions
9
+ it 'raise an appropriate error if the file is malformed' do
10
+ expect { RegressionCheck.send(:config, "#{fixtures_dir}metadata.json") }.to raise_error(OctocatalogDiff::Errors::ConfigurationFileContentError, 'Configuration must define OctocatalogDiff::Config!')
11
+ end
12
+ it 'loads in a good octocatalog-diff config file' do
13
+ expect { RegressionCheck.send(:config, "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
14
+ end
15
+ it 'loads in the settings from the file correctly' do
16
+ # TODO
17
+ end
15
18
  end
16
- end
17
19
 
18
- context '.smoke' do
19
- # octocatalog-diff is returning a blank error for these tests
20
- unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
21
- it 'returns a pass for a successful catalog compilation' do
22
- expect { RegressionCheck.smoke(['good.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
20
+ context '.smoke' do
21
+ # octocatalog-diff is returning a blank error for these tests
22
+ unless ci_env
23
+ it 'returns a pass for a successful catalog compilation' do
24
+ expect { RegressionCheck.smoke(['good.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
25
+ end
26
+ it 'returns a failure for a catalog with an error' do
27
+ expect { RegressionCheck.smoke(['does_not_exist.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.to raise_error(OctocatalogDiff::Errors::CatalogError)
28
+ end
23
29
  end
24
- it 'returns a failure for a catalog with an error' do
25
- expect { RegressionCheck.smoke(['does_not_exist.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.to raise_error(OctocatalogDiff::Errors::CatalogError)
30
+ it 'returns a failure for a good and bad catalog' do
31
+ # RegressionCheck.smoke(['good.example.com', 'syntax_error.example.com'], "#{fixtures_dir}octocatalog_diff.cfg.rb")
26
32
  end
27
33
  end
28
- it 'returns a failure for a good and bad catalog' do
29
- # RegressionCheck.smoke(['good.example.com', 'syntax_error.example.com'], "#{fixtures_dir}octocatalog_diff.cfg.rb")
30
- end
31
- end
32
34
 
33
- context '.regression' do
35
+ context '.regression' do
36
+ # TODO
37
+ end
34
38
  end
39
+ rescue NameError
40
+ puts 'puppet-check+rspec: octocatalog-diff is not installed, and its unit tests will be skipped'
35
41
  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
@@ -15,7 +15,7 @@ describe RubyParser do
15
15
  it 'puts a bad syntax ruby file in the error files hash' do
16
16
  RubyParser.ruby(["#{fixtures_dir}lib/syntax.rb"], false, [])
17
17
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}lib/syntax.rb"])
18
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}lib/syntax.rb"].join("\n")).to match(%r{^.*syntax error})
18
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}lib/syntax.rb"].join("\n")).to match(/^.*syntax error/)
19
19
  expect(PuppetCheck.files[:warnings]).to eql({})
20
20
  expect(PuppetCheck.files[:clean]).to eql([])
21
21
  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(%r{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
@@ -45,9 +49,9 @@ describe RubyParser do
45
49
  RubyParser.template(["#{fixtures_dir}templates/syntax.erb"])
46
50
  expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}templates/syntax.erb"])
47
51
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
48
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(%r{1: syntax error, unexpected.*\n.*ruby})
52
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(/1: syntax error, unexpected.*\n.*ruby/)
49
53
  else
50
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(%r{syntax error, unexpected tIDENTIFIER})
54
+ expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(/syntax error, unexpected tIDENTIFIER/)
51
55
  end
52
56
  expect(PuppetCheck.files[:warnings]).to eql({})
53
57
  expect(PuppetCheck.files[:clean]).to eql([])
@@ -56,7 +60,7 @@ describe RubyParser do
56
60
  RubyParser.template(["#{fixtures_dir}templates/style.erb"])
57
61
  expect(PuppetCheck.files[:errors]).to eql({})
58
62
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}templates/style.erb"])
59
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}templates/style.erb"].join("\n")).to match(%r{already initialized constant.*\n.*previous definition of})
63
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}templates/style.erb"].join("\n")).to match(/already initialized constant.*\n.*previous definition of/)
60
64
  expect(PuppetCheck.files[:clean]).to eql([])
61
65
  end
62
66
  it 'puts a ruby template file with ignored errors in the clean files array' 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(%r{^.*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(%r{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.0
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: 2024-05-12 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
@@ -87,19 +87,19 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '1.0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: octocatalog-diff
90
+ name: rubocop-rspec
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.0'
96
- type: :development
95
+ version: '3.0'
96
+ type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.0'
102
+ version: '3.0'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rake
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -151,6 +151,7 @@ files:
151
151
  - lib/puppet-check/tasks.rb
152
152
  - lib/puppet-check/utils.rb
153
153
  - lib/puppet_check.rb
154
+ - puppet-check.gemspec
154
155
  - spec/fixtures/foobarbaz
155
156
  - spec/fixtures/hieradata/good.eyaml
156
157
  - spec/fixtures/hieradata/good.json
@@ -166,9 +167,9 @@ files:
166
167
  - spec/fixtures/lib/rubocop_style.rb
167
168
  - spec/fixtures/lib/style.rb
168
169
  - spec/fixtures/lib/syntax.rb
169
- - spec/fixtures/librarian_good/Puppetfile
170
- - spec/fixtures/librarian_style/Puppetfile
171
- - spec/fixtures/librarian_syntax/Puppetfile
170
+ - spec/fixtures/librarian/Puppetfile_good
171
+ - spec/fixtures/librarian/Puppetfile_style
172
+ - spec/fixtures/librarian/Puppetfile_syntax
172
173
  - spec/fixtures/manifests/eof_syntax.pp
173
174
  - spec/fixtures/manifests/good.pp
174
175
  - spec/fixtures/manifests/style_lint.pp
@@ -220,14 +221,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
221
  requirements:
221
222
  - - ">="
222
223
  - !ruby/object:Gem::Version
223
- version: 2.7.0
224
+ version: 3.0.0
224
225
  required_rubygems_version: !ruby/object:Gem::Requirement
225
226
  requirements:
226
227
  - - ">="
227
228
  - !ruby/object:Gem::Version
228
229
  version: '0'
229
230
  requirements: []
230
- rubygems_version: 3.3.5
231
+ rubygems_version: 3.4.20
231
232
  signing_key:
232
233
  specification_version: 4
233
234
  summary: A streamlined comprehensive set of checks for your entire Puppet code and