puppet-check 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a111d0def6afe05d7924d10fe26d46a3c50eef1f
4
- data.tar.gz: 17202cf67cac1fae5700d2c332a2c432b753e8a2
3
+ metadata.gz: 6f163a7745155d25678269090a38458154b83f78
4
+ data.tar.gz: 916d7c176c97f75f138e9fe5dc3506c51ecdf197
5
5
  SHA512:
6
- metadata.gz: 86af9837fa801c6b5ace0af98e86d3d999f21adfd627eaa4231606f97835655962e485dda91d6312442934718ab53a10d9dc378f391fb7b41a3ccb0931dc8b3a
7
- data.tar.gz: 105522b9b0bc64afbdcafdcc7124b9db9cb0455c8b57d37808080b59a29b423459e6eb0c1c4445419258fd5f89af7c23352f02c786daca8a786f22c85e1d1f71
6
+ metadata.gz: 30666a5147dbfc9e369c969ed774a7dc056c69ee0489573009fa0c32ef96ac0b6afbb37a40926f7d7471a69f09c6a0e2c663de4418fb896466862c698117c0e8
7
+ data.tar.gz: 9dc6066fe7e26bdb43c89602de6fc4f4d2644696856d57ab7f37322b6280e4539cd1397a431770e27cb2992e7131e8172d18dd31bedc127e85dcbadee1579042
@@ -8,21 +8,22 @@
8
8
  - rspec puppet stubbing (minor)
9
9
  - parallel spec option (minor)
10
10
  - multiple node testing with octocatalog-diff (minor)
11
-
12
- ### 1.4.1 (Roadmap)
13
- - rakefile interface with puppet-lint, rubocop, reek (patch)
14
11
  - split syntax and style checks to separate methods for style (patch)
15
- - change settings to hash (patch)
16
- - add in begin/rescue on rspec, octocatalog, and rake loading (patch)
17
- - svn support for module fixtures (patch)
18
- - fail on warnings option + change exit code logic/possibilities (patch)
19
- - look into partition for execute_parsers optimization (patch)
20
- - handle octocatalog-diff not installed situation better (patch)
12
+ - missing puppet binary error changed
13
+ - puppet 5
14
+ - try closing the template to deal with the erb binding issue
15
+
16
+ ### 1.4.1
17
+ - Support for using SVN to download external module dependencies for RSpec Puppet.
18
+ - Better handled situations with uninstalled optional dependencies.
19
+ - Code cleanup and optimization.
20
+ - Added option to fail on warnings.
21
+ - Added additional error info for failed smoke checks.
21
22
 
22
23
  ### 1.4.0
23
24
  - Optimized and fixed checks on dependencies and requirements in `metadata.json`.
24
- - Optional octocatalog-diff smoke testing
25
- - Optional octocatalog-diff config file support
25
+ - Optional octocatalog-diff smoke testing.
26
+ - Optional octocatalog-diff config file support.
26
27
 
27
28
  ### 1.3.2
28
29
  - For the Puppet Forge method of downloading external module dependencies as spec fixtures, the module is now updated if it is already present. Previously, a fresh forced install was always attempted.
data/README.md CHANGED
@@ -129,6 +129,7 @@ The following files have unrecognized formats and therefore were not processed:
129
129
  - Puppetlabs Spec Helper requires an additional config file for RSpec Puppet support.
130
130
  - Puppetlabs Spec Helper does not update external module dependencies in a stateful/persistent workspace and fails gracefully instead.
131
131
  - Puppetlabs Spec Helper requires extra configuration items to setup self-module RSpec testing.
132
+ - Puppetlabs Spec Helper does not frontend to Octocatalog Diff.
132
133
 
