puppet-check 2.2.2 → 2.3.1
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +1 -4
- data/lib/puppet-check/cli.rb +6 -2
- data/lib/puppet-check/data_parser.rb +120 -119
- data/lib/puppet-check/output_results.rb +27 -18
- data/lib/puppet-check/puppet_parser.rb +8 -5
- data/lib/puppet-check/regression_check.rb +28 -23
- data/lib/puppet-check/ruby_parser.rb +21 -16
- data/lib/puppet_check.rb +41 -45
- data/puppet-check.gemspec +23 -0
- data/spec/octocatalog-diff/octocatalog_diff.cfg.rb +1 -5
- data/spec/puppet-check/cli_spec.rb +5 -3
- data/spec/puppet-check/data_parser_spec.rb +14 -13
- data/spec/puppet-check/output_results_spec.rb +4 -4
- data/spec/puppet-check/puppet_parser_spec.rb +8 -8
- data/spec/puppet-check/regression_check_spec.rb +31 -25
- data/spec/puppet-check/rspec_puppet_support_spec.rb +1 -4
- data/spec/puppet-check/ruby_parser_spec.rb +7 -7
- data/spec/puppet_check_spec.rb +5 -1
- data/spec/system/system_spec.rb +12 -12
- metadata +11 -30
data/lib/puppet_check.rb
CHANGED
@@ -13,7 +13,7 @@ class PuppetCheck
|
|
13
13
|
ignored: []
|
14
14
|
}
|
15
15
|
|
16
|
-
# allow the parser methods write to the files
|
16
|
+
# allow the parser methods to write to the files
|
17
17
|
class << self
|
18
18
|
attr_accessor :files
|
19
19
|
end
|
@@ -27,7 +27,7 @@ class PuppetCheck
|
|
27
27
|
files = self.class.parse_paths(paths)
|
28
28
|
|
29
29
|
# parse the files
|
30
|
-
parsed_files = execute_parsers(files, settings)
|
30
|
+
parsed_files = execute_parsers(files, settings[:style], settings[:puppetlint_args], settings[:rubocop_args], settings[:public], settings[:private])
|
31
31
|
|
32
32
|
# output the diagnostic results
|
33
33
|
OutputResults.run(parsed_files.clone, settings[:output_format])
|
@@ -36,14 +36,12 @@ class PuppetCheck
|
|
36
36
|
if parsed_files[:errors].empty? && (!settings[:fail_on_warning] || 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
|
-
return 0
|
42
|
-
end
|
43
39
|
|
44
|
-
|
45
|
-
begin
|
40
|
+
# perform smoke checks if there were no errors and the user desires
|
46
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'
|
47
45
|
# smoke check failure? output message and return 2
|
48
46
|
rescue OctocatalogDiff::Errors::CatalogError => err
|
49
47
|
puts 'There was a smoke check error:'
|
@@ -60,6 +58,7 @@ class PuppetCheck
|
|
60
58
|
# puts catalog.error_message unless catalog.valid?
|
61
59
|
# 2
|
62
60
|
# end
|
61
|
+
|
63
62
|
# code to output differences in catalog?
|
64
63
|
# everything passed? return 0
|
65
64
|
0
|
@@ -72,29 +71,26 @@ class PuppetCheck
|
|
72
71
|
# establish default settings
|
73
72
|
def self.defaults(settings = {})
|
74
73
|
private_class_method :method
|
75
|
-
# initialize fail on warning, style check, and regression check bools
|
76
|
-
settings[:fail_on_warning] ||= false
|
77
|
-
settings[:style] ||= false
|
78
|
-
settings[:smoke] ||= false
|
79
|
-
settings[:regression] ||= false
|
80
|
-
|
81
|
-
# initialize ssl keys for eyaml checks
|
82
|
-
settings[:public] ||= nil
|
83
|
-
settings[:private] ||= nil
|
84
74
|
|
85
|
-
#
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
75
|
+
# return settings with defaults where unspecified
|
76
|
+
{
|
77
|
+
# initialize fail on warning, style check, and regression check bools
|
78
|
+
fail_on_warning: false,
|
79
|
+
style: false,
|
80
|
+
smoke: false,
|
81
|
+
regression: false,
|
82
|
+
# initialize ssl keys for eyaml checks
|
83
|
+
public: nil,
|
84
|
+
private: nil,
|
85
|
+
# initialize output format option
|
86
|
+
output_format: 'text',
|
87
|
+
# initialize octocatalog-diff options
|
88
|
+
octoconfig: '.octocatalog-diff.cfg.rb',
|
89
|
+
octonodes: %w[localhost.localdomain],
|
90
|
+
# initialize style arg arrays
|
91
|
+
puppetlint_args: [],
|
92
|
+
rubocop_args: []
|
93
|
+
}.merge(settings)
|
98
94
|
end
|
99
95
|
|
100
96
|
# parse the paths and return the array of files
|
@@ -102,36 +98,36 @@ class PuppetCheck
|
|
102
98
|
private_class_method :method
|
103
99
|
files = []
|
104
100
|
|
105
|
-
# traverse the unique paths and return all files
|
101
|
+
# traverse the unique paths and return all files not explicitly in fixtures
|
106
102
|
paths.uniq.each do |path|
|
107
103
|
if File.directory?(path)
|
108
|
-
|
109
|
-
|
104
|
+
# glob all files in directory and concat them
|
105
|
+
files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?(subpath) && !subpath.include?('fixtures') })
|
106
|
+
elsif File.file?(path) && !path.include?('fixtures')
|
110
107
|
files.push(path)
|
108
|
+
else
|
109
|
+
warn "puppet-check: #{path} is not a directory, file, or symlink, and will not be considered during parsing"
|
111
110
|
end
|
112
111
|
end
|
113
112
|
|
114
|
-
#
|
115
|
-
files.reject! { |file| file.include?('fixtures') }
|
113
|
+
# check that at least one file was found, and remove double slashes from returned array
|
116
114
|
raise "puppet-check: no files found in supplied paths '#{paths.join(', ')}'." if files.empty?
|
117
|
-
files.map
|
118
|
-
|
119
|
-
files.uniq
|
115
|
+
files.map { |file| file.gsub('//', '/') }.uniq
|
120
116
|
end
|
121
117
|
|
122
118
|
private
|
123
119
|
|
124
120
|
# categorize and pass the files out to the parsers to determine their status
|
125
|
-
def execute_parsers(files,
|
121
|
+
def execute_parsers(files, style, puppetlint_args, rubocop_args, public, private)
|
126
122
|
# check manifests
|
127
123
|
manifests, files = files.partition { |file| File.extname(file) == '.pp' }
|
128
|
-
PuppetParser.manifest(manifests,
|
124
|
+
PuppetParser.manifest(manifests, style, puppetlint_args) unless manifests.empty?
|
129
125
|
# check puppet templates
|
130
126
|
templates, files = files.partition { |file| File.extname(file) == '.epp' }
|
131
127
|
PuppetParser.template(templates) unless templates.empty?
|
132
128
|
# check ruby files
|
133
129
|
rubies, files = files.partition { |file| File.extname(file) == '.rb' }
|
134
|
-
RubyParser.ruby(rubies,
|
130
|
+
RubyParser.ruby(rubies, style, rubocop_args) unless rubies.empty?
|
135
131
|
# check ruby templates
|
136
132
|
templates, files = files.partition { |file| File.extname(file) == '.erb' }
|
137
133
|
RubyParser.template(templates) unless templates.empty?
|
@@ -142,11 +138,11 @@ class PuppetCheck
|
|
142
138
|
jsons, files = files.partition { |file| File.extname(file) == '.json' }
|
143
139
|
DataParser.json(jsons) unless jsons.empty?
|
144
140
|
# check eyaml data; block this for now
|
145
|
-
|
146
|
-
|
141
|
+
eyamls, files = files.partition { |file| File.extname(file) =~ /\.eya?ml$/ }
|
142
|
+
DataParser.eyaml(eyamls, public, private) unless eyamls.empty?
|
147
143
|
# check misc ruby
|
148
|
-
librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
|
149
|
-
RubyParser.librarian(librarians,
|
144
|
+
librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem|Vagrant)file|.gemspec$/ }
|
145
|
+
RubyParser.librarian(librarians, style, rubocop_args) unless librarians.empty?
|
150
146
|
# ignore everything else
|
151
147
|
files.each { |file| self.class.files[:ignored].push(file.to_s) }
|
152
148
|
# return PuppetCheck.files to mitigate singleton write accessor side effects
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'puppet-check'
|
3
|
+
spec.version = '2.3.1'
|
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 = '>= 2.7.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.0'
|
19
|
+
spec.add_dependency 'rubocop-performance', '~> 1.0'
|
20
|
+
# spec.add_development_dependency 'octocatalog-diff', '~> 2.0'
|
21
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
23
|
+
end
|
@@ -9,11 +9,7 @@ module OctocatalogDiff
|
|
9
9
|
settings[:hiera_config] = "#{octocatalog_diff_dir}hiera.yaml"
|
10
10
|
settings[:hiera_path] = "#{octocatalog_diff_dir}hieradata"
|
11
11
|
settings[:fact_file] = "#{octocatalog_diff_dir}facts.yaml"
|
12
|
-
settings[:puppet_binary] =
|
13
|
-
"#{octocatalog_diff_dir}../../bin/puppet"
|
14
|
-
else
|
15
|
-
'/usr/local/bin/puppet'
|
16
|
-
end
|
12
|
+
settings[:puppet_binary] = '/usr/local/bin/puppet'
|
17
13
|
settings[:bootstrapped_to_dir] = octocatalog_diff_dir
|
18
14
|
|
19
15
|
settings
|
@@ -3,14 +3,16 @@ require_relative '../../lib/puppet-check/cli'
|
|
3
3
|
|
4
4
|
describe PuppetCheck::CLI do
|
5
5
|
context '.run' do
|
6
|
-
it '
|
7
|
-
expect { PuppetCheck::CLI.run(%w[-
|
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
|
+
expect(PuppetCheck.files[:ignored].length).to eql(7)
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
11
13
|
context '.parse' do
|
12
14
|
it 'raises an error if an invalid option was specified' do
|
13
|
-
expect { PuppetCheck::CLI.parse(%w[-s -
|
15
|
+
expect { PuppetCheck::CLI.parse(%w[-s -asdf foo]) }.to raise_error(OptionParser::InvalidOption)
|
14
16
|
end
|
15
17
|
|
16
18
|
it 'allows fail on warnings, style, smoke, and regression checks to be enabled' do
|
@@ -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(
|
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(
|
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
|
@@ -45,23 +45,24 @@ describe DataParser do
|
|
45
45
|
expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', 'private.pem') }.to output("Specified Public X509 and/or Private RSA PKCS7 certs do not exist. EYAML checks will not be executed.\n").to_stderr
|
46
46
|
end
|
47
47
|
it 'puts a bad syntax eyaml file in the error files hash' do
|
48
|
-
|
49
|
-
|
48
|
+
DataParser.eyaml(["#{fixtures_dir}hieradata/syntax.eyaml"], "#{fixtures_dir}keys/public_key.pkcs7.pem", "#{fixtures_dir}keys/private_key.pkcs7.pem")
|
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(/^block sequence entries are not allowed/)
|
50
51
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
51
52
|
expect(PuppetCheck.files[:clean]).to eql([])
|
52
53
|
end
|
53
54
|
it 'puts a good eyaml file with potential hiera issues in the warning files array' do
|
54
|
-
|
55
|
+
DataParser.eyaml(["#{fixtures_dir}hieradata/style.eyaml"], "#{fixtures_dir}keys/public_key.pkcs7.pem", "#{fixtures_dir}keys/private_key.pkcs7.pem")
|
55
56
|
expect(PuppetCheck.files[:errors]).to eql({})
|
56
|
-
|
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(/^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
59
|
expect(PuppetCheck.files[:clean]).to eql([])
|
59
60
|
end
|
60
61
|
it 'puts a good eyaml file in the clean files array' do
|
61
|
-
|
62
|
+
DataParser.eyaml(["#{fixtures_dir}hieradata/good.eyaml"], "#{fixtures_dir}keys/public_key.pkcs7.pem", "#{fixtures_dir}keys/private_key.pkcs7.pem")
|
62
63
|
expect(PuppetCheck.files[:errors]).to eql({})
|
63
64
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
64
|
-
|
65
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}hieradata/good.eyaml"])
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
@@ -69,14 +70,14 @@ describe DataParser do
|
|
69
70
|
it 'puts a bad syntax json file in the error files hash' do
|
70
71
|
DataParser.json(["#{fixtures_dir}hieradata/syntax.json"])
|
71
72
|
expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}hieradata/syntax.json"])
|
72
|
-
expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.json"].join("\n")).to match(
|
73
|
+
expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.json"].join("\n")).to match(/after object value, got.*at line 2 column 3/)
|
73
74
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
74
75
|
expect(PuppetCheck.files[:clean]).to eql([])
|
75
76
|
end
|
76
77
|
it 'puts a bad metadata json file in the error files hash' do
|
77
78
|
DataParser.json(["#{fixtures_dir}metadata_syntax/metadata.json"])
|
78
79
|
expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}metadata_syntax/metadata.json"])
|
79
|
-
expect(PuppetCheck.files[:errors]["#{fixtures_dir}metadata_syntax/metadata.json"].join("\n")).to match(
|
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/)
|
80
81
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
81
82
|
expect(PuppetCheck.files[:clean]).to eql([])
|
82
83
|
end
|
@@ -84,7 +85,7 @@ describe DataParser do
|
|
84
85
|
DataParser.json(["#{fixtures_dir}metadata_style/metadata.json"])
|
85
86
|
expect(PuppetCheck.files[:errors]).to eql({})
|
86
87
|
expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}metadata_style/metadata.json"])
|
87
|
-
expect(PuppetCheck.files[:warnings]["#{fixtures_dir}metadata_style/metadata.json"].join("\n")).to match(
|
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/)
|
88
89
|
expect(PuppetCheck.files[:clean]).to eql([])
|
89
90
|
end
|
90
91
|
it 'puts another bad style metadata json file in the warning files array' do
|
@@ -98,7 +99,7 @@ describe DataParser do
|
|
98
99
|
DataParser.json(["#{fixtures_dir}task_metadata/task_bad.json"])
|
99
100
|
expect(PuppetCheck.files[:errors]).to eql({})
|
100
101
|
expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}task_metadata/task_bad.json"])
|
101
|
-
expect(PuppetCheck.files[:warnings]["#{fixtures_dir}task_metadata/task_bad.json"].join("\n")).to match(
|
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/)
|
102
103
|
expect(PuppetCheck.files[:clean]).to eql([])
|
103
104
|
end
|
104
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").to_stdout
|
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
|
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("\
|
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
|
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("\
|
16
|
+
expect { OutputResults.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("\
|
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
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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.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.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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
context '.smoke' do
|
21
|
+
# octocatalog-diff is returning a blank error for these tests
|
22
|
+
unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
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
|
25
|
-
|
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
|
-
|
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
|
@@ -14,11 +14,8 @@ describe RSpecPuppetSupport do
|
|
14
14
|
before(:each) { Dir.chdir(fixtures_dir) }
|
15
15
|
|
16
16
|
it 'creates missing directories, missing site.pp, missing symlinks, and a missing spec_helper' do
|
17
|
-
# travis ci
|
18
|
-
if ENV['TRAVIS'] == 'true'
|
19
|
-
expect { rspec_puppet_setup }.to output("puppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
|
20
17
|
# circle ci and gh actions
|
21
|
-
|
18
|
+
if ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
22
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
|
23
20
|
else
|
24
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
|
@@ -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(
|
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,7 @@ 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(
|
26
|
+
expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment/)
|
27
27
|
expect(PuppetCheck.files[:clean]).to eql([])
|
28
28
|
end
|
29
29
|
it 'puts a bad style ruby file in the clean files array when rubocop_args ignores its warnings' do
|
@@ -45,9 +45,9 @@ describe RubyParser do
|
|
45
45
|
RubyParser.template(["#{fixtures_dir}templates/syntax.erb"])
|
46
46
|
expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}templates/syntax.erb"])
|
47
47
|
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(
|
48
|
+
expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(/1: syntax error, unexpected.*\n.*ruby/)
|
49
49
|
else
|
50
|
-
expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(
|
50
|
+
expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(/syntax error, unexpected tIDENTIFIER/)
|
51
51
|
end
|
52
52
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
53
53
|
expect(PuppetCheck.files[:clean]).to eql([])
|
@@ -56,7 +56,7 @@ describe RubyParser do
|
|
56
56
|
RubyParser.template(["#{fixtures_dir}templates/style.erb"])
|
57
57
|
expect(PuppetCheck.files[:errors]).to eql({})
|
58
58
|
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(
|
59
|
+
expect(PuppetCheck.files[:warnings]["#{fixtures_dir}templates/style.erb"].join("\n")).to match(/already initialized constant.*\n.*previous definition of/)
|
60
60
|
expect(PuppetCheck.files[:clean]).to eql([])
|
61
61
|
end
|
62
62
|
it 'puts a ruby template file with ignored errors in the clean files array' do
|
@@ -77,7 +77,7 @@ describe RubyParser do
|
|
77
77
|
it 'puts a bad syntax librarian Puppet file in the error files hash' do
|
78
78
|
RubyParser.librarian(["#{fixtures_dir}librarian_syntax/Puppetfile"], false, [])
|
79
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(
|
80
|
+
expect(PuppetCheck.files[:errors]["#{fixtures_dir}librarian_syntax/Puppetfile"].join("\n")).to match(/^.*syntax error/)
|
81
81
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
82
82
|
expect(PuppetCheck.files[:clean]).to eql([])
|
83
83
|
end
|
@@ -85,7 +85,7 @@ describe RubyParser do
|
|
85
85
|
RubyParser.librarian(["#{fixtures_dir}librarian_style/Puppetfile"], true, [])
|
86
86
|
expect(PuppetCheck.files[:errors]).to eql({})
|
87
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(
|
88
|
+
expect(PuppetCheck.files[:warnings]["#{fixtures_dir}librarian_style/Puppetfile"].join("\n")).to match(/Align the arguments.*\n.*Use the new/)
|
89
89
|
expect(PuppetCheck.files[:clean]).to eql([])
|
90
90
|
end
|
91
91
|
it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
|
data/spec/puppet_check_spec.rb
CHANGED
@@ -87,7 +87,11 @@ 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
|
-
|
90
|
+
if ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
91
|
+
expect(dir.length).to eql(37)
|
92
|
+
else
|
93
|
+
expect(dir.length).to eql(40)
|
94
|
+
end
|
91
95
|
end
|
92
96
|
|
93
97
|
it 'correctly parses multiple directories and returns all of their files' do
|
data/spec/system/system_spec.rb
CHANGED
@@ -6,10 +6,10 @@ require_relative '../../lib/puppet-check/tasks'
|
|
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
8
|
# see regression_check_spec
|
9
|
-
if ENV['
|
10
|
-
let(:cli) { PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding .]) }
|
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
11
|
else
|
12
|
-
let(:cli) { PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --smoke -n good.example.com --octoconfig spec/octocatalog-diff/octocatalog-diff.cfg.rb .]) }
|
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
13
|
end
|
14
14
|
|
15
15
|
it 'outputs diagnostic results correctly after processing all of the files' do
|
@@ -17,10 +17,10 @@ describe PuppetCheck do
|
|
17
17
|
|
18
18
|
expect { cli }.not_to raise_exception
|
19
19
|
|
20
|
-
expect(PuppetCheck.files[:errors].length).to eql(
|
21
|
-
expect(PuppetCheck.files[:warnings].length).to eql(
|
22
|
-
expect(PuppetCheck.files[:clean].length).to eql(
|
23
|
-
expect(PuppetCheck.files[:ignored].length).to eql(
|
20
|
+
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)
|
23
|
+
expect(PuppetCheck.files[:ignored].length).to eql(3)
|
24
24
|
|
25
25
|
expect(cli).to eql(2)
|
26
26
|
end
|
@@ -40,7 +40,7 @@ describe PuppetCheck do
|
|
40
40
|
}
|
41
41
|
settings = { style: true }
|
42
42
|
# see regression_check_spec
|
43
|
-
unless ENV['
|
43
|
+
unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
44
44
|
settings[:smoke] = true
|
45
45
|
settings[:octonodes] = %w[good.example.com]
|
46
46
|
settings[:octoconfig] = 'spec/octocatalog-diff/octocatalog-diff.cfg.rb'
|
@@ -50,10 +50,10 @@ describe PuppetCheck do
|
|
50
50
|
expect { Rake::Task[:'puppetcheck:file'].invoke(settings) }.to raise_error(ArgumentError, /Attempt to redefine entity/)
|
51
51
|
|
52
52
|
# current puppet pops limitations no longer allow testing this
|
53
|
-
# expect(PuppetCheck.files[:errors].length).to eql(
|
54
|
-
# expect(PuppetCheck.files[:warnings].length).to eql(
|
55
|
-
# expect(PuppetCheck.files[:clean].length).to eql(
|
56
|
-
# expect(PuppetCheck.files[:ignored].length).to eql(
|
53
|
+
# expect(PuppetCheck.files[:errors].length).to eql(11)
|
54
|
+
# expect(PuppetCheck.files[:warnings].length).to eql(12)
|
55
|
+
# expect(PuppetCheck.files[:clean].length).to eql(14)
|
56
|
+
# expect(PuppetCheck.files[:ignored].length).to eql(3)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|