puppet-check 1.6.0 → 1.6.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
  SHA256:
3
- metadata.gz: 5e965d79b58fb8bb6f0b3a3d01d94a451e628239abd3aeefc472dc6a8965cb59
4
- data.tar.gz: 25554b24ad51443eb8b6eabee9aaed19003c20b833a4dc5b74f59db236a607aa
3
+ metadata.gz: 4351237d9dbb4f8790fb4b3aa77dce9a3274b9146b566261ca089c4759c634ee
4
+ data.tar.gz: 4a6c8d9e48b456bea5a130e3984613f7cb923891c9fe6779ac481ffdc043a3c1
5
5
  SHA512:
6
- metadata.gz: 70176578f2be7977ac92d902dd790647962b43fafd32f3a2c1f65af121d84633b8701e759d536f063dd4c692513a35d2e6ca536812626215f571bb587986e19b
7
- data.tar.gz: d15e1217350f3c8ee6215d23b2a5806f451564e6b371ffd994004f53dcd49631ebd469782c4e5a025bde864949eddd73007ce053424b77435d571192a0a6b8f0
6
+ metadata.gz: dcf4c5c9ec7906f130f8ae74f61b1efaab297d33276f1587c88ac68bea8f25a09aa1deeac0ede9cee835e0b2bed95b404e1a208649df29e76693d56a37ab867c
7
+ data.tar.gz: 1b4a1c372216d42d5e0e547e98a606866d0576da2e494d56340eb7a025e0f3763a9139ca18c24165a473c03429c1cf271ca0606017889e29dfbead14a0e5e7da
@@ -1,4 +1,10 @@
1
- ### 1.6.0 (Next)
1
+ ### 1.6.1 (Next)
2
+ - Removed check for hieradata nil/undef value for Hiera >= 5.
3
+ - Add rudimentary checks for task metadata.
4
+ - Preliminary support for Puppet 6.
5
+ - RSpec Puppet fixed its default `spec_helper`. Revert to loading it instead of generating a working one.
6
+
7
+ ### 1.6.0
2
8
  - Minimum Ruby version increased to 2.1.
3
9
  - Minimum Puppet version increased to 3.7.
4
10
  - Minimum Puppet-Lint and Rubocop increased to 2.0 and 0.51.0.
data/README.md CHANGED
@@ -121,19 +121,8 @@ The following files have unrecognized formats and therefore were not processed:
121
121
  -- foobarbaz
122
122
  ```
123
123
 
124
- ### Why not Puppetlabs Spec Helper?
125
- - Puppetlabs Spec Helper is focused more on advanced and robust spec testing. Puppet Check is focused more on efficient and comprehensive Puppet code and data validation.
126
- - Puppetlabs Spec Helper performs fewer types of checks.
127
- - Puppetlabs Spec Helper has extra layers of gems in between it and the gems executing the checks.
128
- - Puppetlabs Spec Helper does not allow interfacing through it to the gems executing the checks.
129
- - Puppetlabs Spec Helper has no CLI.
130
- - Puppetlabs Spec Helper intrinsically only executes spec tests against one module at a time.
131
- - Puppetlabs Spec Helper requires an additional config file for RSpec Puppet support.
132
- - Puppetlabs Spec Helper does not update external module dependencies in a stateful/persistent workspace and fails gracefully instead.
133
- - Puppetlabs Spec Helper requires extra configuration items to setup self-module RSpec testing.
134
- - Puppetlabs Spec Helper does not frontend to Octocatalog Diff or Test-Kitchen.
135
-
136
- 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.
124
+ ### What About Puppet Development Kit?
125
+ The fairly recent release of the Puppet Development Kit (PDK) will hopefully eventually bring about the capability to test and validate your Puppet code and data in a streamlined, efficient, comprehensive, and accurate fashion comparable to Puppet Check. Unfortunately, the PDK has not yet achieved feature or efficiency parity with Puppet Check. The goal is for the PDK to one day replace Puppet Check and for Puppet Check to enter maintenance mode, but for now Puppet Check is still needed to lead Puppet testing.
137
126
 
138
127
  ## Usage
139
128
  Please see the [Gemspec](puppet-check.gemspec) for dependency information. All other dependencies should be fine with various versions. Puppet Check can be used with a CLI, Rake tasks, or API, from your system, rbenv, rvm, Docker, or Vagrant. Please note all interfaces (API by default, but can be modified) will ignore any directories named `fixtures` or specified paths with that directory during file checks and spec tests.
@@ -295,7 +284,7 @@ You can also use Puppet Check inside of Docker for quick, portable, and disposab
295
284
 
296
285
  ```dockerfile
