puppet-check 1.6.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,19 +19,19 @@ class PuppetCheck
19
19
  self.class.settings = settings
20
20
 
21
21
  # settings defaults
22
- self.class.defaults
22
+ self.class.defaults(settings)
23
23
 
24
24
  # grab all of the files to be processed
25
25
  files = self.class.parse_paths(paths)
26
26
 
27
27
  # parse the files
28
- execute_parsers(files, settings[:future_parser], settings[:style_check], settings[:public], settings[:private], settings[:puppetlint_args], settings[:rubocop_args])
28
+ execute_parsers(files, settings)
29
29
 
30
30
  # output the diagnostic results
31
- settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup
31
+ settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup(settings[:output_format])
32
32
 
33
33
  # progress to regression checks if no errors in file checks
34
- if self.class.settings[:error_files].empty? && (!self.class.settings[:fail_on_warning] || self.class.settings[:warning_files].empty?)
34
+ if self.class.settings[:error_files].empty? && (!settings[:fail_on_warning] || self.class.settings[:warning_files].empty?)
35
35
  begin
36
36
  require_relative 'puppet-check/regression_check'
37
37
  # if octocatalog-diff is not installed then return immediately
@@ -41,7 +41,7 @@ class PuppetCheck
41
41
 
42
42
  # perform smoke checks if there were no errors and the user desires
43
43
  begin
44
- catalog = RegressionCheck.smoke(settings[:octonodes], settings[:octoconfig]) if settings[:smoke_check]
44
+ catalog = RegressionCheck.smoke(settings[:octonodes], settings[:octoconfig]) if settings[:smoke]
45
45
  # smoke check failure? output message and return 2
46
46
  rescue OctocatalogDiff::Errors::CatalogError => err
47
47
  puts 'There was a smoke check error:'
@@ -51,7 +51,7 @@ class PuppetCheck
51
51
  end
52
52
  # perform regression checks if there were no errors and the user desires
53
53
  # begin
54
- # catalog = RegressionCheck.regression(settings[:octonodes], settings[:octoconfig]) if settings[:regression_check]
54
+ # catalog = RegressionCheck.regression(settings[:octonodes], settings[:octoconfig]) if settings[:regression]
55
55
  # rescue OctocatalogDiff::Errors::CatalogError => err
56
56
  # puts 'There was a catalog compilation error during the regression check:'
57
57
  # puts err
@@ -68,20 +68,19 @@ class PuppetCheck
68
68
  end
69
69
 
70
70
  # establish default settings
71
- def self.defaults
72
- # initialize future parser, fail on warning, style check, and regression check bools
73
- @settings[:future_parser] ||= false
74
- @settings[:fail_on_warning] ||= false
75
- @settings[:style_check] ||= false
76
- @settings[:smoke_check] ||= false
77
- @settings[:regression_check] ||= false
71
+ def self.defaults(settings)
72
+ # initialize fail on warning, style check, and regression check bools
73
+ settings[:fail_on_warning] ||= false
74
+ settings[:style] ||= false
75
+ settings[:smoke] ||= false
76
+ settings[:regression] ||= false
78
77
 
79
78
  # initialize ssl keys for eyaml checks
80
- @settings[:public] ||= nil
81
- @settings[:private] ||= nil
79
+ settings[:public] ||= nil
80
+ settings[:private] ||= nil
82
81
 
83
82
  # initialize output format option
84
- @settings[:output_format] ||= 'text'
83
+ settings[:output_format] ||= 'text'
85
84
 
86
85
  # initialize diagnostic output arrays
87
86
  @settings[:error_files] = []
@@ -90,12 +89,12 @@ class PuppetCheck
90
89
  @settings[:ignored_files] = []
91
90
 
92
91
  # initialize octocatalog-diff options
93
- @settings[:octoconfig] ||= '.octocatalog-diff.cfg.rb'
94
- @settings[:octonodes] ||= %w[localhost.localdomain]
92
+ settings[:octoconfig] ||= '.octocatalog-diff.cfg.rb'
93
+ settings[:octonodes] ||= %w[localhost.localdomain]
95
94
 