133
134
  It is worth nothing that there is no current development objective for Puppet Check to achieve the same advanced level of robustness for spec testing that Puppetlabs Spec Helper enables. If you are performing standard spec testing on your Puppet code and data, then Puppet Check's spec testing is a fantastic lighter and faster alternative to Puppetlabs Spec Helper. If you require advanced and intricate capabilities in your spec testing (e.g. direct interfacing to the `Puppet::Parser::Scope` API), then you will likely prefer Puppetlabs Spec Helper's spec testing in conjunction with Puppet Check's file validation.
134
135
 
@@ -141,15 +142,17 @@ Reek dropped support for Ruby 2.0 when it went to 4.0. Since dependencies by Rub
141
142
  ### CLI
142
143
  ```
143
144
  usage: puppet-check [options] paths
145
+ --version Display the current version.
144
146
  -f, --future Enable future parser
147
+ --fail-on-warnings Fail on warnings
145
148
  -s, --style Enable style checks
146
- --smoke Enable smoke testing
149
+ --smoke Enable smoke testing
147
150
  -r, --regression Enable regression testing (in progress, do not use)
148
151
  -o, --output format Format for results output (default is text): text, json, or yaml
149
- --octoconfig config_file Octocatalog-diff configuration file to use.
150
- -n, --octonodes node1.example.com,node2.example.com
151
- Octocatalog-diff nodes to test catalog on.
152
- --puppet-lint arg_one,arg_two
152
+ --octoconfig config_file Octocatalog-diff configuration file to use.
153
+ -n node1.example.com,node2.example.com,
154
+ --octonodes Octocatalog-diff nodes to test catalog on.
155
+ --puppet-lint arg_one,arg_two
153
156
  Arguments for PuppetLint ignored checks
154
157
  -c, --config file Load PuppetLint options from file.
155
158
  --rubocop arg_one,arg_two Arguments for Rubocop disabled cops
@@ -176,13 +179,16 @@ rake puppetcheck:beaker # Execute Beaker acceptance tests
176
179
  You can add style, smoke, and regression checks to and select the future parser for the `rake puppetcheck:file`, or change the output format, by adding the following after the require:
177
180
 
178
181
  ```ruby
179
- PuppetCheck.style_check = true
180
- PuppetCheck.future_parser = true
181
- PuppetCheck.smoke_check = true
182
- PuppetCheck.regression_check = true # in progress, do not use
183
- PuppetCheck.output_format = 'yaml'
184
- PuppetCheck.octoconfig = '.octocatalog-diff.cfg.rb'
185
- PuppetCheck.octonodes = %w(localhost.localdomain)
182
+ PuppetCheck.settings[:style_check] = true
183
+ PuppetCheck.settings[:fail_on_warnings] = true
184
+ PuppetCheck.settings[:future_parser] = true
185
+ PuppetCheck.settings[:smoke_check] = true
186
+ PuppetCheck.settings[:regression_check] = true # in progress, do not use
187
+ PuppetCheck.settings[:output_format] = 'yaml'
188
+ PuppetCheck.settings[:octoconfig] = '.octocatalog-diff.cfg.rb'
189
+ PuppetCheck.settings[:octonodes] = %w(localhost.localdomain)
190
+ PuppetCheck.settings[:puppetlint_args] = ['--puppetlint-arg-one', '--puppetlint-arg-two']
191
+ PuppetCheck.settings[:rubocop_args] = ['--except', 'rubocop-arg-one,rubocop-arg-two']
186
192
  ```
187
193
 
188
194
  Please note that `rspec` does not support yaml output and therefore would still use the default 'progress' formatter even if `yaml` is specified as the format option to Puppet Check.
@@ -196,7 +202,7 @@ Please note it is perfectly acceptable to only execute standard RSpec tests in y
196
202
 
197
203
  Prior to executing the spec tests, Puppet Check will parse everything in the current path and identify all `spec` directories not within `fixtures` directories. It will then execute RSpec Puppet setup actions inside all directories one level above that contain a `manifests` directory. This is assumed to be a Puppet module directory. These setup actions include creating all of the necessary directories inside of `spec/fixtures`, creating a blank `site.pp` if it is missing, symlinking everything from the module that is needed into fixtures (automatically replaces functionality of self module symlink in `.fixtures.yaml` from Puppetlabs Spec Helper), and creates the `spec_helper.rb` if it is missing. Note these setup actions can replace `rspec-puppet-init` from RSpec Puppet and currently are both faster and more accurate.
198
204
 
199
- Puppet Check will also automatically download specified external module dependencies for and during RSpec Puppet testing. Currently `git`, `puppet forge`, and `hg` commands are supported. They can be implemented in the following way in your modules' `metadata.json`:
205
+ Puppet Check will also automatically download specified external module dependencies for and during RSpec Puppet testing. Currently `git`, `puppet forge`, `svn`, and `hg` commands are supported. They can be implemented in the following way in your modules' `metadata.json`:
200
206
 
201
207
  ```json