297
286
  # a reliable and small container at the moment
298
- FROM ubuntu:16.04
287
+ FROM ubuntu:18.04
299
288
  # you need ruby and any other extra dependencies that come from packages; in this example we install git to use it for downloading external module dependencies
300
289
  RUN apt-get update && apt-get install ruby git -y
301
290
  # you need puppet-check and any other extra dependencies that come from gems; in this example we install reek because the ruby ABI is 2.3 and then rspec-puppet and rake for extra testing
@@ -304,7 +293,7 @@ RUN gem install --no-document puppet-check reek rspec-puppet rake
304
293
  ENV LANG en_US.UTF-8
305
294
  # create the directory for your module, directory environment, etc. and change directory into it
306
295
  WORKDIR /module_name_or_directory_environment_name
307
- # copy the module, directory environment, etc. contents into the corresponding directory inside the container
296
+ # copy the module, directory environment, etc. contents into the corresponding directory inside the container; alternative, bind a volume mount for your module(s) into the container at runtime
308
297
  COPY / .
309
298
  # execute your tests; in this example we are executing the full suite of tests
310
299
  ENTRYPOINT ["rake", "puppetcheck"]
@@ -319,7 +308,7 @@ As an alternative to Docker, you can also use Vagrant for quick and disposable t
319
308
  ```ruby
320
309
  Vagrant.configure(2) do |config|
321
310
  # a reliable and small box at the moment
322
- config.vm.box = 'fedora/24-cloud-base'
311
+ config.vm.box = 'fedora/26-cloud-base'
323
312
 
324
313
  config.vm.provision 'shell', inline: <<-SHELL
325
314
  # cd to '/vagrant'
@@ -113,7 +113,7 @@ class PuppetCheck
113
113
 
114
114
  # do not process fixtures, check that at least one file was found, and remove double slashes
115
115
  files.reject! { |file| file =~ /fixtures/ }
116
- raise "puppet-check: no files found in supplied paths #{paths.join(', ')}." if files.empty?
116
+ raise "puppet-check: no files found in supplied paths '#{paths.join(', ')}'." if files.empty?
117
117
  files.map! { |file| file.gsub('//', '/') }
118
118
 
119
119
  files.uniq
@@ -27,7 +27,7 @@ class PuppetCheck::CLI
27
27
 
28
28
  # base options
29
29
  opts.on('--version', 'Display the current version.') do
30
- puts 'puppet-check 1.6.0'
30
+ puts 'puppet-check 1.6.1'
31
31
  exit 0
32
32
  end
33
33
 
@@ -160,11 +160,43 @@ class DataParser
160
160
  warnings.push('Recommended field \'operatingsystem_support\' not found.')
161
161
  end
162
162
 
163
- # check for spdx license (rubygems/util/licenses for rubygems >= 2.5 in the far future)
164
- if parsed.key?('license') && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
165
- warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/")
163
+ # check for spdx license
164
+ begin
165
+ require 'rubygems/util/licenses'
166
+
167
+ if parsed.key?('license') && !Gem::Licenses.match?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
168
+ warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/")
169
+ end
170
+ rescue LoadError
171
+ if parsed.key?('license') && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
172
+ warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/")
173
+ end
174
+ end
175
+ # assume this is task metadata if it has this key
176
+ elsif parsed.key?('description')
177
+ # check that description is a string
178
+ warnings.push('description value is not a String') unless parsed['description'].is_a?(String)
179
+ # check that input_method is one of three possible values
180
+ if parsed.key?('input_method')
181
+ if parsed['input_method'].is_a?(String)
182
+ warnings.push('input_method value is not one of environment, stdin, or powershell') unless %w[environment stdin powershell].include?(parsed['input_method'])
183
+ else
184
+ warnings.push('input_method value is not a String')
185
+ end
186
+ end
187
+ # check that parameters is a hash
188
+ if parsed.key?('parameters')
189
+ warnings.push('parameters value is not a Hash') unless parsed['parameters'].is_a?(Hash)
190
+ end
191
+ # check that puppet_task_version is an integer
192
+ if parsed.key?('puppet_task_version')
193
+ warnings.push('puppet_task_version value is not an Integer') unless parsed['puppet_task_version'].is_a?(Integer)
166
194
  end
167
- # assume this is hieradata
195
+ # check that supports_noop is a boolean
196
+ if parsed.key?('supports_noop')
197
+ warnings.push('supports_noop value is not a Boolean') unless parsed['supports_noop'].is_a?(TrueClass) || parsed['supports_noop'].is_a?(FalseClass)
198
+ end
199
+ # assume this is hieradata and ensure it is non-empty
168
200
  elsif parsed
169
201
  # perform some rudimentary hiera checks if data exists
170
202
  warnings = hiera(parsed, file)
@@ -180,15 +212,18 @@ class DataParser
180
212
  private_class_method :method
181
213
  warnings = []
182
214
 
183
- data.each do |key, value|
184
- # check for nil values in the data (nil keys are fine)
185
- if (value.is_a?(Hash) && value.values.any?(&:nil?)) || value.nil?
186
- warnings.push("Value(s) missing in key '#{key}'.")
215
+ # disregard nil/undef value data check if default values (common)
216
+ unless file =~ /^common/
217
+ data.each do |key, value|
218
+ # check for nil values in the data (nil keys are fine)
219
+ if (value.is_a?(Hash) && value.values.any?(&:nil?)) || value.nil?
220
+ warnings.push("Value(s) missing in key '#{key}'.")
221
+ end
187
222
  end
188
223
  end
189
224
 
190
225
  # check that '---' does not show up more than once in the hieradata
191
- 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
226
+ warnings.push('The string --- appears more than once in this data and Hiera may fail to parse it correctly.') if File.read(file).scan(/---/).count >= 2
192
227
 
193
228
  warnings
194
229
  end
@@ -36,12 +36,12 @@ class PuppetParser
36
36
  warnings = "#{file}:"
37
37
  unless errors.empty?
38
38
  # puppet 5.4-5.x has a new validator output format
39
- if Puppet::PUPPETVERSION.to_f >= 5.4
40
- warnings << "\n#{errors.map(&:to_s).join("\n").gsub("file: #{File.absolute_path(file)}, ", '')}"
41
- # puppet <= 5.3 validator output format
42
- else
43
- warnings << "\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}"
44
- end
39
+ warnings << if Puppet::PUPPETVERSION.to_f >= 5.4
40
+ "\n#{errors.map(&:to_s).join("\n").gsub("file: #{File.absolute_path(file)}, ", '')}"
41
+ # puppet <= 5.3 validator output format
42
+ else
43
+ "\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}"
44
+ end
45
45
  end
46
46
  Puppet::Util::Log.close_all
47
47
 
@@ -54,7 +54,7 @@ class RSpecPuppetSupport
54
54
 
55
55
  # create spec_helper if missing
56
56
  return if File.file?('spec/spec_helper.rb')
57
- File.open('spec/spec_helper.rb', 'w') { |file| file.puts "require 'rspec-puppet'\n\nfixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))\n\nRSpec.configure do |c|\n c.module_path = File.join(fixture_path, 'modules')\n c.manifest_dir = File.join(fixture_path, 'manifests')\n c.manifest = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests', 'site.pp')\n c.environmentpath = File.join(Dir.pwd, 'spec')\nend" }
57
+ File.open('spec/spec_helper.rb', 'w') { |file| file.puts "require 'rspec-puppet/spec_helper'\n" }
58
58
  end
59
59
 
60
60
  # setup the module dependencies for rspec-puppet testing
@@ -0,0 +1,10 @@
1
+ {
2
+ "description": 1,
3
+ "supports_noop": "false",
4
+ "input_method": "unsupported",
5
+ "puppet_task_version": "1",
6
+ "parameters": [
7
+ "first",
8
+ "second"
9
+ ]
10
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "description": "Does the things.",
3
+ "supports_noop": false,
4
+ "input_method": "stdin",
5
+ "puppet_task_version": 1,
6
+ "parameters": {
7
+ "first": {
8
+ "description": "First param.",
9
+ "type": "Optional[String[1]]"
10
+ },
11
+ "second": {
12
+ "description": "Second param.",
13
+ "type": "Optional[String[1]]"
14
+ }
15
+ }
16
+ }
@@ -18,7 +18,7 @@ describe DataParser do
18
18
  it 'puts a good yaml file with potential hiera issues in the warning files array' do
19
19
  DataParser.yaml([fixtures_dir + 'hieradata/style.yaml'])
20
20
  expect(PuppetCheck.settings[:error_files]).to eql([])
21
- expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}hieradata/style.yaml:\nValue\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera will fail to parse it correctly})
21
+ expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}hieradata/style.yaml:\nValue\(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})
22
22
  expect(PuppetCheck.settings[:clean_files]).to eql([])
23
23
  end
24
24
  it 'puts a good yaml file in the clean files array' do
@@ -90,6 +90,12 @@ describe DataParser do
90
90
  expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}metadata_style_two/metadata.json:\n'puppetlabs/one' has non-semantic versioning.*\n'puppetlabs/two' is missing an upper bound\.\n.*operatingsystem.*\n.*operatingsystemrelease})
91
91
  expect(PuppetCheck.settings[:clean_files]).to eql([])
92
92
  end
93
+ it 'puts a bad task metadata json file in the warning files array' do
94
+ DataParser.json([fixtures_dir + 'task_metadata/task_bad.json'])
95
+ expect(PuppetCheck.settings[:error_files]).to eql([])
96
+ expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}task_metadata/task_bad.json:\ndescription 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})
97
+ expect(PuppetCheck.settings[:clean_files]).to eql([])
98
+ end
93
99
  it 'puts a good json file in the clean files array' do
94
100
  DataParser.json([fixtures_dir + 'hieradata/good.json'])
95
101
  expect(PuppetCheck.settings[:error_files]).to eql([])
@@ -102,5 +108,11 @@ describe DataParser do
102
108
  expect(PuppetCheck.settings[:warning_files]).to eql([])
103
109
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}metadata_good/metadata.json"])
104
110
  end
111
+ it 'puts a good task metadata json file in the clean files array' do
112
+ DataParser.json([fixtures_dir + 'task_metadata/task_good.json'])
113
+ expect(PuppetCheck.settings[:error_files]).to eql([])
114
+ expect(PuppetCheck.settings[:warning_files]).to eql([])
115
+ expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}task_metadata/task_good.json"])
116
+ end
105
117
  end
106
118
  end
@@ -14,7 +14,6 @@ describe RegressionCheck do
14
14
  expect { RegressionCheck.config(octocatalog_diff_dir + 'octocatalog-diff.cfg.rb') }.not_to raise_exception
15
15
  end
16
16
  it 'loads in the settings from the file correctly' do
17
- #
18
17
  end
19
18
  end
20
19
 
@@ -34,6 +33,5 @@ describe RegressionCheck do
34
33
  end
35
34
 
36
35
  context '.regression' do
37
- #
38
36
  end
39
37
  end
@@ -41,7 +41,7 @@ describe PuppetCheck do
41
41
  let(:repeats) { PuppetCheck.parse_paths(['hieradata', 'hieradata', 'lib', 'hieradata/good.json', 'manifests/good.pp', 'manifests/good.pp']) }
42
42
 
43
43
  it 'raises an error if no files were found' do
44
- expect { no_files }.to raise_error(RuntimeError, 'puppet-check: no files found in supplied paths foo, bar, baz.')
44
+ expect { no_files }.to raise_error(RuntimeError, 'puppet-check: no files found in supplied paths \'foo, bar, baz\'.')
45
45
  end
46
46
 
47
47
  it 'correctly parses one file and returns it' do
@@ -50,7 +50,7 @@ describe PuppetCheck do
50
50
 
51
51
  it 'correctly parses one directory and returns all of its files' do
52
52
  dir.each { |file| expect(File.file?(file)).to be true }
53
- expect(dir.length).to eql(35)
53
+ expect(dir.length).to eql(37)
54
54
  end
55
55
 
56
56
  it 'correctly parses multiple directories and returns all of their files' do
@@ -18,8 +18,8 @@ describe PuppetCheck do
18
18
  expect { cli }.not_to raise_exception
19
19
 
20
20
  expect(PuppetCheck.settings[:error_files].length).to eql(9)
21
- expect(PuppetCheck.settings[:warning_files].length).to eql(9)
22
- expect(PuppetCheck.settings[:clean_files].length).to eql(11)
21
+ expect(PuppetCheck.settings[:warning_files].length).to eql(10)
22
+ expect(PuppetCheck.settings[:clean_files].length).to eql(12)
23
23
  expect(PuppetCheck.settings[:ignored_files].length).to eql(6)
24
24
 
25
25
  expect(cli).to eql(2)
@@ -49,8 +49,8 @@ describe PuppetCheck do
49
49
  expect { tasks }.not_to raise_exception
50
50
 
51
51
  expect(PuppetCheck.settings[:error_files].length).to eql(9)
52
- expect(PuppetCheck.settings[:warning_files].length).to eql(9)
53
- expect(PuppetCheck.settings[:clean_files].length).to eql(11)
52
+ expect(PuppetCheck.settings[:warning_files].length).to eql(10)
53
+ expect(PuppetCheck.settings[:clean_files].length).to eql(12)
54
54
  expect(PuppetCheck.settings[:ignored_files].length).to eql(6)
55
55
  end
56
56
  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: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Schuchard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-12 00:00:00.000000000 Z
11
+ date: 2018-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '3.7'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6'
22
+ version: '7'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '3.7'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6'
32
+ version: '7'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: puppet-lint
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -48,16 +48,22 @@ dependencies:
48
48
  name: reek
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '4.0'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '6'
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
- - - "~>"
61
+ - - ">"
59
62
  - !ruby/object:Gem::Version
60
63
  version: '4.0'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '6'
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: rubocop
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +193,8 @@ files:
187
193
  - spec/fixtures/metadata_syntax/metadata.json
188
194
  - spec/fixtures/spec/facter/facter_spec.rb
189
195
  - spec/fixtures/spec/fixtures/do_not_parse_me
196
+ - spec/fixtures/task_metadata/task_bad.json
197
+ - spec/fixtures/task_metadata/task_good.json
190
198
  - spec/fixtures/templates/good.epp
191
199
  - spec/fixtures/templates/good.erb
192
200
  - spec/fixtures/templates/no_method_error.erb
@@ -265,6 +273,8 @@ test_files:
265
273
  - spec/fixtures/metadata_syntax/metadata.json
266
274
  - spec/fixtures/spec/facter/facter_spec.rb
267
275
  - spec/fixtures/spec/fixtures/do_not_parse_me
276
+ - spec/fixtures/task_metadata/task_bad.json
277
+ - spec/fixtures/task_metadata/task_good.json
268
278
  - spec/fixtures/templates/good.epp
269
279
  - spec/fixtures/templates/good.erb
270
280
  - spec/fixtures/templates/no_method_error.erb