96
95
  # initialize style arg arrays
97
- @settings[:puppetlint_args] ||= []
98
- @settings[:rubocop_args] ||= []
96
+ settings[:puppetlint_args] ||= []
97
+ settings[:rubocop_args] ||= []
99
98
  end
100
99
 
101
100
  # parse the paths and return the array of files
@@ -120,16 +119,16 @@ class PuppetCheck
120
119
  end
121
120
 
122
121
  # categorize and pass the files out to the parsers to determine their status
123
- def execute_parsers(files, future, style, public, private, pl_args, rc_args)
122
+ def execute_parsers(files, settings)
124
123
  # check manifests
125
124
  manifests, files = files.partition { |file| File.extname(file) == '.pp' }
126
- PuppetParser.manifest(manifests, future, style, pl_args) unless manifests.empty?
125
+ PuppetParser.manifest(manifests, settings[:style], settings[:puppetlint_args]) unless manifests.empty?
127
126
  # check puppet templates
128
127
  templates, files = files.partition { |file| File.extname(file) == '.epp' }
129
128
  PuppetParser.template(templates) unless templates.empty?
130
129
  # check ruby files
131
130
  rubies, files = files.partition { |file| File.extname(file) == '.rb' }
132
- RubyParser.ruby(rubies, style, rc_args) unless rubies.empty?
131
+ RubyParser.ruby(rubies, settings[:style], settings[:rubocop_args]) unless rubies.empty?
133
132
  # check ruby templates
134
133
  templates, files = files.partition { |file| File.extname(file) == '.erb' }
135
134
  RubyParser.template(templates) unless templates.empty?
@@ -144,7 +143,7 @@ class PuppetCheck
144
143
  # DataParser.eyaml(eyamls, public, private) unless eyamls.empty?
145
144
  # check misc ruby
146
145
  librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
147
- RubyParser.librarian(librarians, style, rc_args) unless librarians.empty?
146
+ RubyParser.librarian(librarians, settings[:style], settings[:rubocop_args]) unless librarians.empty?
148
147
  # ignore everything else
149
148
  self.class.settings[:ignored_files].concat(files)
150
149
  end
@@ -4,13 +4,13 @@ module OctocatalogDiff
4
4
  class Config
5
5
  def self.config
6
6
  settings = {}
7
- octocatalog_diff_dir = File.dirname(__FILE__) + '/'
7
+ octocatalog_diff_dir = "#{File.dirname(__FILE__)}/"
8
8
 
9
- settings[:hiera_config] = octocatalog_diff_dir + 'hiera.yaml'
10
- settings[:hiera_path] = octocatalog_diff_dir + 'hieradata'
11
- settings[:fact_file] = octocatalog_diff_dir + 'facts.yaml'
12
- settings[:puppet_binary] = if File.directory?('/home/travis')
13
- octocatalog_diff_dir + '../../bin/puppet'
9
+ settings[:hiera_config] = "#{octocatalog_diff_dir}hiera.yaml"
10
+ settings[:hiera_path] = "#{octocatalog_diff_dir}hieradata"
11
+ settings[:fact_file] = "#{octocatalog_diff_dir}facts.yaml"
12
+ settings[:puppet_binary] = if ENV['TRAVIS'] == 'true'
13
+ "#{octocatalog_diff_dir}../../bin/puppet"
14
14
  else
15
15
  '/usr/local/bin/puppet'
16
16
  end
@@ -13,8 +13,8 @@ describe PuppetCheck::CLI do
13
13
  expect { PuppetCheck::CLI.parse(%w[-s -f -asdf foo]) }.to raise_error(OptionParser::InvalidOption)
14
14
  end
15
15
 
