Skip to content

Commit 185f57a

Browse files
(CAT-2484): add unit tests for new file-type aware fixing methods on puppet-lint
Tests supports_fixes? and should_write_fixes? methods that implement selective fixing based on file extension. Signed-off-by: Gavin Didrichsen <[email protected]>
1 parent 762497d commit 185f57a

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class foo-bar {
2+
notify { 'hello': }
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
classes:
3+
foo-bar:
4+
parameters: []
5+
resources:
6+
notify:
7+
- title: hello

spec/unit/puppet-lint/puppet-lint_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,53 @@
1515
linter.run
1616
expect(linter.manifest).to eq('')
1717
end
18+
19+
describe '#supports_fixes?' do
20+
context 'with a .pp file' do
21+
it 'returns true' do
22+
linter.instance_variable_set(:@path, 'test.pp')
23+
expect(linter.supports_fixes?).to be true
24+
end
25+
end
26+
27+
context 'with a .yaml file' do
28+
it 'returns false' do
29+
linter.instance_variable_set(:@path, 'test.yaml')
30+
expect(linter.supports_fixes?).to be false
31+
end
32+
end
33+
34+
context 'with no path set' do
35+
it 'returns false' do
36+
expect(linter.supports_fixes?).to be false
37+
end
38+
end
39+
end
40+
41+
describe '#should_write_fixes?' do
42+
before(:each) do
43+
linter.instance_variable_set(:@path, 'test.pp')
44+
linter.instance_variable_set(:@manifest, 'class test { }')
45+
end
46+
47+
context 'when file supports fixes and has no syntax errors' do
48+
it 'returns true' do
49+
expect(linter.should_write_fixes?).to be true
50+
end
51+
end
52+
53+
context 'when file has syntax errors' do
54+
it 'returns false' do
55+
linter.instance_variable_set(:@problems, [{ check: :syntax }])
56+
expect(linter.should_write_fixes?).to be false
57+
end
58+
end
59+
60+
context 'when file type does not support fixes' do
61+
it 'returns false' do
62+
linter.instance_variable_set(:@path, 'test.yaml')
63+
expect(linter.should_write_fixes?).to be false
64+
end
65+
end
66+
end
1867
end

0 commit comments

Comments
 (0)