puppetlabs-syntax 7.2.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 +7 -0
- data/.github/workflows/ci.yml +38 -0
- data/.github/workflows/mend.yml +15 -0
- data/.github/workflows/nightly.yml +30 -0
- data/.github/workflows/release.yml +16 -0
- data/.github/workflows/release_prep.yml +20 -0
- data/.gitignore +20 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +177 -0
- data/CHANGELOG.md +183 -0
- data/CODEOWNERS +2 -0
- data/Gemfile +59 -0
- data/HISTORY.md +382 -0
- data/LICENSE.txt +22 -0
- data/README.md +198 -0
- data/Rakefile +26 -0
- data/lib/puppetlabs-syntax/hiera.rb +176 -0
- data/lib/puppetlabs-syntax/manifests.rb +70 -0
- data/lib/puppetlabs-syntax/tasks/puppetlabs-syntax.rb +86 -0
- data/lib/puppetlabs-syntax/templates.rb +90 -0
- data/lib/puppetlabs-syntax/version.rb +5 -0
- data/lib/puppetlabs-syntax.rb +42 -0
- data/puppetlabs-syntax.gemspec +28 -0
- data/spec/fixtures/hiera/data/hiera_1.yaml +0 -0
- data/spec/fixtures/hiera/data/hiera_2.eyaml +0 -0
- data/spec/fixtures/hiera/data/test/hiera_3.yaml +0 -0
- data/spec/fixtures/hiera/data/test/hiera_4.eyaml +0 -0
- data/spec/fixtures/hiera/hiera_bad.eyaml +25 -0
- data/spec/fixtures/hiera/hiera_bad.yaml +1 -0
- data/spec/fixtures/hiera/hiera_badkey.yaml +18 -0
- data/spec/fixtures/hiera/hiera_badvalue.yaml +8 -0
- data/spec/fixtures/hiera/hiera_good.eyaml +13 -0
- data/spec/fixtures/hiera/hiera_good.yaml +7 -0
- data/spec/fixtures/hiera/hiera_key_empty.yaml +0 -0
- data/spec/fixtures/hiera/hiera_key_no_value.yaml +2 -0
- data/spec/fixtures/test_module/manifests/deprecation_notice.pp +6 -0
- data/spec/fixtures/test_module/manifests/fail_error.pp +3 -0
- data/spec/fixtures/test_module/manifests/fail_warning.pp +5 -0
- data/spec/fixtures/test_module/manifests/future_syntax.pp +3 -0
- data/spec/fixtures/test_module/manifests/pass.pp +5 -0
- data/spec/fixtures/test_module/manifests/pass_storeconfigs.pp +3 -0
- data/spec/fixtures/test_module/manifests/schedule_notice.pp +5 -0
- data/spec/fixtures/test_module/manifests/tag_notice.pp +5 -0
- data/spec/fixtures/test_module/manifests/test_app.pp +3 -0
- data/spec/fixtures/test_module/templates/fail_error.epp +3 -0
- data/spec/fixtures/test_module/templates/fail_error.erb +3 -0
- data/spec/fixtures/test_module/templates/fail_error_also.epp +3 -0
- data/spec/fixtures/test_module/templates/fail_warning.erb +2 -0
- data/spec/fixtures/test_module/templates/ignore.tpl +3 -0
- data/spec/fixtures/test_module/templates/pass.epp +3 -0
- data/spec/fixtures/test_module/templates/pass.erb +2 -0
- data/spec/fixtures/test_module/templates/pass_also.epp +3 -0
- data/spec/fixtures/test_module/templates/pass_unbound_var.erb +1 -0
- data/spec/fixtures/test_module/templates/typeerror_shouldwin.erb +2 -0
- data/spec/puppetlabs-syntax/hiera_spec.rb +107 -0
- data/spec/puppetlabs-syntax/manifests_spec.rb +96 -0
- data/spec/puppetlabs-syntax/tasks/puppetlabs-syntax_spec.rb +55 -0
- data/spec/puppetlabs-syntax/templates_spec.rb +127 -0
- data/spec/puppetlabs-syntax_spec.rb +42 -0
- data/spec/spec_helper.rb +26 -0
- metadata +150 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= this_variable_has_not_been_bound %>
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe PuppetlabsSyntax::Hiera do
|
|
6
|
+
let(:subject) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'expects an array of files' do
|
|
9
|
+
expect { subject.check(nil) }.to raise_error(/Expected an array of files/)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'returns nothing from valid YAML' do
|
|
13
|
+
files = fixture_hiera('hiera_good.yaml')
|
|
14
|
+
res = subject.check(files)
|
|
15
|
+
expect(res).to eq []
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'returns an error from invalid YAML' do
|
|
19
|
+
files = fixture_hiera('hiera_bad.yaml')
|
|
20
|
+
expected = /ERROR: Failed to parse #{files[0]}:/
|
|
21
|
+
res = subject.check(files)
|
|
22
|
+
expect(res.size).to eq 1
|
|
23
|
+
expect(res.first).to match(expected)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'returns warnings on malformed keys' do
|
|
27
|
+
files = fixture_hiera('hiera_key_no_value.yaml')
|
|
28
|
+
expected = /ERROR: #{files[0]} doesn't contain a valid Hash, datatype is/
|
|
29
|
+
res = subject.check(files)
|
|
30
|
+
expect(res.size).to eq 1
|
|
31
|
+
expect(res.first).to match(expected)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'check_hiera_keys = true' do
|
|
35
|
+
before do
|
|
36
|
+
PuppetlabsSyntax.check_hiera_keys = true
|
|
37
|
+
PuppetlabsSyntax.check_hiera_data = true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns warnings for invalid keys' do
|
|
41
|
+
hiera_yaml = 'hiera_badkey.yaml'
|
|
42
|
+
examples = 9
|
|
43
|
+
files = fixture_hiera(hiera_yaml)
|
|
44
|
+
res = subject.check(files)
|
|
45
|
+
(1..examples).each do |n|
|
|
46
|
+
expect(res).to include(/warning#{n}:/)
|
|
47
|
+
end
|
|
48
|
+
expect(res.size).to eq examples
|
|
49
|
+
expect(res[0]).to match('Key :typical:typo::warning1: Looks like a missing colon')
|
|
50
|
+
expect(res[1]).to match('Key ::notsotypical::warning2: Puppet automatic lookup will not use leading \'::\'')
|
|
51
|
+
expect(res[2]).to match('Key :noCamelCase::warning3: Not a valid Puppet variable name for automatic lookup')
|
|
52
|
+
expect(res[3]).to match('Key :root::noCamelCase::warning4: Not a valid Puppet variable name for automatic lookup')
|
|
53
|
+
expect(res[4]).to match('Key :Leading_caps_warning5: Not a valid Puppet variable name for automatic lookup')
|
|
54
|
+
expect(res[5]).to match('Key :namespace::Leading_warning6: Not a valid Puppet variable name for automatic lookup')
|
|
55
|
+
expect(res[6]).to match('Key :no-hyphens::warning7: Not a valid Puppet variable name for automatic lookup')
|
|
56
|
+
expect(res[7]).to match('Key :picky::warning8: Puppet automatic lookup will not look up symbols')
|
|
57
|
+
expect(res[8]).to match('Key :this_is::warning9: string after a function call but before `}` in the value')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'returns warnings for invalid values' do
|
|
61
|
+
hiera_yaml = 'hiera_badvalue.yaml'
|
|
62
|
+
examples = 3
|
|
63
|
+
files = fixture_hiera(hiera_yaml)
|
|
64
|
+
res = subject.check(files)
|
|
65
|
+
(1..examples).each do |n|
|
|
66
|
+
expect(res).to include(/warning#{n}:/)
|
|
67
|
+
end
|
|
68
|
+
expect(res.size).to eq examples
|
|
69
|
+
expect(res[0]).to match('Key :this_is::warning1: string after a function call but before `}` in the value')
|
|
70
|
+
expect(res[1]).to match('Key :this_is::warning2: string after a function call but before `}` in the value')
|
|
71
|
+
expect(res[2]).to match('Key :this_is::warning3: string after a function call but before `}` in the value')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'returns nothing for good eyaml' do
|
|
75
|
+
files = fixture_hiera('hiera_good.eyaml')
|
|
76
|
+
res = subject.check(files)
|
|
77
|
+
expect(res).to eq []
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'returns warnings for bad eyaml values' do
|
|
81
|
+
hiera_yaml = 'hiera_bad.eyaml'
|
|
82
|
+
examples = 9
|
|
83
|
+
files = fixture_hiera(hiera_yaml)
|
|
84
|
+
res = subject.check(files)
|
|
85
|
+
(1..examples).each do |n|
|
|
86
|
+
expect(res).to include(/::warning#{n}/)
|
|
87
|
+
end
|
|
88
|
+
expect(res.size).to eq examples
|
|
89
|
+
expect(res[0]).to match('Key acme::warning1 has unknown eyaml method unknown-method')
|
|
90
|
+
expect(res[1]).to match('Key acme::warning2 has unterminated eyaml value')
|
|
91
|
+
expect(res[2]).to match('Key acme::warning3 has unpadded or truncated base64 data')
|
|
92
|
+
expect(res[3]).to match('Key acme::warning4 has corrupt base64 data')
|
|
93
|
+
expect(res[4]).to match('Key acme::warning5\[\'key2\'\] has corrupt base64 data')
|
|
94
|
+
expect(res[5]).to match('Key acme::warning6\[\'hash_key\'\]\[2\] has corrupt base64 data')
|
|
95
|
+
expect(res[6]).to match('Key acme::warning7 has invalid eyaml encoded format')
|
|
96
|
+
expect(res[7]).to match('Key acme::warning8 has unpadded or truncated base64 data')
|
|
97
|
+
expect(res[8]).to match('Key acme::warning9 has unterminated eyaml value')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'handles empty files' do
|
|
101
|
+
hiera_yaml = 'hiera_key_empty.yaml'
|
|
102
|
+
files = fixture_hiera(hiera_yaml)
|
|
103
|
+
res = subject.check(files)
|
|
104
|
+
expect(res).to be_empty
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'puppet'
|
|
5
|
+
|
|
6
|
+
describe PuppetlabsSyntax::Manifests do
|
|
7
|
+
let(:subject) { described_class.new }
|
|
8
|
+
|
|
9
|
+
it 'expects an array of files' do
|
|
10
|
+
expect { subject.check(nil) }.to raise_error(/Expected an array of files/)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'returns nothing from a valid file' do
|
|
14
|
+
files = fixture_manifests('pass.pp')
|
|
15
|
+
output, has_errors = subject.check(files)
|
|
16
|
+
|
|
17
|
+
expect(output).to eq([])
|
|
18
|
+
expect(has_errors).to be(false)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'returns nothing from a valid file with a class using tag parameter' do
|
|
22
|
+
files = fixture_manifests('tag_notice.pp')
|
|
23
|
+
output, has_errors = subject.check(files)
|
|
24
|
+
|
|
25
|
+
expect(output).to eq([])
|
|
26
|
+
expect(has_errors).to be(false)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'returns nothing from a valid file with a class using schedule parameter' do
|
|
30
|
+
files = fixture_manifests('schedule_notice.pp')
|
|
31
|
+
output, has_errors = subject.check(files)
|
|
32
|
+
|
|
33
|
+
expect(output).to eq([])
|
|
34
|
+
expect(has_errors).to be(false)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'returns an error from an invalid file' do
|
|
38
|
+
files = fixture_manifests('fail_error.pp')
|
|
39
|
+
output, has_errors = subject.check(files)
|
|
40
|
+
|
|
41
|
+
expect(output.size).to eq(3)
|
|
42
|
+
expect(output[2]).to match(/2 errors. Giving up/)
|
|
43
|
+
expect(has_errors).to be(true)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'returns a warning from an invalid file' do
|
|
47
|
+
files = fixture_manifests('fail_warning.pp')
|
|
48
|
+
output, has_errors = subject.check(files)
|
|
49
|
+
|
|
50
|
+
expect(output.size).to eq(2)
|
|
51
|
+
expect(has_errors).to be(true)
|
|
52
|
+
|
|
53
|
+
expect(output[0]).to match(/Unrecogni(s|z)ed escape sequence '\\\['/)
|
|
54
|
+
expect(output[1]).to match(/Unrecogni(s|z)ed escape sequence '\\\]'/)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'ignores warnings about storeconfigs' do
|
|
58
|
+
files = fixture_manifests('pass_storeconfigs.pp')
|
|
59
|
+
output, has_errors = subject.check(files)
|
|
60
|
+
|
|
61
|
+
expect(output).to eq([])
|
|
62
|
+
expect(has_errors).to be(false)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'reads more than one valid file' do
|
|
66
|
+
files = fixture_manifests(['pass.pp', 'pass_storeconfigs.pp'])
|
|
67
|
+
output, has_errors = subject.check(files)
|
|
68
|
+
|
|
69
|
+
expect(output).to eq([])
|
|
70
|
+
expect(has_errors).to be(false)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'continues after finding an error in the first file' do
|
|
74
|
+
files = fixture_manifests(['fail_error.pp', 'fail_warning.pp'])
|
|
75
|
+
output, has_errors = subject.check(files)
|
|
76
|
+
|
|
77
|
+
expect(has_errors).to be(true)
|
|
78
|
+
expect(output.size).to eq(5)
|
|
79
|
+
expect(output[0]).to match(%r{This Name has no effect. A Host Class Definition can not end with a value-producing expression without other effect \(file: \S*/fail_error.pp, line: 2, column: 32\)$})
|
|
80
|
+
expect(output[1]).to match(%r{This Name has no effect. A value was produced and then forgotten \(one or more preceding expressions may have the wrong form\) \(file: \S*/fail_error.pp, line: 2, column: 3\)$})
|
|
81
|
+
expect(output[2]).to match('2 errors. Giving up')
|
|
82
|
+
expect(output[3]).to match(/Unrecogni(s|z)ed escape sequence '\\\['/)
|
|
83
|
+
expect(output[4]).to match(/Unrecogni(s|z)ed escape sequence '\\\]'/)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe 'deprecation notices' do
|
|
87
|
+
it 'insteads be failures' do
|
|
88
|
+
files = fixture_manifests('deprecation_notice.pp')
|
|
89
|
+
output, has_errors = subject.check(files)
|
|
90
|
+
|
|
91
|
+
expect(has_errors).to be(true)
|
|
92
|
+
expect(output.size).to eq(1)
|
|
93
|
+
expect(output[0]).to match(/Node inheritance is not supported in Puppet >= 4.0.0/)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'puppetlabs-syntax/tasks/puppetlabs-syntax'
|
|
5
|
+
|
|
6
|
+
known_pp = 'spec/fixtures/test_module/manifests/pass.pp'
|
|
7
|
+
known_erb = 'spec/fixtures/test_module/templates/pass.erb'
|
|
8
|
+
known_yaml = 'spec/fixtures/hiera/data/hiera_1.yaml'
|
|
9
|
+
known_eyaml = 'spec/fixtures/hiera/data/hiera_2.eyaml'
|
|
10
|
+
known_yaml_subdir = 'spec/fixtures/hiera/data/test/hiera_3.yaml'
|
|
11
|
+
known_eyaml_subdir = 'spec/fixtures/hiera/data/test/hiera_4.eyaml'
|
|
12
|
+
|
|
13
|
+
describe 'PuppetlabsSyntax rake tasks' do
|
|
14
|
+
describe 'with default excludes' do
|
|
15
|
+
it 'filters directories' do
|
|
16
|
+
list = PuppetlabsSyntax::RakeTask.new.filelist(['**/lib', known_pp])
|
|
17
|
+
expect(list.count).to eq 0
|
|
18
|
+
expect(list).not_to include(known_pp)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe 'with custom excludes' do
|
|
23
|
+
before do
|
|
24
|
+
list = PuppetlabsSyntax.exclude_paths
|
|
25
|
+
PuppetlabsSyntax.exclude_paths = list - ['spec/fixtures/**/*']
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'filters directories' do
|
|
29
|
+
list = PuppetlabsSyntax::RakeTask.new.filelist(['**/lib', known_pp])
|
|
30
|
+
expect(list.count).to eq 1
|
|
31
|
+
expect(list).to include(known_pp)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'generates FileList of manifests relative to Rakefile' do
|
|
35
|
+
list = PuppetlabsSyntax::RakeTask.new.filelist_manifests
|
|
36
|
+
expect(list).to include(known_pp)
|
|
37
|
+
expect(list.count).to eq 9
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'generates FileList of templates relative to Rakefile' do
|
|
41
|
+
list = PuppetlabsSyntax::RakeTask.new.filelist_templates
|
|
42
|
+
expect(list).to include(known_erb)
|
|
43
|
+
expect(list.count).to eq 9
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'generates FileList of Hiera yaml files relative to Rakefile' do
|
|
47
|
+
list = PuppetlabsSyntax::RakeTask.new.filelist_hiera_yaml
|
|
48
|
+
expect(list).to include(known_yaml)
|
|
49
|
+
expect(list).to include(known_eyaml)
|
|
50
|
+
expect(list).to include(known_yaml_subdir)
|
|
51
|
+
expect(list).to include(known_eyaml_subdir)
|
|
52
|
+
expect(list.count).to eq 4
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe PuppetlabsSyntax::Templates do
|
|
6
|
+
let(:subject) { described_class.new }
|
|
7
|
+
let(:conditional_warning_regex) do
|
|
8
|
+
# ruby 3.4 uses '= ,ruby 2.6 to 3.3 uses `=
|
|
9
|
+
/2: warning: found [`']= literal' in conditional/
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'expects an array of files' do
|
|
13
|
+
expect { subject.check(nil) }.to raise_error(/Expected an array of files/)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'returns nothing from a valid file' do
|
|
17
|
+
files = fixture_templates('pass.erb')
|
|
18
|
+
res = subject.check(files)
|
|
19
|
+
|
|
20
|
+
expect(res[:warnings]).to match([])
|
|
21
|
+
expect(res[:errors]).to match([])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'ignores NameErrors from unbound variables' do
|
|
25
|
+
files = fixture_templates('pass_unbound_var.erb')
|
|
26
|
+
res = subject.check(files)
|
|
27
|
+
|
|
28
|
+
expect(res[:warnings]).to match([])
|
|
29
|
+
expect(res[:errors]).to match([])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'catches SyntaxError' do
|
|
33
|
+
files = fixture_templates('fail_error.erb')
|
|
34
|
+
res = subject.check(files)
|
|
35
|
+
|
|
36
|
+
expect(res[:errors].size).to eq(1)
|
|
37
|
+
expect(res[:errors][0]).to match(/2: syntax error/)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'catches Ruby warnings' do
|
|
41
|
+
files = fixture_templates('fail_warning.erb')
|
|
42
|
+
res = subject.check(files)
|
|
43
|
+
|
|
44
|
+
expect(res[:warnings].size).to eq(1)
|
|
45
|
+
expect(res[:warnings][0]).to match(conditional_warning_regex)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'reads more than one valid file' do
|
|
49
|
+
files = fixture_templates(['pass.erb', 'pass_unbound_var.erb'])
|
|
50
|
+
res = subject.check(files)
|
|
51
|
+
|
|
52
|
+
expect(res[:warnings]).to match([])
|
|
53
|
+
expect(res[:errors]).to match([])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'continues after finding an error in the first file' do
|
|
57
|
+
files = fixture_templates(['fail_error.erb', 'fail_warning.erb'])
|
|
58
|
+
res = subject.check(files)
|
|
59
|
+
|
|
60
|
+
expect(res[:warnings].size).to eq(1)
|
|
61
|
+
expect(res[:errors].size).to eq(1)
|
|
62
|
+
expect(res[:errors][0]).to match(/2: syntax error/)
|
|
63
|
+
expect(res[:warnings][0]).to match(conditional_warning_regex)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'ignores a TypeError' do
|
|
67
|
+
files = fixture_templates('typeerror_shouldwin.erb')
|
|
68
|
+
res = subject.check(files)
|
|
69
|
+
|
|
70
|
+
expect(res[:warnings]).to match([])
|
|
71
|
+
expect(res[:errors]).to match([])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'ignores files without .erb extension' do
|
|
75
|
+
files = fixture_templates('ignore.tpl')
|
|
76
|
+
res = subject.check(files)
|
|
77
|
+
|
|
78
|
+
expect(res[:warnings]).to match([])
|
|
79
|
+
expect(res[:errors]).to match([])
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'returns nothing from a valid file' do
|
|
83
|
+
files = fixture_templates('pass.epp')
|
|
84
|
+
res = subject.check(files)
|
|
85
|
+
|
|
86
|
+
expect(res[:warnings]).to match([])
|
|
87
|
+
expect(res[:errors]).to match([])
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'catches SyntaxError' do
|
|
91
|
+
files = fixture_templates('fail_error.epp')
|
|
92
|
+
res = subject.check(files)
|
|
93
|
+
|
|
94
|
+
expect(res[:errors].size).to eq(1)
|
|
95
|
+
expect(res[:errors][0]).to match(/This Type-Name has no effect/)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'reads more than one valid file' do
|
|
99
|
+
files = fixture_templates(['pass.epp', 'pass_also.epp'])
|
|
100
|
+
res = subject.check(files)
|
|
101
|
+
|
|
102
|
+
expect(res[:warnings]).to match([])
|
|
103
|
+
expect(res[:errors]).to match([])
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'continues after finding an error in the first file' do
|
|
107
|
+
files = fixture_templates(['fail_error.epp', 'fail_error_also.epp'])
|
|
108
|
+
res = subject.check(files)
|
|
109
|
+
|
|
110
|
+
expect(res[:errors].size).to eq(2)
|
|
111
|
+
expect(res[:errors][0]).to match(/This Type-Name has no effect/)
|
|
112
|
+
expect(res[:errors][1]).to match(/Syntax error at '}' \(file: \S*\/fail_error_also.epp, line: 2, column: 4\)/)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context "when the 'epp_only' options is set" do
|
|
116
|
+
before do
|
|
117
|
+
PuppetlabsSyntax.epp_only = true
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'processes an ERB as EPP and find an error' do
|
|
121
|
+
files = fixture_templates('pass.erb')
|
|
122
|
+
res = subject.check(files)
|
|
123
|
+
|
|
124
|
+
expect(res[:errors].size).to eq(1)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe PuppetlabsSyntax do
|
|
6
|
+
after do
|
|
7
|
+
described_class.exclude_paths = []
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'defaults exclude_paths to include the pkg directory' do
|
|
11
|
+
expect(described_class.exclude_paths).to include('pkg/**/*')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'supports setting exclude_paths' do
|
|
15
|
+
described_class.exclude_paths = ['foo', 'bar/baz']
|
|
16
|
+
expect(described_class.exclude_paths).to eq(['foo', 'bar/baz'])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'supports appending exclude_paths' do
|
|
20
|
+
described_class.exclude_paths << 'foo'
|
|
21
|
+
expect(described_class.exclude_paths).to eq(['foo'])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'supports a fail_on_deprecation_notices setting' do
|
|
25
|
+
described_class.fail_on_deprecation_notices = false
|
|
26
|
+
expect(described_class.fail_on_deprecation_notices).to be(false)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'supports forcing EPP only templates' do
|
|
30
|
+
described_class.epp_only = true
|
|
31
|
+
expect(described_class.epp_only).to be(true)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'supports setting paths for manifests, templates and hiera' do
|
|
35
|
+
described_class.hieradata_paths = []
|
|
36
|
+
expect(described_class.hieradata_paths).to eq([])
|
|
37
|
+
described_class.manifests_paths = ['**/environments/production/**/*.pp']
|
|
38
|
+
expect(described_class.manifests_paths).to eq(['**/environments/production/**/*.pp'])
|
|
39
|
+
described_class.templates_paths = []
|
|
40
|
+
expect(described_class.templates_paths).to eq([])
|
|
41
|
+
end
|
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rspec'
|
|
4
|
+
require 'puppetlabs-syntax'
|
|
5
|
+
|
|
6
|
+
def fixture_hiera(list)
|
|
7
|
+
fixture_files(list, 'hiera')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def fixture_templates(list)
|
|
11
|
+
fixture_files(list, 'test_module/templates')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def fixture_manifests(list)
|
|
15
|
+
fixture_files(list, 'test_module/manifests')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def fixture_files(list, path)
|
|
19
|
+
list = [list].flatten
|
|
20
|
+
list.map { |f| File.expand_path("../fixtures/#{path}/#{f}", __FILE__) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
RSpec.configure do |config|
|
|
24
|
+
config.color = true
|
|
25
|
+
config.formatter = 'documentation'
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: puppetlabs-syntax
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 7.2.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Puppet, Inc.
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-08-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: puppet
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '8'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '10'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '8'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '10'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: rake
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '13.1'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '13.1'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: voxpupuli-rubocop
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 5.2.0
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 5.2.0
|
|
61
|
+
description: " Syntax checks for Puppet manifests and templates.\n"
|
|
62
|
+
email:
|
|
63
|
+
- modules-team@puppet.com
|
|
64
|
+
executables: []
|
|
65
|
+
extensions: []
|
|
66
|
+
extra_rdoc_files: []
|
|
67
|
+
files:
|
|
68
|
+
- ".github/workflows/ci.yml"
|
|
69
|
+
- ".github/workflows/mend.yml"
|
|
70
|
+
- ".github/workflows/nightly.yml"
|
|
71
|
+
- ".github/workflows/release.yml"
|
|
72
|
+
- ".github/workflows/release_prep.yml"
|
|
73
|
+
- ".gitignore"
|
|
74
|
+
- ".rubocop.yml"
|
|
75
|
+
- ".rubocop_todo.yml"
|
|
76
|
+
- CHANGELOG.md
|
|
77
|
+
- CODEOWNERS
|
|
78
|
+
- Gemfile
|
|
79
|
+
- HISTORY.md
|
|
80
|
+
- LICENSE.txt
|
|
81
|
+
- README.md
|
|
82
|
+
- Rakefile
|
|
83
|
+
- lib/puppetlabs-syntax.rb
|
|
84
|
+
- lib/puppetlabs-syntax/hiera.rb
|
|
85
|
+
- lib/puppetlabs-syntax/manifests.rb
|
|
86
|
+
- lib/puppetlabs-syntax/tasks/puppetlabs-syntax.rb
|
|
87
|
+
- lib/puppetlabs-syntax/templates.rb
|
|
88
|
+
- lib/puppetlabs-syntax/version.rb
|
|
89
|
+
- puppetlabs-syntax.gemspec
|
|
90
|
+
- spec/fixtures/hiera/data/hiera_1.yaml
|
|
91
|
+
- spec/fixtures/hiera/data/hiera_2.eyaml
|
|
92
|
+
- spec/fixtures/hiera/data/test/hiera_3.yaml
|
|
93
|
+
- spec/fixtures/hiera/data/test/hiera_4.eyaml
|
|
94
|
+
- spec/fixtures/hiera/hiera_bad.eyaml
|
|
95
|
+
- spec/fixtures/hiera/hiera_bad.yaml
|
|
96
|
+
- spec/fixtures/hiera/hiera_badkey.yaml
|
|
97
|
+
- spec/fixtures/hiera/hiera_badvalue.yaml
|
|
98
|
+
- spec/fixtures/hiera/hiera_good.eyaml
|
|
99
|
+
- spec/fixtures/hiera/hiera_good.yaml
|
|
100
|
+
- spec/fixtures/hiera/hiera_key_empty.yaml
|
|
101
|
+
- spec/fixtures/hiera/hiera_key_no_value.yaml
|
|
102
|
+
- spec/fixtures/test_module/manifests/deprecation_notice.pp
|
|
103
|
+
- spec/fixtures/test_module/manifests/fail_error.pp
|
|
104
|
+
- spec/fixtures/test_module/manifests/fail_warning.pp
|
|
105
|
+
- spec/fixtures/test_module/manifests/future_syntax.pp
|
|
106
|
+
- spec/fixtures/test_module/manifests/pass.pp
|
|
107
|
+
- spec/fixtures/test_module/manifests/pass_storeconfigs.pp
|
|
108
|
+
- spec/fixtures/test_module/manifests/schedule_notice.pp
|
|
109
|
+
- spec/fixtures/test_module/manifests/tag_notice.pp
|
|
110
|
+
- spec/fixtures/test_module/manifests/test_app.pp
|
|
111
|
+
- spec/fixtures/test_module/templates/fail_error.epp
|
|
112
|
+
- spec/fixtures/test_module/templates/fail_error.erb
|
|
113
|
+
- spec/fixtures/test_module/templates/fail_error_also.epp
|
|
114
|
+
- spec/fixtures/test_module/templates/fail_warning.erb
|
|
115
|
+
- spec/fixtures/test_module/templates/ignore.tpl
|
|
116
|
+
- spec/fixtures/test_module/templates/pass.epp
|
|
117
|
+
- spec/fixtures/test_module/templates/pass.erb
|
|
118
|
+
- spec/fixtures/test_module/templates/pass_also.epp
|
|
119
|
+
- spec/fixtures/test_module/templates/pass_unbound_var.erb
|
|
120
|
+
- spec/fixtures/test_module/templates/typeerror_shouldwin.erb
|
|
121
|
+
- spec/puppetlabs-syntax/hiera_spec.rb
|
|
122
|
+
- spec/puppetlabs-syntax/manifests_spec.rb
|
|
123
|
+
- spec/puppetlabs-syntax/tasks/puppetlabs-syntax_spec.rb
|
|
124
|
+
- spec/puppetlabs-syntax/templates_spec.rb
|
|
125
|
+
- spec/puppetlabs-syntax_spec.rb
|
|
126
|
+
- spec/spec_helper.rb
|
|
127
|
+
homepage: https://github.com/puppetlabs/puppetlabs-syntax/
|
|
128
|
+
licenses:
|
|
129
|
+
- MIT
|
|
130
|
+
metadata: {}
|
|
131
|
+
post_install_message:
|
|
132
|
+
rdoc_options: []
|
|
133
|
+
require_paths:
|
|
134
|
+
- lib
|
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - ">="
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '3.2'
|
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
145
|
+
requirements: []
|
|
146
|
+
rubygems_version: 3.4.19
|
|
147
|
+
signing_key:
|
|
148
|
+
specification_version: 4
|
|
149
|
+
summary: Syntax checks for Puppet manifests, templates, and Hiera YAML
|
|
150
|
+
test_files: []
|