16
- it 'allows future parser, fail on warnings, style, smoke, and regression checks to be enabled' do
17
- expect(PuppetCheck::CLI.parse(%w[-f --fail-on-warnings -s -r --smoke foo])).to include(future_parser: true, fail_on_warnings: true, style_check: true, smoke_check: true, regression_check: true)
16
+ 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)
18
18
  end
19
19
 
20
20
  it 'correctly parser EYAML options' do
@@ -42,7 +42,7 @@ describe PuppetCheck::CLI do
42
42
  end
43
43
 
44
44
  it 'correctly parses multiple sets of arguments' do
45
- expect(PuppetCheck::CLI.parse(%w[-s -f --puppet-lint puppetlint-arg-one,puppetlint-arg-two --rubocop rubocop-arg-one,rubocop-arg-two foo])).to include(future_parser: true, style_check: true, puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'], rubocop_args: ['--except', 'rubocop-arg-one,rubocop-arg-two'])
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'])
46
46
  end
47
47
  end
48
48
  end
@@ -10,106 +10,104 @@ describe DataParser do
10
10
 
11
11
  context '.yaml' do
12
12
  it 'puts a bad syntax yaml file in the error files array' do
13
- DataParser.yaml([fixtures_dir + 'hieradata/syntax.yaml'])
13
+ DataParser.yaml(["#{fixtures_dir}hieradata/syntax.yaml"])
14
14
  expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}hieradata/syntax.yaml:\nblock sequence entries are not allowed})
15
15
  expect(PuppetCheck.settings[:warning_files]).to eql([])
16
16
  expect(PuppetCheck.settings[:clean_files]).to eql([])
17
17
  end
18
18
  it 'puts a good yaml file with potential hiera issues in the warning files array' do
19
- DataParser.yaml([fixtures_dir + 'hieradata/style.yaml'])
19
+ DataParser.yaml(["#{fixtures_dir}hieradata/style.yaml"])
20
20
  expect(PuppetCheck.settings[:error_files]).to eql([])
21
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
25
- DataParser.yaml([fixtures_dir + 'hieradata/good.yaml'])
25
+ DataParser.yaml(["#{fixtures_dir}hieradata/good.yaml"])
26
26
  expect(PuppetCheck.settings[:error_files]).to eql([])
27
27
  expect(PuppetCheck.settings[:warning_files]).to eql([])
28
28
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}hieradata/good.yaml"])
29
29
  end
30
30
  end
31
31
 
32
- if RUBY_VERSION.to_f >= 2.3
33
- context '.eyaml' do
34
- before(:each) do
35
- PuppetCheck.settings[:ignored_files] = []
36
- end
32
+ context '.eyaml' do
33
+ before(:each) do
34
+ PuppetCheck.settings[:ignored_files] = []
35
+ end
37
36
 