202
208
  "dependencies": [
@@ -214,6 +220,11 @@ Puppet Check will also automatically download specified external module dependen
214
220
  "name": "module-name",
215
221
  "hg": "hg-url",
216
222
  "args": "hg clone optional-arguments"
223
+ },
224
+ {
225
+ "name": "module-name",
226
+ "svn": "svn-url",
227
+ "args": "svn co optional arguments"
217
228
  }
218
229
  ]
219
230
  ```
@@ -234,7 +245,7 @@ Example:
234
245
  ]
235
246
  ```
236
247
 
237
- Note that `args` will be ignored during `git pull` and `hg pull/hg update` when the modules are updated instead of freshly cloned.
248
+ Note that `args` will be ignored during `git pull`, 'svn update', and `hg pull/hg update` when the modules are updated instead of freshly cloned.
238
249
 
239
250
  #### puppetcheck:beaker
240
251
  The spec tests will be executed against everything that matches the pattern `**/acceptance`. Any of these directories inside of a `fixtures` directory will be ignored. This means everything in the current path that appears to be a Puppet module acceptance test for your module (not dependencies) will be regarded as such and executed during this rake task.
@@ -249,15 +260,16 @@ If you are performing your Puppet testing from within a Ruby script or your own
249
260
  # file checks
250
261
  require 'puppet-check'
251
262
 
252
- PuppetCheck.future_parser = true # default false
253
- PuppetCheck.style_check = true # default false
254
- PuppetCheck.smoke_check = true # default false
255
- PuppetCheck.regression_check = true # in progress, do not use; default false
256
- PuppetCheck.output_format = 'yaml' # also 'json'; default 'text'
257
- PuppetCheck.octoconfig = '$HOME/octocatalog-diff.cfg.rb' # default '.octocatalog-diff.cfg.rb'
258
- PuppetCheck.octonodes = %w(server.example.com) # default: %w(localhost.localdomain)
259
- PuppetCheck.puppetlint_args = ['--puppetlint-arg-one', '--puppetlint-arg-two'] # default []
260
- PuppetCheck.rubocop_args = ['--except', 'rubocop-arg-one,rubocop-arg-two'] # default []
263
+ PuppetCheck.settings[:future_parser] = true # default false
264
+ PuppetCheck.settings[:fail_on_warnings] = true # default false
265
+ PuppetCheck.settings[:style_check] = true # default false
266
+ PuppetCheck.settings[:smoke_check] = true # default false
267
+ PuppetCheck.settings[:regression_check] = true # in progress, do not use; default false
268
+ PuppetCheck.settings[:output_format] = 'yaml' # also 'json'; default 'text'
269
+ PuppetCheck.settings[:octoconfig] = '$HOME/octocatalog-diff.cfg.rb' # default '.octocatalog-diff.cfg.rb'
270
+ PuppetCheck.settings[:octonodes] = %w(server.example.com) # default: %w(localhost.localdomain)
271
+ PuppetCheck.settings[:puppetlint_args] = ['--puppetlint-arg-one', '--puppetlint-arg-two'] # default []
272
+ PuppetCheck.settings[:rubocop_args] = ['--except', 'rubocop-arg-one,rubocop-arg-two'] # default []
261
273
 
