puppet-check 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +12 -29
- data/lib/puppet-check/cli.rb +2 -2
- data/lib/puppet-check/data_parser.rb +19 -21
- data/lib/puppet-check/output_results.rb +6 -5
- data/lib/puppet-check/puppet_parser.rb +18 -26
- data/lib/puppet-check/rspec_puppet_support.rb +18 -6
- data/lib/puppet-check/ruby_parser.rb +37 -41
- data/lib/puppet-check/tasks.rb +1 -1
- data/lib/{puppet-check.rb → puppet_check.rb} +1 -1
- data/spec/fixtures/plans/good.pp +3 -0
- data/spec/fixtures/plans/style.pp +6 -0
- data/spec/fixtures/plans/syntax.pp +5 -0
- data/spec/octocatalog-diff/{octocatalog-diff.cfg.rb → octocatalog_diff.cfg.rb} +6 -6
- data/spec/puppet-check/data_parser_spec.rb +41 -43
- data/spec/puppet-check/output_results_spec.rb +9 -9
- data/spec/puppet-check/puppet_parser_spec.rb +34 -16
- data/spec/puppet-check/regression_check_spec.rb +7 -9
- data/spec/puppet-check/rspec_puppet_support_spec.rb +13 -5
- data/spec/puppet-check/ruby_parser_spec.rb +18 -14
- data/spec/puppet-check/tasks_spec.rb +3 -3
- data/spec/{puppet-check_spec.rb → puppet_check_spec.rb} +1 -1
- data/spec/spec_helper.rb +7 -2
- data/spec/system/system_spec.rb +15 -13
- metadata +31 -32
@@ -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
|
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
|
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
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
32
|
+
context '.eyaml' do
|
33
|
+
before(:each) do
|
34
|
+
PuppetCheck.settings[:ignored_files] = []
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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"])
|
@@ -38,38 +38,38 @@ describe OutputResults do
|
|
38
38
|
|
39
39
|
it 'outputs files with errors as yaml' do
|
40
40
|
PuppetCheck.settings[:error_files] = ['foo: i had an error']
|
41
|
-
expect { OutputResults.markup(
|
41
|
+
expect { OutputResults.markup('yaml') }.to output("---\nerrors:\n- 'foo: i had an error'\n").to_stdout
|
42
42
|
end
|
43
43
|
it 'outputs files with warnings as yaml' do
|
44
44
|
PuppetCheck.settings[:warning_files] = ['foo: i had a warning']
|
45
|
-
expect { OutputResults.markup(
|
45
|
+
expect { OutputResults.markup('yaml') }.to output("---\nwarnings:\n- 'foo: i had a warning'\n").to_stdout
|
46
46
|
end
|
47
47
|
it 'outputs files with no errors or warnings as yaml' do
|
48
48
|
PuppetCheck.settings[:clean_files] = ['foo: i was totally good to go']
|
49
|
-
expect { OutputResults.markup(
|
49
|
+
expect { OutputResults.markup('yaml') }.to output("---\nclean:\n- 'foo: i was totally good to go'\n").to_stdout
|
50
50
|
end
|
51
51
|
it 'outputs files that were not processed as yaml' do
|
52
52
|
PuppetCheck.settings[:ignored_files] = ['foo: who knows what i am']
|
53
|
-
expect { OutputResults.markup(
|
53
|
+
expect { OutputResults.markup('yaml') }.to output("---\nignored:\n- 'foo: who knows what i am'\n").to_stdout
|
54
54
|
end
|
55
55
|
it 'outputs files with errors as json' do
|
56
56
|
PuppetCheck.settings[:error_files] = ['foo: i had an error']
|
57
|
-
expect { OutputResults.markup(
|
57
|
+
expect { OutputResults.markup('json') }.to output("{\n \"errors\": [\n \"foo: i had an error\"\n ]\n}\n").to_stdout
|
58
58
|
end
|
59
59
|
it 'outputs files with warnings as json' do
|
60
60
|
PuppetCheck.settings[:warning_files] = ['foo: i had a warning']
|
61
|
-
expect { OutputResults.markup(
|
61
|
+
expect { OutputResults.markup('json') }.to output("{\n \"warnings\": [\n \"foo: i had a warning\"\n ]\n}\n").to_stdout
|
62
62
|
end
|
63
63
|
it 'outputs files with no errors or warnings as json' do
|
64
64
|
PuppetCheck.settings[:clean_files] = ['foo: i was totally good to go']
|
65
|
-
expect { OutputResults.markup(
|
65
|
+
expect { OutputResults.markup('json') }.to output("{\n \"clean\": [\n \"foo: i was totally good to go\"\n ]\n}\n").to_stdout
|
66
66
|
end
|
67
67
|
it 'outputs files that were not processed as json' do
|
68
68
|
PuppetCheck.settings[:ignored_files] = ['foo: who knows what i am']
|
69
|
-
expect { OutputResults.markup(
|
69
|
+
expect { OutputResults.markup('json') }.to output("{\n \"ignored\": [\n \"foo: who knows what i am\"\n ]\n}\n").to_stdout
|
70
70
|
end
|
71
71
|
it 'raises an error for an unsupported output format' do
|
72
|
-
expect { OutputResults.markup(
|
72
|
+
expect { OutputResults.markup('awesomesauce') }.to raise_error(RuntimeError, 'puppet-check: Unsupported output format \'awesomesauce\' was specified.')
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -10,62 +10,80 @@ 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
|
14
|
-
if Puppet::PUPPETVERSION
|
13
|
+
PuppetParser.manifest(["#{fixtures_dir}manifests/syntax.pp"], false, [])
|
14
|
+
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0')
|
15
15
|
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nLanguage validation logged 2 errors})
|
16
|
-
# dealing with annoying warning in puppet 5 and 6
|
17
|
-
elsif RUBY_VERSION.to_f < 2.3
|
18
|
-
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})
|
19
16
|
else
|
20
17
|
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
|
21
18
|
end
|
22
19
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
23
20
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
24
21
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
30
|
+
end
|
31
|
+
it 'puts a bad syntax Puppet plan in the error files array' do
|
32
|
+
PuppetParser.manifest(["#{fixtures_dir}plans/syntax.pp"], false, [])
|
33
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}plans/syntax.pp:\nSyntax error at '\)'})
|
28
34
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
29
35
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
30
36
|
end
|
31
37
|
it 'puts a bad parser and lint style Puppet manifest in the warning files array' do
|
32
|
-
PuppetParser.manifest([fixtures_dir
|
38
|
+
PuppetParser.manifest(["#{fixtures_dir}manifests/style_parser.pp"], true, [])
|
33
39
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
34
40
|
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})
|
35
41
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
36
42
|
end
|
37
43
|
it 'puts a bad lint style Puppet manifest in the warning files array' do
|
38
|
-
PuppetParser.manifest([fixtures_dir
|
44
|
+
PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, [])
|
39
45
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
40
|
-
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*double quoted string containing.*\n.*indentation of})
|
46
|
+
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)})
|
41
47
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
42
48
|
end
|
43
49
|
it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
|
44
|
-
PuppetParser.manifest([fixtures_dir
|
50
|
+
PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
|
45
51
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
46
52
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
47
53
|
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
|
48
54
|
end
|
55
|
+
it 'puts a bad style Puppet plan in the warning files array' do
|
56
|
+
PuppetParser.manifest(["#{fixtures_dir}plans/style.pp"], true, [])
|
57
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
58
|
+
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}plans/style.pp:\n.*variable not enclosed in {}})
|
59
|
+
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
60
|
+
end
|
49
61
|
it 'puts a good Puppet manifest in the clean files array' do
|
50
|
-
PuppetParser.manifest([fixtures_dir
|
62
|
+
PuppetParser.manifest(["#{fixtures_dir}manifests/good.pp"], true, [])
|
51
63
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
52
64
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
53
65
|
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}manifests/good.pp"])
|
54
66
|
end
|
67
|
+
it 'puts a good Puppet plan in the clean files array' do
|
68
|
+
PuppetParser.manifest(["#{fixtures_dir}plans/good.pp"], true, [])
|
69
|
+
expect(PuppetCheck.settings[:error_files]).to eql([])
|
70
|
+
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
71
|
+
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}plans/good.pp"])
|
72
|
+
end
|
55
73
|
it 'throws a well specified error for an invalid PuppetLint argument' do
|
56
|
-
expect { PuppetParser.manifest([fixtures_dir
|
74
|
+
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')
|
57
75
|
end
|
58
76
|
end
|
59
77
|
|
60
78
|
context '.template' do
|
61
79
|
it 'puts a bad syntax Puppet template in the error files array' do
|
62
|
-
PuppetParser.template([fixtures_dir
|
80
|
+
PuppetParser.template(["#{fixtures_dir}templates/syntax.epp"])
|
63
81
|
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}templates/syntax.epp:\nThis Name has no effect})
|
64
82
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
65
83
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
66
84
|
end
|
67
85
|
it 'puts a good Puppet template in the clean files array' do
|
68
|
-
PuppetParser.template([fixtures_dir
|
86
|
+
PuppetParser.template(["#{fixtures_dir}templates/good.epp"])
|
69
87
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
70
88
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
71
89
|
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
|
9
|
-
|
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
|
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
|
20
|
+
unless ENV['TRAVIS'] == 'true' || ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
23
21
|
it 'returns a pass for a successful catalog compilation' do
|
24
|
-
expect { RegressionCheck.smoke(['good.example.com'], "#{octocatalog_diff_dir}
|
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}
|
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}
|
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
|
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(
|
9
|
-
%w[manifests modules].each { |dir| FileUtils.rm_r(
|
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
|
-
|
17
|
+
# travis ci
|
18
|
+
if ENV['TRAVIS'] == 'true' || ENV['GITHUB_ACTIONS'] == '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
|
@@ -10,25 +10,25 @@ describe RubyParser do
|
|
10
10
|
|
11
11
|
context '.ruby' do
|
12
12
|
it 'puts a bad syntax ruby file in the error files array' do
|
13
|
-
RubyParser.ruby([fixtures_dir
|
13
|
+
RubyParser.ruby(["#{fixtures_dir}lib/syntax.rb"], false, [])
|
14
14
|
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}lib/syntax.rb:\n.*syntax error})
|
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 bad style ruby file in the warning files array' do
|
19
|
-
RubyParser.ruby([fixtures_dir
|
19
|
+
RubyParser.ruby(["#{fixtures_dir}lib/style.rb"], true, [])
|
20
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.*Source code comment is empty.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment})
|
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.*Remove unnecessary empty.*\n.*Source code comment is empty.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment})
|
22
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
|
-
RubyParser.ruby([fixtures_dir
|
25
|
+
RubyParser.ruby(["#{fixtures_dir}lib/rubocop_style.rb"], true, ['--except', 'Lint/UselessAssignment,Style/HashSyntax,Style/GlobalVars,Style/StringLiterals'])
|
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}lib/rubocop_style.rb"])
|
29
29
|
end
|
30
30
|
it 'puts a good ruby file in the clean files array' do
|
31
|
-
RubyParser.ruby([fixtures_dir
|
31
|
+
RubyParser.ruby(["#{fixtures_dir}lib/good.rb"], true, [])
|
32
32
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
33
33
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
34
34
|
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}lib/good.rb"])
|
@@ -37,25 +37,29 @@ describe RubyParser do
|
|
37
37
|
|
38
38
|
context '.template' do
|
39
39
|
it 'puts a bad syntax ruby template file in the error files array' do
|
40
|
-
RubyParser.template([fixtures_dir
|
41
|
-
|
40
|
+
RubyParser.template(["#{fixtures_dir}templates/syntax.erb"])
|
41
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
|
42
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}templates/syntax.erb:\n.*1: syntax error, unexpected.*\n.*ruby})
|
43
|
+
else
|
44
|
+
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}templates/syntax.erb:\n.*syntax error, unexpected tIDENTIFIER})
|
45
|
+
end
|
42
46
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
43
47
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
44
48
|
end
|
45
49
|
it 'puts a bad style ruby template file in the warning files array' do
|
46
|
-
RubyParser.template([fixtures_dir
|
50
|
+
RubyParser.template(["#{fixtures_dir}templates/style.erb"])
|
47
51
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
48
52
|
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}templates/style.erb:\n.*already initialized constant.*\n.*previous definition of})
|
49
53
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
50
54
|
end
|
51
55
|
it 'puts a ruby template file with ignored errors in the clean files array' do
|
52
|
-
RubyParser.template([fixtures_dir
|
56
|
+
RubyParser.template(["#{fixtures_dir}templates/no_method_error.erb"])
|
53
57
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
54
58
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
55
59
|
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}templates/no_method_error.erb"])
|
56
60
|
end
|
57
61
|
it 'puts a good ruby template file in the clean files array' do
|
58
|
-
RubyParser.template([fixtures_dir
|
62
|
+
RubyParser.template(["#{fixtures_dir}templates/good.erb"])
|
59
63
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
60
64
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
61
65
|
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}templates/good.erb"])
|
@@ -64,25 +68,25 @@ describe RubyParser do
|
|
64
68
|
|
65
69
|
context '.librarian' do
|
66
70
|
it 'puts a bad syntax librarian Puppet file in the error files array' do
|
67
|
-
RubyParser.librarian([fixtures_dir
|
71
|
+
RubyParser.librarian(["#{fixtures_dir}librarian_syntax/Puppetfile"], false, [])
|
68
72
|
expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}librarian_syntax/Puppetfile:\n.*syntax error})
|
69
73
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
70
74
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
71
75
|
end
|
72
76
|
it 'puts a bad style librarian Puppet file in the warning files array' do
|
73
|
-
RubyParser.librarian([fixtures_dir
|
77
|
+
RubyParser.librarian(["#{fixtures_dir}librarian_style/Puppetfile"], true, [])
|
74
78
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
75
79
|
expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}librarian_style/Puppetfile:\n.*Align the arguments.*\n.*Use the new})
|
76
80
|
expect(PuppetCheck.settings[:clean_files]).to eql([])
|
77
81
|
end
|
78
82
|
it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
|
79
|
-
RubyParser.librarian([fixtures_dir
|
83
|
+
RubyParser.librarian(["#{fixtures_dir}librarian_style/Puppetfile"], true, ['--except', 'Layout/ArgumentAlignment,Style/HashSyntax'])
|
80
84
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
81
85
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
82
86
|
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}librarian_style/Puppetfile"])
|
83
87
|
end
|
84
88
|
it 'puts a good librarian Puppet file in the clean files array' do
|
85
|
-
RubyParser.librarian([fixtures_dir
|
89
|
+
RubyParser.librarian(["#{fixtures_dir}librarian_good/Puppetfile"], true, [])
|
86
90
|
expect(PuppetCheck.settings[:error_files]).to eql([])
|
87
91
|
expect(PuppetCheck.settings[:warning_files]).to eql([])
|
88
92
|
expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}librarian_good/Puppetfile"])
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'rake/task'
|
2
|
-
require_relative '../spec_helper
|
2
|
+
require_relative '../spec_helper'
|
3
3
|
require_relative '../../lib/puppet-check/tasks'
|
4
4
|
|
5
5
|
describe PuppetCheck::Tasks do
|
6
6
|
after(:all) do
|
7
7
|
# cleanup rspec_puppet_setup
|
8
|
-
|
9
|
-
%w[manifests modules].each { |dir| FileUtils.rm_r(
|
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 'puppetcheck:spec' do
|
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,13 @@ require 'rspec'
|
|
4
4
|
module Variables
|
5
5
|
extend RSpec::SharedContext
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
def fixtures_dir
|
8
|
+
@fixtures_dir = "#{File.dirname(__FILE__)}/fixtures/"
|
9
|
+
end
|
10
|
+
|
11
|
+
def octocatalog_diff_dir
|
12
|
+
@octocatalog_diff_dir = "#{File.dirname(__FILE__)}/octocatalog-diff/"
|
13
|
+
end
|
9
14
|
end
|
10
15
|
|
11
16
|
RSpec.configure do |config|
|
data/spec/system/system_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'rake/task'
|
2
|
-
require_relative '../spec_helper
|
2
|
+
require_relative '../spec_helper'
|
3
3
|
require_relative '../../lib/puppet-check/cli'
|
4
4
|
require_relative '../../lib/puppet-check/tasks'
|
5
5
|
|
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
|
10
|
-
let(:cli) { PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop
|
9
|
+
if ENV['TRAVIS'] == 'true' || 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 .]) }
|
11
11
|
else
|
12
|
-
let(:cli) { PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop
|
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 .]) }
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'outputs diagnostic results correctly after processing all of the files' do
|
@@ -17,9 +17,9 @@ describe PuppetCheck do
|
|
17
17
|
|
18
18
|
expect { cli }.not_to raise_exception
|
19
19
|
|
20
|
-
expect(PuppetCheck.settings[:error_files].length).to eql(
|
21
|
-
expect(PuppetCheck.settings[:warning_files].length).to eql(
|
22
|
-
expect(PuppetCheck.settings[:clean_files].length).to eql(
|
20
|
+
expect(PuppetCheck.settings[:error_files].length).to eql(10)
|
21
|
+
expect(PuppetCheck.settings[:warning_files].length).to eql(11)
|
22
|
+
expect(PuppetCheck.settings[:clean_files].length).to eql(13)
|
23
23
|
expect(PuppetCheck.settings[:ignored_files].length).to eql(6)
|
24
24
|
|
25
25
|
expect(cli).to eql(2)
|
@@ -40,18 +40,20 @@ describe PuppetCheck do
|
|
40
40
|
PuppetCheck.settings[:ignored_files] = []
|
41
41
|
PuppetCheck.settings[:style] = true
|
42
42
|
# see regression_check_spec
|
43
|
-
unless
|
43
|
+
unless ENV['TRAVIS'] == 'true' || ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
44
44
|
PuppetCheck.settings[:smoke] = true
|
45
45
|
PuppetCheck.settings[:octonodes] = %w[good.example.com]
|
46
46
|
PuppetCheck.settings[:octoconfig] = 'spec/octocatalog-diff/octocatalog-diff.cfg.rb'
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
# cannot re-use plan fixture between system tests
|
50
|
+
expect { tasks }.to raise_error(ArgumentError, /Attempt to redefine entity/)
|
50
51
|
|
51
|
-
|
52
|
-
expect(PuppetCheck.settings[:
|
53
|
-
expect(PuppetCheck.settings[:
|
54
|
-
expect(PuppetCheck.settings[:
|
52
|
+
# current puppet pops limitations no longer allow testing this
|
53
|
+
# expect(PuppetCheck.settings[:error_files].length).to eql(10)
|
54
|
+
# expect(PuppetCheck.settings[:warning_files].length).to eql(11)
|
55
|
+
# expect(PuppetCheck.settings[:clean_files].length).to eql(13)
|
56
|
+
# expect(PuppetCheck.settings[:ignored_files].length).to eql(6)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|