38
- it 'returns a warning if a public key was not specified' do
39
- expect { DataParser.eyaml(['foo.eyaml'], nil, 'private.pem') }.to output("Public X509 and/or Private RSA PKCS7 certs were not specified. EYAML checks will not be executed.\n").to_stderr
40
- end
41
- it 'returns a warning if a private key was not specified' do
42
- expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', nil) }.to output("Public X509 and/or Private RSA PKCS7 certs were not specified. EYAML checks will not be executed.\n").to_stderr
43
- end
44
- it 'returns a warning if the public key or private key are not existing files' do
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
- end
47
- it 'puts a bad syntax eyaml file in the error files array' do
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.settings[:error_files][0]).to match(%r{^#{fixtures_dir}hieradata/syntax.eyaml:\nblock sequence entries are not allowed})
50
- expect(PuppetCheck.settings[:warning_files]).to eql([])
51
- expect(PuppetCheck.settings[:clean_files]).to eql([])
52
- end
53
- it 'puts a good eyaml file with potential hiera issues in the warning files array' do
54
- # DataParser.eyaml([fixtures_dir + 'hieradata/style.eyaml'], fixtures_dir + 'keys/public_key.pkcs7.pem', fixtures_dir + 'keys/private_key.pkcs7.pem')
55
- expect(PuppetCheck.settings[:error_files]).to eql([])
56
- # expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}hieradata/style.eyaml:\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})
57
- expect(PuppetCheck.settings[:clean_files]).to eql([])
58
- end
59
- it 'puts a good eyaml file in the clean files array' do
60
- # DataParser.eyaml([fixtures_dir + 'hieradata/good.eyaml'], fixtures_dir + 'keys/public_key.pkcs7.pem', fixtures_dir + 'keys/private_key.pkcs7.pem')
61
- expect(PuppetCheck.settings[:error_files]).to eql([])
62
- expect(PuppetCheck.settings[:warning_files]).to eql([])
63
- # expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}hieradata/good.eyaml"])
64
- end
37
+ it 'returns a warning if a public key was not specified' do
38
+ expect { DataParser.eyaml(['foo.eyaml'], nil, 'private.pem') }.to output("Public X509 and/or Private RSA PKCS7 certs were not specified. EYAML checks will not be executed.\n").to_stderr
39
+ end
40
+ it 'returns a warning if a private key was not specified' do
41
+ expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', nil) }.to output("Public X509 and/or Private RSA PKCS7 certs were not specified. EYAML checks will not be executed.\n").to_stderr
42
+ end
43
+ it 'returns a warning if the public key or private key are not existing files' do
44
+ 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
45
+ end
46
+ it 'puts a bad syntax eyaml file in the error files array' do
47
+ # DataParser.eyaml(["#{fixtures_dir}hieradata/syntax.eyaml'], fixtures_dir + 'keys/public_key.pkcs7.pem', fixtures_dir + 'keys/private_key.pkcs7.pem")
48
+ # expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}hieradata/syntax.eyaml:\nblock sequence entries are not allowed})
49
+ expect(PuppetCheck.settings[:warning_files]).to eql([])
50
+ expect(PuppetCheck.settings[:clean_files]).to eql([])
51
+ end
52
+ it 'puts a good eyaml file with potential hiera issues in the warning files array' do
53
+ # DataParser.eyaml(["#{fixtures_dir}hieradata/style.eyaml'], fixtures_dir + 'keys/public_key.pkcs7.pem', fixtures_dir + 'keys/private_key.pkcs7.pem")
54
+ expect(PuppetCheck.settings[:error_files]).to eql([])
55
+ # expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}hieradata/style.eyaml:\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})
56
+ expect(PuppetCheck.settings[:clean_files]).to eql([])
57
+ end
58
+ it 'puts a good eyaml file in the clean files array' do
59
+ # DataParser.eyaml(["#{fixtures_dir}hieradata/good.eyaml'], fixtures_dir + 'keys/public_key.pkcs7.pem', fixtures_dir + 'keys/private_key.pkcs7.pem")
60
+ expect(PuppetCheck.settings[:error_files]).to eql([])
61
+ expect(PuppetCheck.settings[:warning_files]).to eql([])
62
+ # expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}hieradata/good.eyaml"])
65
63
  end
66
64
  end
67
65
 
68
66
  context '.json' do
69
67
  it 'puts a bad syntax json file in the error files array' do
70
- DataParser.json([fixtures_dir + 'hieradata/syntax.json'])
68
+ DataParser.json(["#{fixtures_dir}hieradata/syntax.json"])
71
69
  expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}hieradata/syntax.json:\n.*unexpected token})
72
70
  expect(PuppetCheck.settings[:warning_files]).to eql([])
73
71
  expect(PuppetCheck.settings[:clean_files]).to eql([])
74
72
  end
75
73
  it 'puts a bad metadata json file in the error files array' do
76
- DataParser.json([fixtures_dir + 'metadata_syntax/metadata.json'])
74
+ DataParser.json(["#{fixtures_dir}metadata_syntax/metadata.json"])
77
75
  expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}metadata_syntax/metadata.json:\nRequired field.*\nField 'requirements'.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds})