262
274
  PuppetCheck.new.run([dirs, files])
263
275
 
@@ -318,9 +330,9 @@ end
318
330
  To overcome the lack of convenient portability, you could try spinning up the Vagrant instance at the top level of your Puppet code and data and then descend into directories to execute tests as necessary. Cleverness or patience will be necessary if you decide to use Vagrant for testing and desire portability.
319
331
 
320
332
  ### Exit Codes
321
- - 0: PuppetCheck exited with no internal exceptions or errors in your Puppet code and data.
322
- - 1: PuppetCheck exited with an internal exception (takes preference over other non-zero exit codes) or failed spec test.
323
- - 2: PuppetCheck exited with one or more errors in your Puppet code and data.
333
+ - 0: PuppetCheck exited with no internal exceptions or errors in your code and data.
334
+ - 1: PuppetCheck exited with an internal exception (takes preference over other non-zero exit codes) or failed spec test(s).
335
+ - 2: PuppetCheck exited with one or more errors in your code and data. Alternatively, PuppetCheck exited with one or more warnings in your code and data and you specified to fail on warnings.
324
336
 
325
337
  ### Optional dependencies
326
338
  - **rake**: install this if you want to use Puppet Check with `rake` tasks in addition to the CLI.
@@ -2,39 +2,39 @@ require_relative 'puppet-check/puppet_parser'
2
2
  require_relative 'puppet-check/ruby_parser'
3
3
  require_relative 'puppet-check/data_parser'
4
4
  require_relative 'puppet-check/output_results'
5
- begin
6
- require_relative 'puppet-check/regression_check'
7
- rescue LoadError
8
- end
9
5
 
10
6
  # interfaces from CLI/tasks and to individual parsers
11
7
  class PuppetCheck
12
- # initialize future parser, style check, and regression check bools
13
- @future_parser = false
14
- @style_check = false
15
- @smoke_check = false
16
- @regression_check = false
8
+ # initialize settings hash
9
+ @settings = {}
10
+
11
+ # initialize future parser, fail on warning, style check, and regression check bools
12
+ @settings[:future_parser] = false
13
+ @settings[:fail_on_warning] = false
14
+ @settings[:style_check] = false
15
+ @settings[:smoke_check] = false
16
+ @settings[:regression_check] = false
17
17
 
18
18
  # initialize output format option
19
- @output_format = 'text'
19
+ @settings[:output_format] = 'text'
20
20
 
21
21
  # initialize octocatalog-diff options
22
- @octoconfig = '.octocatalog-diff.cfg.rb'
23
- @octonodes = %w(localhost.localdomain)
22
+ @settings[:octoconfig] = '.octocatalog-diff.cfg.rb'
23
+ @settings[:octonodes] = %w[localhost.localdomain]
24
24
 
25
25
  # initialize diagnostic output arrays
26
- @error_files = []
27
- @warning_files = []
28
- @clean_files = []
29
- @ignored_files = []
26
+ @settings[:error_files] = []
27
+ @settings[:warning_files] = []
28
+ @settings[:clean_files] = []
29
+ @settings[:ignored_files] = []
30
30
 
31
31
  # initialize style arg arrays
32
- @puppetlint_args = []
33
- @rubocop_args = []
32
+ @settings[:puppetlint_args] = []
33
+ @settings[:rubocop_args] = []
34
34
 
35
35
  # allow the parser methods read user options and append to the file arrays; allow CLI and tasks write to user options
36
36
  class << self
37
- attr_accessor :future_parser, :style_check, :smoke_check, :regression_check, :output_format, :octoconfig, :octonodes, :error_files, :warning_files, :clean_files, :ignored_files, :puppetlint_args, :rubocop_args
37
+ attr_accessor :settings
38
38
  end
