puppet-check 1.4.0 → 1.4.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 +12 -11
- data/README.md +38 -26
- data/lib/puppet-check.rb +53 -39
- data/lib/puppet-check/cli.rb +12 -11
- data/lib/puppet-check/data_parser.rb +10 -10
- data/lib/puppet-check/output_results.rb +15 -15
- data/lib/puppet-check/puppet_parser.rb +6 -6
- data/lib/puppet-check/regression_check.rb +2 -2
- data/lib/puppet-check/rspec_puppet_support.rb +15 -7
- data/lib/puppet-check/ruby_parser.rb +9 -9
- data/lib/puppet-check/tasks.rb +27 -18
- data/spec/fixtures/metadata.json +5 -0
- data/spec/octocatalog-diff/hiera.yaml +1 -2
- data/spec/octocatalog-diff/octocatalog-diff.cfg.rb +5 -1
- data/spec/puppet-check/cli_spec.rb +40 -38
- data/spec/puppet-check/data_parser_spec.rb +30 -30
- data/spec/puppet-check/output_results_spec.rb +29 -29
- data/spec/puppet-check/puppet_parser_spec.rb +25 -25
- data/spec/puppet-check/regression_check_spec.rb +9 -6
- data/spec/puppet-check/rspec_puppet_support_spec.rb +2 -2
- data/spec/puppet-check/ruby_parser_spec.rb +39 -39
- data/spec/puppet-check/tasks_spec.rb +2 -2
- data/spec/puppet-check_spec.rb +33 -21
- data/spec/system/system_spec.rb +20 -20
- metadata +2 -2
@@ -4,80 +4,80 @@ require_relative '../../lib/puppet-check/output_results'
|
|
4
4
|
describe OutputResults do
|
5
5
|
context '.text' do
|
6
6
|
before(:each) do
|
7
|
-
PuppetCheck.error_files = []
|
8
|
-
PuppetCheck.warning_files = []
|
9
|
-
PuppetCheck.clean_files = []
|
10
|
-
PuppetCheck.ignored_files = []
|
7
|
+
PuppetCheck.settings[:error_files] = []
|
8
|
+
PuppetCheck.settings[:warning_files] = []
|
9
|
+
PuppetCheck.settings[:clean_files] = []
|
10
|
+
PuppetCheck.settings[:ignored_files] = []
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'outputs files with errors' do
|
14
|
-
PuppetCheck.error_files = ['foo: i had an error']
|
14
|
+
PuppetCheck.settings[:error_files] = ['foo: i had an error']
|
15
15
|
expect { OutputResults.text }.to output("\033[31mThe following files have errors:\033[0m\n-- foo: i had an error\n").to_stdout
|
16
16
|
end
|
17
17
|
it 'outputs files with warnings' do
|
18
|
-
PuppetCheck.warning_files = ['foo: i had a warning']
|
18
|
+
PuppetCheck.settings[:warning_files] = ['foo: i had a warning']
|
19
19
|
expect { OutputResults.text }.to output("\n\033[33mThe following files have warnings:\033[0m\n-- foo: i had a warning\n").to_stdout
|
20
20
|
end
|
21
21
|
it 'outputs files with no errors or warnings' do
|
22
|
-
PuppetCheck.clean_files = ['foo: i was totally good to go']
|
22
|
+
PuppetCheck.settings[:clean_files] = ['foo: i was totally good to go']
|
23
23
|
expect { OutputResults.text }.to output("\n\033[32mThe following files have no errors or warnings:\033[0m\n-- foo: i was totally good to go\n").to_stdout
|
24
24
|
end
|
25
25
|
it 'outputs files that were not processed' do
|
26
|
-
PuppetCheck.ignored_files = ['foo: who knows what i am']
|
26
|
+
PuppetCheck.settings[:ignored_files] = ['foo: who knows what i am']
|
27
27
|
expect { OutputResults.text }.to output("\n\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- foo: who knows what i am\n").to_stdout
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
context '.markup' do
|
32
32
|
before(:each) do
|
33
|
-
PuppetCheck.error_files = []
|
34
|
-
PuppetCheck.warning_files = []
|
35
|
-
PuppetCheck.clean_files = []
|
36
|
-
PuppetCheck.ignored_files = []
|
33
|
+
PuppetCheck.settings[:error_files] = []
|
34
|
+
PuppetCheck.settings[:warning_files] = []
|
35
|
+
PuppetCheck.settings[:clean_files] = []
|
36
|
+
PuppetCheck.settings[:ignored_files] = []
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'outputs files with errors as yaml' do
|
40
|
-
PuppetCheck.output_format = 'yaml'
|
41
|
-
PuppetCheck.error_files = ['foo: i had an error']
|
40
|
+
PuppetCheck.settings[:output_format] = 'yaml'
|
41
|
+
PuppetCheck.settings[:error_files] = ['foo: i had an error']
|
42
42
|
expect { OutputResults.markup }.to output("---\nerrors:\n- 'foo: i had an error'\n").to_stdout
|
43
43
|
end
|
44
44
|
it 'outputs files with warnings as yaml' do
|
45
|
-
PuppetCheck.output_format = 'yaml'
|
46
|
-
PuppetCheck.warning_files = ['foo: i had a warning']
|
45
|
+
PuppetCheck.settings[:output_format] = 'yaml'
|
46
|
+
PuppetCheck.settings[:warning_files] = ['foo: i had a warning']
|
47
47
|
expect { OutputResults.markup }.to output("---\nwarnings:\n- 'foo: i had a warning'\n").to_stdout
|
48
48
|
end
|
49
49
|
it 'outputs files with no errors or warnings as yaml' do
|
50
|
-
PuppetCheck.output_format = 'yaml'
|
51
|
-
PuppetCheck.clean_files = ['foo: i was totally good to go']
|
50
|
+
PuppetCheck.settings[:output_format] = 'yaml'
|
51
|
+
PuppetCheck.settings[:clean_files] = ['foo: i was totally good to go']
|
52
52
|
expect { OutputResults.markup }.to output("---\nclean:\n- 'foo: i was totally good to go'\n").to_stdout
|
53
53
|
end
|
54
54
|
it 'outputs files that were not processed as yaml' do
|
55
|
-
PuppetCheck.output_format = 'yaml'
|
56
|
-
PuppetCheck.ignored_files = ['foo: who knows what i am']
|
55
|
+
PuppetCheck.settings[:output_format] = 'yaml'
|
56
|
+
PuppetCheck.settings[:ignored_files] = ['foo: who knows what i am']
|
57
57
|
expect { OutputResults.markup }.to output("---\nignored:\n- 'foo: who knows what i am'\n").to_stdout
|
58
58
|
end
|
59
59
|
it 'outputs files with errors as json' do
|
60
|
-
PuppetCheck.output_format = 'json'
|
61
|
-
PuppetCheck.error_files = ['foo: i had an error']
|
60
|
+
PuppetCheck.settings[:output_format] = 'json'
|
61
|
+
PuppetCheck.settings[:error_files] = ['foo: i had an error']
|
62
62
|
expect { OutputResults.markup }.to output("{\n \"errors\": [\n \"foo: i had an error\"\n ]\n}\n").to_stdout
|
63
63
|
end
|
64
64
|
it 'outputs files with warnings as json' do
|
65
|
-
PuppetCheck.output_format = 'json'
|
66
|
-
PuppetCheck.warning_files = ['foo: i had a warning']
|
65
|
+
PuppetCheck.settings[:output_format] = 'json'
|
66
|
+
PuppetCheck.settings[:warning_files] = ['foo: i had a warning']
|
67
67
|
expect { OutputResults.markup }.to output("{\n \"warnings\": [\n \"foo: i had a warning\"\n ]\n}\n").to_stdout
|
68
68
|
end
|
69
69
|
it 'outputs files with no errors or warnings as json' do
|
70
|
-
PuppetCheck.output_format = 'json'
|
71
|
-
PuppetCheck.clean_files = ['foo: i was totally good to go']
|
70
|
+
PuppetCheck.settings[:output_format] = 'json'
|
71
|
+
PuppetCheck.settings[:clean_files] = ['foo: i was totally good to go']
|
72
72
|
expect { OutputResults.markup }.to output("{\n \"clean\": [\n \"foo: i was totally good to go\"\n ]\n}\n").to_stdout
|
73
73
|
end
|
74
74
|
it 'outputs files that were not processed as json' do
|
75
|
-
PuppetCheck.output_format = 'json'
|
76
|
-
PuppetCheck.ignored_files = ['foo: who knows what i am']
|
75
|
+
PuppetCheck.settings[:output_format] = 'json'
|
76
|
+
PuppetCheck.settings[:ignored_files] = ['foo: who knows what i am']
|
77
77
|
expect { OutputResults.markup }.to output("{\n \"ignored\": [\n \"foo: who knows what i am\"\n ]\n}\n").to_stdout
|
78
78
|
end
|
79
79
|
it 'raises an error for an unsupported output format' do
|
80
|
-
PuppetCheck.output_format = 'awesomesauce'
|
80
|
+
PuppetCheck.settings[:output_format] = 'awesomesauce'
|
81
81
|
expect { OutputResults.markup }.to raise_error(RuntimeError, 'puppet-check: Unsupported output format \'awesomesauce\' was specified.')
|
82
82
|
end
|
83
83
|
end
|
@@ -3,9 +3,9 @@ require_relative '../../lib/puppet-check/puppet_parser'
|
|
3
3
|
|
4
4
|
describe PuppetParser do
|
5
5
|
before(:each) do
|
6
|
-
PuppetCheck.error_files = []
|
7
|
-
PuppetCheck.warning_files = []
|
8
|
-
PuppetCheck.clean_files = []
|
6
|
+
PuppetCheck.settings[:error_files] = []
|
7
|
+
PuppetCheck.settings[:warning_files] = []
|
8
|
+
PuppetCheck.settings[:clean_files] = []
|
9
9
|
end
|
10
10
|
|
11
11
|
context '.manifest' do
|
@@ -13,36 +13,36 @@ describe PuppetParser do
|
|
13
13
|
PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'], false, false, [])
|
14
14
|
# stupid Puppet deprecation warning
|
15
15
|
if RUBY_VERSION.to_f < 2.1
|
16
|
-
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nSupport for ruby version.*\n.*\nThis Variable has no effect.*\nIllegal variable name})
|
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})
|
17
17
|
else
|
18
|
-
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
|
18
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
|
19
19
|
end
|
20
|
-
expect(PuppetCheck.warning_files).to eql([])
|
21
|
-
expect(PuppetCheck.clean_files).to eql([])
|
20
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
21
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
22
22
|
end
|
23
23
|
it 'puts a bad parser and lint style Puppet manifest in the warning files array' do
|
24
24
|
PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'], false, true, [])
|
25
|
-
expect(PuppetCheck.error_files).to eql([])
|
26
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}manifests/style_parser.pp:\nUnrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing})
|
27
|
-
expect(PuppetCheck.clean_files).to eql([])
|
25
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
26
|
+
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})
|
27
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
28
28
|
end
|
29
29
|
it 'puts a bad lint style Puppet manifest in the warning files array' do
|
30
30
|
PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, [])
|
31
|
-
expect(PuppetCheck.error_files).to eql([])
|
32
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*double quoted string containing.*\n.*indentation of})
|
33
|
-
expect(PuppetCheck.clean_files).to eql([])
|
31
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
32
|
+
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*double quoted string containing.*\n.*indentation of})
|
33
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
34
34
|
end
|
35
35
|
it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
|
36
36
|
PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
|
37
|
-
expect(PuppetCheck.error_files).to eql([])
|
38
|
-
expect(PuppetCheck.warning_files).to eql([])
|
39
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
|
37
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
38
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
39
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
|
40
40
|
end
|
41
41
|
it 'puts a good Puppet manifest in the clean files array' do
|
42
42
|
PuppetParser.manifest([fixtures_dir + 'manifests/good.pp'], false, true, [])
|
43
|
-
expect(PuppetCheck.error_files).to eql([])
|
44
|
-
expect(PuppetCheck.warning_files).to eql([])
|
45
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}manifests/good.pp"])
|
43
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
44
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
45
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}manifests/good.pp"])
|
46
46
|
end
|
47
47
|
it 'throws a well specified error for an invalid PuppetLint argument' do
|
48
48
|
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')
|
@@ -52,15 +52,15 @@ describe PuppetParser do
|
|
52
52
|
context '.template' do
|
53
53
|
it 'puts a bad syntax Puppet template in the error files array' do
|
54
54
|
PuppetParser.template([fixtures_dir + 'templates/syntax.epp'])
|
55
|
-
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}templates/syntax.epp:\nThis Name has no effect})
|
56
|
-
expect(PuppetCheck.warning_files).to eql([])
|
57
|
-
expect(PuppetCheck.clean_files).to eql([])
|
55
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}templates/syntax.epp:\nThis Name has no effect})
|
56
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
57
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
58
58
|
end
|
59
59
|
it 'puts a good Puppet template in the clean files array' do
|
60
60
|
PuppetParser.template([fixtures_dir + 'templates/good.epp'])
|
61
|
-
expect(PuppetCheck.error_files).to eql([])
|
62
|
-
expect(PuppetCheck.warning_files).to eql([])
|
63
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}templates/good.epp"])
|
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}templates/good.epp"])
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -4,8 +4,11 @@ require_relative '../../lib/puppet-check/regression_check'
|
|
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
5
|
describe RegressionCheck do
|
6
6
|
context '.config' do
|
7
|
-
|
8
|
-
|
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
|
9
12
|
end
|
10
13
|
it 'loads in a good octocatalog-diff config file' do
|
11
14
|
expect { RegressionCheck.config(octocatalog_diff_dir + 'octocatalog-diff.cfg.rb') }.not_to raise_exception
|
@@ -16,14 +19,14 @@ describe RegressionCheck do
|
|
16
19
|
end
|
17
20
|
|
18
21
|
context '.smoke' do
|
19
|
-
#
|
22
|
+
# octocatalog-diff is returning a blank error for these tests
|
20
23
|
unless File.directory?('/home/travis')
|
21
24
|
it 'returns a pass for a successful catalog compilation' do
|
22
25
|
expect { RegressionCheck.smoke(['good.example.com'], "#{octocatalog_diff_dir}octocatalog-diff.cfg.rb") }.not_to raise_exception
|
23
26
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
it 'returns a failure for a catalog with an error' do
|
28
|
+
expect { RegressionCheck.smoke(['does_not_exist.example.com'], "#{octocatalog_diff_dir}octocatalog-diff.cfg.rb") }.to raise_error(OctocatalogDiff::Errors::CatalogError)
|
29
|
+
end
|
27
30
|
end
|
28
31
|
it 'returns a failure for a good and bad catalog' do
|
29
32
|
# RegressionCheck.smoke(['good.example.com', 'syntax_error.example.com'], "#{fixtures_dir}octocatalog-diff.cfg.rb")
|
@@ -25,8 +25,8 @@ describe RSpecPuppetSupport do
|
|
25
25
|
expect(File.directory?('spec/fixtures/modules/stdlib')).to be true
|
26
26
|
|
27
27
|
# cleanup rspec_puppet_setup
|
28
|
-
%w
|
29
|
-
%w
|
28
|
+
%w[spec/spec_helper.rb].each { |file| File.delete(file) }
|
29
|
+
%w[manifests modules].each { |dir| FileUtils.rm_r('spec/fixtures/' + dir) }
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -3,89 +3,89 @@ require_relative '../../lib/puppet-check/ruby_parser'
|
|
3
3
|
|
4
4
|
describe RubyParser do
|
5
5
|
before(:each) do
|
6
|
-
PuppetCheck.error_files = []
|
7
|
-
PuppetCheck.warning_files = []
|
8
|
-
PuppetCheck.clean_files = []
|
6
|
+
PuppetCheck.settings[:error_files] = []
|
7
|
+
PuppetCheck.settings[:warning_files] = []
|
8
|
+
PuppetCheck.settings[:clean_files] = []
|
9
9
|
end
|
10
10
|
|
11
11
|
context '.ruby' do
|
12
12
|
it 'puts a bad syntax ruby file in the error files array' do
|
13
13
|
RubyParser.ruby([fixtures_dir + 'lib/syntax.rb'], false, [])
|
14
|
-
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}lib/syntax.rb:\n.*syntax error})
|
15
|
-
expect(PuppetCheck.warning_files).to eql([])
|
16
|
-
expect(PuppetCheck.clean_files).to eql([])
|
14
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}lib/syntax.rb:\n.*syntax error})
|
15
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
16
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
17
17
|
end
|
18
18
|
it 'puts a bad style ruby file in the warning files array' do
|
19
19
|
RubyParser.ruby([fixtures_dir + 'lib/style.rb'], true, [])
|
20
|
-
expect(PuppetCheck.error_files).to eql([])
|
21
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment})
|
22
|
-
expect(PuppetCheck.clean_files).to eql([])
|
20
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
21
|
+
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment})
|
22
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
23
23
|
end
|
24
24
|
it 'puts a bad style ruby file in the clean files array when rubocop_args ignores its warnings' do
|
25
25
|
RubyParser.ruby([fixtures_dir + 'lib/rubocop_style.rb'], true, ['--except', 'Lint/UselessAssignment,Style/HashSyntax,Style/GlobalVars,Style/StringLiterals'])
|
26
|
-
expect(PuppetCheck.error_files).to eql([])
|
27
|
-
expect(PuppetCheck.warning_files).to eql([])
|
28
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}lib/rubocop_style.rb"])
|
26
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
27
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
28
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}lib/rubocop_style.rb"])
|
29
29
|
end
|
30
30
|
it 'puts a good ruby file in the clean files array' do
|
31
31
|
RubyParser.ruby([fixtures_dir + 'lib/good.rb'], true, [])
|
32
|
-
expect(PuppetCheck.error_files).to eql([])
|
33
|
-
expect(PuppetCheck.warning_files).to eql([])
|
34
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}lib/good.rb"])
|
32
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
33
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
34
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}lib/good.rb"])
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context '.template' do
|
39
39
|
it 'puts a bad syntax ruby template file in the error files array' do
|
40
40
|
RubyParser.template([fixtures_dir + 'templates/syntax.erb'])
|
41
|
-
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}templates/syntax.erb:\n.*syntax error, unexpected tIDENTIFIER})
|
42
|
-
expect(PuppetCheck.warning_files).to eql([])
|
43
|
-
expect(PuppetCheck.clean_files).to eql([])
|
41
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}templates/syntax.erb:\n.*syntax error, unexpected tIDENTIFIER})
|
42
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
43
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
44
44
|
end
|
45
45
|
it 'puts a bad style ruby template file in the warning files array' do
|
46
46
|
RubyParser.template([fixtures_dir + 'templates/style.erb'])
|
47
|
-
expect(PuppetCheck.error_files).to eql([])
|
48
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}templates/style.erb:\n.*already initialized constant.*\n.*previous definition of})
|
49
|
-
expect(PuppetCheck.clean_files).to eql([])
|
47
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
48
|
+
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}templates/style.erb:\n.*already initialized constant.*\n.*previous definition of})
|
49
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
50
50
|
end
|
51
51
|
it 'puts a ruby template file with ignored errors in the clean files array' do
|
52
52
|
RubyParser.template([fixtures_dir + 'templates/no_method_error.erb'])
|
53
|
-
expect(PuppetCheck.error_files).to eql([])
|
54
|
-
expect(PuppetCheck.warning_files).to eql([])
|
55
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}templates/no_method_error.erb"])
|
53
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
54
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
55
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}templates/no_method_error.erb"])
|
56
56
|
end
|
57
57
|
it 'puts a good ruby template file in the clean files array' do
|
58
58
|
RubyParser.template([fixtures_dir + 'templates/good.erb'])
|
59
|
-
expect(PuppetCheck.error_files).to eql([])
|
60
|
-
expect(PuppetCheck.warning_files).to eql([])
|
61
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}templates/good.erb"])
|
59
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
60
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
61
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}templates/good.erb"])
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
context '.librarian' do
|
66
66
|
it 'puts a bad syntax librarian Puppet file in the error files array' do
|
67
67
|
RubyParser.librarian([fixtures_dir + 'librarian_syntax/Puppetfile'], false, [])
|
68
|
-
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}librarian_syntax/Puppetfile:\n.*syntax error})
|
69
|
-
expect(PuppetCheck.warning_files).to eql([])
|
70
|
-
expect(PuppetCheck.clean_files).to eql([])
|
68
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}librarian_syntax/Puppetfile:\n.*syntax error})
|
69
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
70
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
71
71
|
end
|
72
72
|
it 'puts a bad style librarian Puppet file in the warning files array' do
|
73
73
|
RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'], true, [])
|
74
|
-
expect(PuppetCheck.error_files).to eql([])
|
75
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}librarian_style/Puppetfile:\n.*Align the parameters.*\n.*Use the new})
|
76
|
-
expect(PuppetCheck.clean_files).to eql([])
|
74
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
75
|
+
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}librarian_style/Puppetfile:\n.*Align the parameters.*\n.*Use the new})
|
76
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
77
77
|
end
|
78
78
|
it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
|
79
79
|
RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'], true, ['--except', 'Style/AlignParameters,Style/HashSyntax'])
|
80
|
-
expect(PuppetCheck.error_files).to eql([])
|
81
|
-
expect(PuppetCheck.warning_files).to eql([])
|
82
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}librarian_style/Puppetfile"])
|
80
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
81
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
82
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}librarian_style/Puppetfile"])
|
83
83
|
end
|
84
84
|
it 'puts a good librarian Puppet file in the clean files array' do
|
85
85
|
RubyParser.librarian([fixtures_dir + 'librarian_good/Puppetfile'], true, [])
|
86
|
-
expect(PuppetCheck.error_files).to eql([])
|
87
|
-
expect(PuppetCheck.warning_files).to eql([])
|
88
|
-
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}librarian_good/Puppetfile"])
|
86
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
87
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
88
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}librarian_good/Puppetfile"])
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -15,8 +15,8 @@ describe PuppetCheck::Tasks do
|
|
15
15
|
expect { spec_tasks }.not_to raise_exception
|
16
16
|
|
17
17
|
# cleanup rspec_puppet_setup
|
18
|
-
%w
|
19
|
-
%w
|
18
|
+
%w[spec/spec_helper.rb].each { |file| File.delete(file) }
|
19
|
+
%w[manifests modules].each { |dir| FileUtils.rm_r('spec/fixtures/' + dir) }
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/spec/puppet-check_spec.rb
CHANGED
@@ -4,34 +4,36 @@ require_relative '../lib/puppet-check'
|
|
4
4
|
describe PuppetCheck do
|
5
5
|
context 'self' do
|
6
6
|
it 'settings can be altered' do
|
7
|
-
PuppetCheck.future_parser = true
|
8
|
-
expect(PuppetCheck.future_parser).to eql(true)
|
9
|
-
PuppetCheck.
|
10
|
-
expect(PuppetCheck.
|
11
|
-
PuppetCheck.
|
12
|
-
expect(PuppetCheck.
|
13
|
-
PuppetCheck.
|
14
|
-
expect(PuppetCheck.
|
15
|
-
PuppetCheck.
|
16
|
-
expect(PuppetCheck.
|
17
|
-
PuppetCheck.
|
18
|
-
expect(PuppetCheck.
|
19
|
-
PuppetCheck.
|
20
|
-
expect(PuppetCheck.
|
21
|
-
PuppetCheck.
|
22
|
-
expect(PuppetCheck.
|
23
|
-
PuppetCheck.
|
24
|
-
expect(PuppetCheck.
|
7
|
+
PuppetCheck.settings[:future_parser] = true
|
8
|
+
expect(PuppetCheck.settings[:future_parser]).to eql(true)
|
9
|
+
PuppetCheck.settings[:fail_on_warnings] = true
|
10
|
+
expect(PuppetCheck.settings[:fail_on_warnings]).to eql(true)
|
11
|
+
PuppetCheck.settings[:style_check] = true
|
12
|
+
expect(PuppetCheck.settings[:style_check]).to eql(true)
|
13
|
+
PuppetCheck.settings[:smoke_check] = true
|
14
|
+
expect(PuppetCheck.settings[:smoke_check]).to eql(true)
|
15
|
+
PuppetCheck.settings[:regression_check] = true
|
16
|
+
expect(PuppetCheck.settings[:regression_check]).to eql(true)
|
17
|
+
PuppetCheck.settings[:output_format] = 'text'
|
18
|
+
expect(PuppetCheck.settings[:output_format]).to eql('text')
|
19
|
+
PuppetCheck.settings[:octoconfig] = '.octocatalog-diff.cfg.rb'
|
20
|
+
expect(PuppetCheck.settings[:octoconfig]).to eql('.octocatalog-diff.cfg.rb')
|
21
|
+
PuppetCheck.settings[:octonodes] = %w[localhost.localdomain]
|
22
|
+
expect(PuppetCheck.settings[:octonodes]).to eql(%w[localhost.localdomain])
|
23
|
+
PuppetCheck.settings[:puppetlint_args] = ['--puppetlint-arg-one', '--puppetlint-arg-two']
|
24
|
+
expect(PuppetCheck.settings[:puppetlint_args]).to eql(['--puppetlint-arg-one', '--puppetlint-arg-two'])
|
25
|
+
PuppetCheck.settings[:rubocop_args] = ['--rubocop-arg-one', '--rubocop-arg-two']
|
26
|
+
expect(PuppetCheck.settings[:rubocop_args]).to eql(['--rubocop-arg-one', '--rubocop-arg-two'])
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
context '.parse_paths' do
|
29
31
|
before(:each) { Dir.chdir(fixtures_dir) }
|
30
32
|
|
31
|
-
let(:no_files) { PuppetCheck.parse_paths(%w
|
33
|
+
let(:no_files) { PuppetCheck.parse_paths(%w[foo bar baz]) }
|
32
34
|
let(:file) { PuppetCheck.parse_paths(['lib/good.rb']) }
|
33
35
|
let(:dir) { PuppetCheck.parse_paths(['.']) }
|
34
|
-
let(:multi_dir) { PuppetCheck.parse_paths(%w
|
36
|
+
let(:multi_dir) { PuppetCheck.parse_paths(%w[hieradata lib manifests]) }
|
35
37
|
let(:repeats) { PuppetCheck.parse_paths(['hieradata', 'hieradata', 'lib', 'hieradata/good.json', 'manifests/good.pp', 'manifests/good.pp']) }
|
36
38
|
|
37
39
|
it 'raises an error if no files were found' do
|
@@ -59,6 +61,16 @@ describe PuppetCheck do
|
|
59
61
|
end
|
60
62
|
|
61
63
|
context '.execute_parsers' do
|
62
|
-
|
64
|
+
it 'correctly organizes a set of files and invokes the correct parsers' do
|
65
|
+
# parser_output = instance_double('execute_parsers', files: %w[puppet.pp puppet_template.epp ruby.rb ruby_template.erb yaml.yaml yaml.yml json.json Puppetfile Modulefile foobarbaz], future: false, style: false, pl_args: [], rc_args: [])
|
66
|
+
# expect(parser_output).to receive(:manifest).with(%w[puppet.pp])
|
67
|
+
# expect(parser_output).to receive(:template).with(%w[puppet_template.epp])
|
68
|
+
# expect(parser_output).to receive(:ruby).with(%w[ruby.rb])
|
69
|
+
# expect(parser_output).to receive(:template).with(%w[ruby_template.erb])
|
70
|
+
# expect(parser_output).to receive(:yaml).with(%w[yaml.yaml yaml.yml])
|
71
|
+
# expect(parser_output).to receive(:json).with(%w[json.json])
|
72
|
+
# expect(parser_output).to receive(:librarian).with(%w[Puppetfile Modulefile])
|
73
|
+
# expect(PuppetCheck.settings[:ignored_files]).to eql(%w[foobarbaz])
|
74
|
+
end
|
63
75
|
end
|
64
76
|
end
|