78
76
  expect(PuppetCheck.settings[:warning_files]).to eql([])
79
77
  expect(PuppetCheck.settings[:clean_files]).to eql([])
80
78
  end
81
79
  it 'puts a bad style metadata json file in the warning files array' do
82
- DataParser.json([fixtures_dir + 'metadata_style/metadata.json'])
80
+ DataParser.json(["#{fixtures_dir}metadata_style/metadata.json"])
83
81
  expect(PuppetCheck.settings[:error_files]).to eql([])
84
82
  expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}metadata_style/metadata.json:\n'pe' is missing an upper bound.\n.*operatingsystem_support.*\nLicense identifier})
85
83
  expect(PuppetCheck.settings[:clean_files]).to eql([])
86
84
  end
87
85
  it 'puts another bad style metadata json file in the warning files array' do
88
- DataParser.json([fixtures_dir + 'metadata_style_two/metadata.json'])
86
+ DataParser.json(["#{fixtures_dir}metadata_style_two/metadata.json"])
89
87
  expect(PuppetCheck.settings[:error_files]).to eql([])
90
88
  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
89
  expect(PuppetCheck.settings[:clean_files]).to eql([])
92
90
  end
93
91
  it 'puts a bad task metadata json file in the warning files array' do
94
- DataParser.json([fixtures_dir + 'task_metadata/task_bad.json'])
92
+ DataParser.json(["#{fixtures_dir}task_metadata/task_bad.json"])
95
93
  expect(PuppetCheck.settings[:error_files]).to eql([])
96
94
  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
95
  expect(PuppetCheck.settings[:clean_files]).to eql([])
98
96
  end
99
97
  it 'puts a good json file in the clean files array' do
100
- DataParser.json([fixtures_dir + 'hieradata/good.json'])
98
+ DataParser.json(["#{fixtures_dir}hieradata/good.json"])
101
99
  expect(PuppetCheck.settings[:error_files]).to eql([])
102
100
  expect(PuppetCheck.settings[:warning_files]).to eql([])
103
101
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}hieradata/good.json"])
104
102
  end
105
103
  it 'puts a good metadata json file in the clean files array' do
106
- DataParser.json([fixtures_dir + 'metadata_good/metadata.json'])
104
+ DataParser.json(["#{fixtures_dir}metadata_good/metadata.json"])
107
105
  expect(PuppetCheck.settings[:error_files]).to eql([])
108
106
  expect(PuppetCheck.settings[:warning_files]).to eql([])
109
107
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}metadata_good/metadata.json"])
110
108
  end
111
109
  it 'puts a good task metadata json file in the clean files array' do
112
- DataParser.json([fixtures_dir + 'task_metadata/task_good.json'])
110
+ DataParser.json(["#{fixtures_dir}task_metadata/task_good.json"])
113
111
  expect(PuppetCheck.settings[:error_files]).to eql([])
114
112
  expect(PuppetCheck.settings[:warning_files]).to eql([])
115
113
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}task_metadata/task_good.json"])
@@ -37,48 +37,39 @@ describe OutputResults do
37
37
  end
38
38
 
39
39
  it 'outputs files with errors as yaml' do
40
- PuppetCheck.settings[:output_format] = 'yaml'
41
40
  PuppetCheck.settings[:error_files] = ['foo: i had an error']
42
- expect { OutputResults.markup }.to output("---\nerrors:\n- 'foo: i had an error'\n").to_stdout
41
+ expect { OutputResults.markup('yaml') }.to output("---\nerrors:\n- 'foo: i had an error'\n").to_stdout
43
42
  end
44
43
  it 'outputs files with warnings as yaml' do
45
- PuppetCheck.settings[:output_format] = 'yaml'
46
44
  PuppetCheck.settings[:warning_files] = ['foo: i had a warning']