39
39
 
40
40
  # main runner for PuppetCheck
@@ -43,23 +43,37 @@ class PuppetCheck
43
43
  files = self.class.parse_paths(paths)
44
44
 
45
45
  # parse the files
46
- execute_parsers(files, self.class.future_parser, self.class.style_check, self.class.puppetlint_args, self.class.rubocop_args)
46
+ execute_parsers(files, self.class.settings[:future_parser], self.class.settings[:style_check], self.class.settings[:puppetlint_args], self.class.settings[:rubocop_args])
47
47
 
48
48
  # output the diagnostic results
49
- PuppetCheck.output_format == 'text' ? OutputResults.text : OutputResults.markup
49
+ PuppetCheck.settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup
50
+
51
+ if self.class.settings[:error_files].empty? && (!self.class.settings[:fail_on_warning] || self.class.settings[:warning_files].empty?)
52
+ begin
53
+ require_relative 'puppet-check/regression_check'
54
+ rescue LoadError
55
+ end
50
56
 
51
- if self.class.error_files.empty?
52
57
  # perform smoke checks if there were no errors and the user desires
53
58
  begin
54
- RegressionCheck.smoke(self.class.octonodes, self.class.octoconfig) if PuppetCheck.smoke_check
59
+ catalog = RegressionCheck.smoke(self.class.octonodes, self.class.octoconfig) if PuppetCheck.settings[:smoke_check]
55
60
  # smoke check failure? output message and return 2
56
61
  rescue OctocatalogDiff::Errors::CatalogError => err
57
62
  puts 'There was a smoke check error:'
58
63
  puts err
64
+ puts catalog.error_message unless catalog.valid?
59
65
  2
60
66
  end
61
67
  # perform regression checks if there were no errors and the user desires
62
- # RegressionCheck.regression(self.class.octonodes, self.class.octoconfig) if PuppetCheck.regression_check
68
+ # begin
69
+ # catalog = RegressionCheck.regression(self.class.octonodes, self.class.octoconfig) if PuppetCheck.settings[:regression_check]
70
+ # rescue OctocatalogDiff::Errors::CatalogError => err
71
+ # puts 'There was a catalog compilation error during the regression check:'
72
+ # puts err
73
+ # puts catalog.error_message unless catalog.valid?
74
+ # 2
75
+ # end
76
+ # code to output differences in catalog?
63
77
  # everything passed? return 0
64
78
  0
65
79
  else
@@ -91,20 +105,20 @@ class PuppetCheck
91
105
 
92
106
  # categorize and pass the files out to the parsers to determine their status
93
107
  def execute_parsers(files, future, style, pl_args, rc_args)