47
- expect { OutputResults.markup }.to output("---\nwarnings:\n- 'foo: i had a warning'\n").to_stdout
45
+ expect { OutputResults.markup('yaml') }.to output("---\nwarnings:\n- 'foo: i had a warning'\n").to_stdout
48
46
  end
49
47
  it 'outputs files with no errors or warnings as yaml' do
50
- PuppetCheck.settings[:output_format] = 'yaml'
51
48
  PuppetCheck.settings[:clean_files] = ['foo: i was totally good to go']
52
- expect { OutputResults.markup }.to output("---\nclean:\n- 'foo: i was totally good to go'\n").to_stdout
49
+ expect { OutputResults.markup('yaml') }.to output("---\nclean:\n- 'foo: i was totally good to go'\n").to_stdout
53
50
  end
54
51
  it 'outputs files that were not processed as yaml' do
55
- PuppetCheck.settings[:output_format] = 'yaml'
56
52
  PuppetCheck.settings[:ignored_files] = ['foo: who knows what i am']
57
- expect { OutputResults.markup }.to output("---\nignored:\n- 'foo: who knows what i am'\n").to_stdout
53
+ expect { OutputResults.markup('yaml') }.to output("---\nignored:\n- 'foo: who knows what i am'\n").to_stdout
58
54
  end
59
55
  it 'outputs files with errors as json' do
60
- PuppetCheck.settings[:output_format] = 'json'
61
56
  PuppetCheck.settings[:error_files] = ['foo: i had an error']
62
- expect { OutputResults.markup }.to output("{\n \"errors\": [\n \"foo: i had an error\"\n ]\n}\n").to_stdout
57
+ expect { OutputResults.markup('json') }.to output("{\n \"errors\": [\n \"foo: i had an error\"\n ]\n}\n").to_stdout
63
58
  end
64
59
  it 'outputs files with warnings as json' do
65
- PuppetCheck.settings[:output_format] = 'json'
66
60
  PuppetCheck.settings[:warning_files] = ['foo: i had a warning']
67
- expect { OutputResults.markup }.to output("{\n \"warnings\": [\n \"foo: i had a warning\"\n ]\n}\n").to_stdout
61
+ expect { OutputResults.markup('json') }.to output("{\n \"warnings\": [\n \"foo: i had a warning\"\n ]\n}\n").to_stdout
68
62
  end
69
63
  it 'outputs files with no errors or warnings as json' do
70
- PuppetCheck.settings[:output_format] = 'json'
71
64
  PuppetCheck.settings[:clean_files] = ['foo: i was totally good to go']
72
- expect { OutputResults.markup }.to output("{\n \"clean\": [\n \"foo: i was totally good to go\"\n ]\n}\n").to_stdout
65
+ expect { OutputResults.markup('json') }.to output("{\n \"clean\": [\n \"foo: i was totally good to go\"\n ]\n}\n").to_stdout
73
66
  end
74
67
  it 'outputs files that were not processed as json' do
75
- PuppetCheck.settings[:output_format] = 'json'
76
68
  PuppetCheck.settings[:ignored_files] = ['foo: who knows what i am']
77
- expect { OutputResults.markup }.to output("{\n \"ignored\": [\n \"foo: who knows what i am\"\n ]\n}\n").to_stdout
69
+ expect { OutputResults.markup('json') }.to output("{\n \"ignored\": [\n \"foo: who knows what i am\"\n ]\n}\n").to_stdout
78
70
  end
79
71
  it 'raises an error for an unsupported output format' do
80
- PuppetCheck.settings[:output_format] = 'awesomesauce'
81
- expect { OutputResults.markup }.to raise_error(RuntimeError, 'puppet-check: Unsupported output format \'awesomesauce\' was specified.')
72
+ expect { OutputResults.markup('awesomesauce') }.to raise_error(RuntimeError, 'puppet-check: Unsupported output format \'awesomesauce\' was specified.')
82
73
  end
83
74
  end
84
75
  end
@@ -10,60 +10,62 @@ describe PuppetParser do
10
10
 
11
11
  context '.manifest' do