94
- PuppetParser.manifest(files.select { |file| File.extname(file) == '.pp' }, future, style, pl_args)
95
- files.reject! { |file| File.extname(file) == '.pp' }
96
- PuppetParser.template(files.select { |file| File.extname(file) == '.epp' })
97
- files.reject! { |file| File.extname(file) == '.epp' }
98
- RubyParser.ruby(files.select { |file| File.extname(file) == '.rb' }, style, rc_args)
99
- files.reject! { |file| File.extname(file) == '.rb' }
100
- RubyParser.template(files.select { |file| File.extname(file) == '.erb' })
101
- files.reject! { |file| File.extname(file) == '.erb' }
102
- DataParser.yaml(files.select { |file| File.extname(file) =~ /\.ya?ml$/ })
103
- files.reject! { |file| File.extname(file) =~ /\.ya?ml$/ }
104
- DataParser.json(files.select { |file| File.extname(file) == '.json' })
105
- files.reject! { |file| File.extname(file) == '.json' }
106
- RubyParser.librarian(files.select { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }, style, rc_args)
107
- files.reject! { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
108
- files.each { |file| self.class.ignored_files.push(file.to_s) }
108
+ manifests, files = files.partition { |file| File.extname(file) == '.pp' }
109
+ PuppetParser.manifest(manifests, future, style, pl_args)
110
+ templates, files = files.partition { |file| File.extname(file) == '.epp' }
111
+ PuppetParser.template(templates)
112
+ rubies, files = files.partition { |file| File.extname(file) == '.rb' }
113
+ RubyParser.ruby(rubies, style, rc_args)
114
+ templates, files = files.partition { |file| File.extname(file) == '.erb' }
115
+ RubyParser.template(templates)
116
+ yamls, files = files.partition { |file| File.extname(file) =~ /\.ya?ml$/ }
117
+ DataParser.yaml(yamls)
118
+ jsons, files = files.partition { |file| File.extname(file) == '.json' }
119
+ DataParser.json(jsons)
120
+ librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
121
+ RubyParser.librarian(librarians, style, rc_args)
122
+ files.each { |file| self.class.settings[:ignored_files].push(file.to_s) }
109
123
  end
110
124
  end
@@ -21,31 +21,32 @@ class PuppetCheck::CLI
21
21
 
22
22
  # base options
23
23
  opts.on('--version', 'Display the current version.') do
24
- puts 'puppet-check 1.4.0'
24
+ puts 'puppet-check 1.4.1'
25
25
  exit 0
26
26
  end
27
27
 
28
28
  # bool options
29
- opts.on('-f', '--future', 'Enable future parser') { PuppetCheck.future_parser = true }
30
- opts.on('-s', '--style', 'Enable style checks') { PuppetCheck.style_check = true }
31
- opts.on('--smoke', 'Enable smoke testing') { PuppetCheck.smoke_check = true }
32
- opts.on('-r', '--regression', 'Enable regression testing (in progress, do not use)') { PuppetCheck.regression_check = true }
29
+ opts.on('-f', '--future', 'Enable future parser') { PuppetCheck.settings[:future_parser] = true }
30
+ opts.on('--fail-on-warnings', 'Fail on warnings') { PuppetCheck.settings[:fail_on_warnings] = true }
31
+ opts.on('-s', '--style', 'Enable style checks') { PuppetCheck.settings[:style_check] = true }
32
+ opts.on('--smoke', 'Enable smoke testing') { PuppetCheck.settings[:smoke_check] = true }
33
+ opts.on('-r', '--regression', 'Enable regression testing (in progress, do not use)') { PuppetCheck.settings[:regression_check] = true }
33
34
 
34
35
  # formatting options
35
- opts.on('-o', '--output format', String, 'Format for results output (default is text): text, json, or yaml') { |arg| PuppetCheck.output_format = arg }
36
+ opts.on('-o', '--output format', String, 'Format for results output (default is text): text, json, or yaml') { |arg| PuppetCheck.settings[:output_format] = arg }
36
37
 
37
38
  # octocatalog-diff options
38
- opts.on('--octoconfig config_file', String, 'Octocatalog-diff configuration file to use.') { |arg| PuppetCheck.octoconfig = arg }
39
- opts.on('-n', '--octonodes node1.example.com,node2.example.com', Array, 'Octocatalog-diff nodes to test catalog on.') { |arg| PuppetCheck.octonodes = arg }
39
+ opts.on('--octoconfig config_file', String, 'Octocatalog-diff configuration file to use.') { |arg| PuppetCheck.settings[:octoconfig] = arg }
40
+ opts.on('-n', '--octonodes node1.example.com,node2.example.com', Array, 'Octocatalog-diff nodes to test catalog on.') { |arg| PuppetCheck.settings[:octonodes] = arg }
40
41
 
41
42
  # arguments to style checkers
42
43
  opts.on('--puppet-lint arg_one,arg_two', Array, 'Arguments for PuppetLint ignored checks') do |puppetlint_args|
43
- PuppetCheck.puppetlint_args += puppetlint_args.map { |arg| "--#{arg}" }
44
+ PuppetCheck.settings[:puppetlint_args] += puppetlint_args.map { |arg| "--#{arg}" }
44
45
  end
45
46
  opts.on('-c', '--config file', String, 'Load PuppetLint options from file.') do |file|
46
- PuppetCheck.puppetlint_args += File.read(file).split("\n")
47
+ PuppetCheck.settings[:puppetlint_args] += File.read(file).split("\n")
47
48
  end
48
- opts.on('--rubocop arg_one,arg_two', String, 'Arguments for Rubocop disabled cops') { |arg| PuppetCheck.rubocop_args = ['--except', arg] }
49
+ opts.on('--rubocop arg_one,arg_two', String, 'Arguments for Rubocop disabled cops') { |arg| PuppetCheck.settings[:rubocop_args] = ['--except', arg] }
49
50
  end
50
51
 
51
52
  opt_parser.parse!(args)
@@ -11,7 +11,7 @@ class DataParser
11
11
  begin
12
12
  parsed = YAML.load_file(file)
13
13
  rescue StandardError => err
14
- PuppetCheck.error_files.push("#{file}:\n#{err.to_s.gsub("(#{file}): ", '')}")
14
+ PuppetCheck.settings[:error_files].push("#{file}:\n#{err.to_s.gsub("(#{file}): ", '')}")
15
15
  else
16
16
  warnings = []
17
17
 
@@ -21,8 +21,8 @@ class DataParser
21
21
  # check that '---' does not show up more than once in the hieradata
22
22
  warnings.push('The string --- appears more than once in this data and Hiera will fail to parse it correctly.') if File.read(file).scan(/---/).count >= 2
23
23
 
24
- next PuppetCheck.warning_files.push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty?
25
- PuppetCheck.clean_files.push(file.to_s)
24
+ next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty?
25
+ PuppetCheck.settings[:clean_files].push(file.to_s)
26
26
  end
27
27
  end
28
28
  end
@@ -36,7 +36,7 @@ class DataParser
36
36
  begin
37
37
  parsed = JSON.parse(File.read(file))
38
38
  rescue JSON::ParserError => err
39
- PuppetCheck.error_files.push("#{file}:\n#{err.to_s.lines.first.strip}")
39
+ PuppetCheck.settings[:error_files].push("#{file}:\n#{err.to_s.lines.first.strip}")
40
40
  else
41
41
  warnings = []
42
42
 
@@ -49,12 +49,12 @@ class DataParser
49
49
  errors = []
50
50
 
51
51
  # check for required keys
52
- %w(name version author license summary source dependencies).each do |key|
52
+ %w[name version author license summary source dependencies].each do |key|
53
53
  errors.push("Required field '#{key}' not found.") unless parsed.key?(key)
54
54
  end
55
55
 
56
56
  # check requirements and dependencies keys
57
- %w(requirements dependencies).each do |key|
57
+ %w[requirements dependencies].each do |key|
58
58
  # skip if key is missing or or value is an empty string, array, or hash
59
59
  next unless parsed.key?(key)
60
60
  next if parsed[key].empty?
@@ -84,14 +84,14 @@ class DataParser
84
84
  end
85
85
 
86
86
  # check for deprecated fields
87
- %w(types checksum).each do |key|
87
+ %w[types checksum].each do |key|
88
88
  errors.push("Deprecated field '#{key}' found.") if parsed.key?(key)
89
89
  end
90
90
 
91
91
  # check for summary under 144 character
92
92
  errors.push('Summary exceeds 144 characters.') if parsed.key?('summary') && parsed['summary'].size > 144
93
93
 
94
- next PuppetCheck.error_files.push("#{file}:\n#{errors.join("\n")}") unless errors.empty?
94
+ next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.join("\n")}") unless errors.empty?
95
95
 
96
96
  # check for warnings
97
97
  # check for operatingsystem_support hash array
@@ -128,8 +128,8 @@ class DataParser
128
128
  # perform some rudimentary hiera checks if data exists
129
129
  warnings = hiera(parsed) unless parsed.class.to_s == 'NilClass'
130
130
  end
131
- next PuppetCheck.warning_files.push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty?
132
- PuppetCheck.clean_files.push(file.to_s)
131
+ next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty?
132
+ PuppetCheck.settings[:clean_files].push(file.to_s)
133
133
  end
134
134
  end
135
135
  end
@@ -4,41 +4,41 @@ require_relative '../puppet-check'
4
4
  class OutputResults
5
5
  # output the results as text
6
6
  def self.text
7
- unless PuppetCheck.error_files.empty?
7
+ unless PuppetCheck.settings[:error_files].empty?
8
8
  print "\033[31mThe following files have errors:\033[0m\n-- "
9
- puts PuppetCheck.error_files.join("\n\n-- ")
9
+ puts PuppetCheck.settings[:error_files].join("\n\n-- ")
10
10
  end
11
- unless PuppetCheck.warning_files.empty?
11
+ unless PuppetCheck.settings[:warning_files].empty?
12
12
  print "\n\033[33mThe following files have warnings:\033[0m\n-- "
13
- puts PuppetCheck.warning_files.join("\n\n-- ")
13
+ puts PuppetCheck.settings[:warning_files].join("\n\n-- ")
14
14
  end
15
- unless PuppetCheck.clean_files.empty?
15
+ unless PuppetCheck.settings[:clean_files].empty?
16
16
  print "\n\033[32mThe following files have no errors or warnings:\033[0m\n-- "
17
- puts PuppetCheck.clean_files.join("\n-- ")
17
+ puts PuppetCheck.settings[:clean_files].join("\n-- ")
18
18
  end
19
- return if PuppetCheck.ignored_files.empty?
19
+ return if PuppetCheck.settings[:ignored_files].empty?
20
20
  print "\n\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- "
21
- puts PuppetCheck.ignored_files.join("\n-- ")
21
+ puts PuppetCheck.settings[:ignored_files].join("\n-- ")
22
22
  end
23
23
 
24
24
  # output the results as yaml or json
25
25
  def self.markup
26
26
  # generate output hash
27
27
  hash = {}
28
- hash['errors'] = PuppetCheck.error_files unless PuppetCheck.error_files.empty?
29
- hash['warnings'] = PuppetCheck.warning_files unless PuppetCheck.warning_files.empty?
30
- hash['clean'] = PuppetCheck.clean_files unless PuppetCheck.clean_files.empty?
31
- hash['ignored'] = PuppetCheck.ignored_files unless PuppetCheck.ignored_files.empty?
28
+ hash['errors'] = PuppetCheck.settings[:error_files] unless PuppetCheck.settings[:error_files].empty?
29
+ hash['warnings'] = PuppetCheck.settings[:warning_files] unless PuppetCheck.settings[:warning_files].empty?
30
+ hash['clean'] = PuppetCheck.settings[:clean_files] unless PuppetCheck.settings[:clean_files].empty?
31
+ hash['ignored'] = PuppetCheck.settings[:ignored_files] unless PuppetCheck.settings[:ignored_files].empty?
32
32
 
33
33
  # convert hash to markup language
34
- if PuppetCheck.output_format == 'yaml'
34
+ if PuppetCheck.settings[:output_format] == 'yaml'
35
35
  require 'yaml'
36
36
  puts Psych.dump(hash, indentation: 2)
37
- elsif PuppetCheck.output_format == 'json'
37
+ elsif PuppetCheck.settings[:output_format] == 'json'
38
38
  require 'json'
39
39
  puts JSON.pretty_generate(hash)
40
40
  else
41
- raise "puppet-check: Unsupported output format '#{PuppetCheck.output_format}' was specified."
41
+ raise "puppet-check: Unsupported output format '#{PuppetCheck.settings[:output_format]}' was specified."
42
42
  end
43
43
  end
44
44
  end