12
12
  it 'puts a bad syntax Puppet manifest in the error files array' do
13
- PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'], false, false, [])
14
- # dealing with annoying warning in puppet 5
15
- if RUBY_VERSION.to_f < 2.3
16
- expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nSupport for ruby version.*\n.*\nThis Variable has no effect.*\nIllegal variable name})
13
+ PuppetParser.manifest(["#{fixtures_dir}manifests/syntax.pp"], false, [])
14
+ if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0')
15
+ expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nLanguage validation logged 2 errors})
17
16
  else
18
17
  expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
19
18
  end
20
19
  expect(PuppetCheck.settings[:warning_files]).to eql([])
21
20
  expect(PuppetCheck.settings[:clean_files]).to eql([])
22
21
  end
23
- it 'puts a bad syntax at eof Puppet manifest in the error files array' do
24
- PuppetParser.manifest([fixtures_dir + 'manifests/eof_syntax.pp'], false, false, [])
25
- expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/eof_syntax.pp:\nSyntax error at end of input})
26
- expect(PuppetCheck.settings[:warning_files]).to eql([])
27
- expect(PuppetCheck.settings[:clean_files]).to eql([])
22
+ # puppet 5 api has output issues for this fixture
23
+ unless Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('6.0.0')
24
+ it 'puts a bad syntax at eof Puppet manifest in the error files array' do
25
+ PuppetParser.manifest(["#{fixtures_dir}manifests/eof_syntax.pp"], false, [])
26
+ expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/eof_syntax.pp:\nSyntax error at end of input})
27
+ expect(PuppetCheck.settings[:warning_files]).to eql([])
28
+ expect(PuppetCheck.settings[:clean_files]).to eql([])
29
+ end
28
30
  end
29
31
  it 'puts a bad parser and lint style Puppet manifest in the warning files array' do
30
- PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'], false, true, [])
32
+ PuppetParser.manifest(["#{fixtures_dir}manifests/style_parser.pp"], true, [])
31
33
  expect(PuppetCheck.settings[:error_files]).to eql([])
32
34
  expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_parser.pp:\nUnrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing})
33
35
  expect(PuppetCheck.settings[:clean_files]).to eql([])
34
36
  end
35
37
  it 'puts a bad lint style Puppet manifest in the warning files array' do
36
- PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, [])
38
+ PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, [])
37
39
  expect(PuppetCheck.settings[:error_files]).to eql([])
38
- expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*double quoted string containing.*\n.*indentation of})
40
+ expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*(?:indentation of|double quoted string containing).*\n.*(?:indentation of|double quoted string containing)})
39
41
  expect(PuppetCheck.settings[:clean_files]).to eql([])
40
42
  end
41
43
  it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
42
- PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
44
+ PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
43
45
  expect(PuppetCheck.settings[:error_files]).to eql([])
44
46
  expect(PuppetCheck.settings[:warning_files]).to eql([])
45
47
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
46
48
  end
47
49
  it 'puts a good Puppet manifest in the clean files array' do
48
- PuppetParser.manifest([fixtures_dir + 'manifests/good.pp'], false, true, [])
50
+ PuppetParser.manifest(["#{fixtures_dir}manifests/good.pp"], true, [])
49
51
  expect(PuppetCheck.settings[:error_files]).to eql([])
50
52
  expect(PuppetCheck.settings[:warning_files]).to eql([])
51
53
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}manifests/good.pp"])
52
54
  end
53
55
  it 'throws a well specified error for an invalid PuppetLint argument' do
54
- expect { PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, ['--non-existent', '--does-not-exist']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
56
+ expect { PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, ['--non-existent', '--does-not-exist']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
55
57
  end
56
58
  end
57
59
 
58
60
  context '.template' do
59
61
  it 'puts a bad syntax Puppet template in the error files array' do
60
- PuppetParser.template([fixtures_dir + 'templates/syntax.epp'])
62
+ PuppetParser.template(["#{fixtures_dir}templates/syntax.epp"])
61
63
  expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}templates/syntax.epp:\nThis Name has no effect})
62
64
  expect(PuppetCheck.settings[:warning_files]).to eql([])
63
65
  expect(PuppetCheck.settings[:clean_files]).to eql([])
64
66
  end
65
67
  it 'puts a good Puppet template in the clean files array' do
66
- PuppetParser.template([fixtures_dir + 'templates/good.epp'])
68
+ PuppetParser.template(["#{fixtures_dir}templates/good.epp"])
67
69
  expect(PuppetCheck.settings[:error_files]).to eql([])
68
70
  expect(PuppetCheck.settings[:warning_files]).to eql([])
69
71
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}templates/good.epp"])
@@ -5,13 +5,11 @@ require_relative '../../lib/puppet-check/regression_check'
5
5
  describe RegressionCheck do
6
6
  context '.config' do
7
7
  # json gem got messed up for the EOL Ruby versions
8
- if RUBY_VERSION.to_f >= 2.2
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
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!')
12
10
  end
13
11
  it 'loads in a good octocatalog-diff config file' do
14
- expect { RegressionCheck.config(octocatalog_diff_dir + 'octocatalog-diff.cfg.rb') }.not_to raise_exception
12
+ expect { RegressionCheck.config("#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
15
13
  end
16
14
  it 'loads in the settings from the file correctly' do
17
15
  end
@@ -19,16 +17,16 @@ describe RegressionCheck do
19
17
 
20
18
  context '.smoke' do
21
19
  # octocatalog-diff is returning a blank error for these tests
22
- unless File.directory?('/home/travis')
20
+ unless ENV['TRAVIS'] == 'true' || ENV['CIRCLECI'] == 'true'
23
21
  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
22
+ expect { RegressionCheck.smoke(['good.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
25
23
  end
26
24
  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)
25
+ expect { RegressionCheck.smoke(['does_not_exist.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.to raise_error(OctocatalogDiff::Errors::CatalogError)
28
26
  end
29
27
  end
30
28
  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")
29
+ # RegressionCheck.smoke(['good.example.com', 'syntax_error.example.com'], "#{fixtures_dir}octocatalog_diff.cfg.rb")
32
30
  end
33
31
  end
34
32
 
@@ -1,12 +1,12 @@
1
- require_relative '../spec_helper.rb'
1
+ require_relative '../spec_helper'
2
2
  require_relative '../../lib/puppet-check/rspec_puppet_support'
3
3
  require 'fileutils'
4
4
 
5
5
  describe RSpecPuppetSupport do
6
6
  after(:all) do
7
7
  # cleanup rspec_puppet_setup
8
- File.delete('spec/spec_helper.rb')
9
- %w[manifests modules].each { |dir| FileUtils.rm_r('spec/fixtures/' + dir) }
8
+ File.delete("#{fixtures_dir}/spec/spec_helper.rb")
9
+ %w[manifests modules].each { |dir| FileUtils.rm_r("#{fixtures_dir}/spec/fixtures/#{dir}") }
10
10
  end
11
11
 
12
12
  context '.run' do
@@ -14,7 +14,15 @@ 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
- expect { rspec_puppet_setup }.to output("puppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
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
+ # circle ci
21
+ elsif ENV['CIRCLECI'] == 'true'
22
+ 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
+ else
24
+ 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
25
+ end
18
26
 
19
27
  # .file_setup
20
28
  expect(File.directory?('spec/fixtures/manifests')).to be true
@@ -24,7 +32,7 @@ describe RSpecPuppetSupport do
24
32
  expect(File.file?('spec/spec_helper.rb')).to be true
25
33
 
26
34
  # .dependency_setup
27
- expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true
35
+ expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless ENV['CIRCLECI'] == 'true'
28
36
  expect(File.directory?('spec/fixtures/modules/stdlib')).to be true
29
37
  end
30
38
  end