Skip to content

Commit b25f35d

Browse files
(CAT-2484): Add integration test for Issue #254 YAML overwrite prevention
Verifies that --fix flag does not corrupt YAML files when processing directories containing both .pp and .yaml files. Signed-off-by: Gavin Didrichsen <[email protected]>
1 parent 6b988a2 commit b25f35d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-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/bin_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,24 @@ def initialize(args)
615615
end
616616
end
617617

618+
context 'when fixing a directory containing both .pp and .yaml files' do
619+
let(:args) { ['--fix', 'spec/fixtures/test/manifests/issue_254_overwriting_yaml'] }
620+
621+
its(:exitstatus) { is_expected.to eq(1) }
622+
623+
it 'does not overwrite YAML files' do
624+
yaml_file = 'spec/fixtures/test/manifests/issue_254_overwriting_yaml/class_with_dash.yaml'
625+
original_yaml = File.read(yaml_file)
626+
627+
bin # Run the command
628+
629+
yaml_after = File.read(yaml_file)
630+
expect(yaml_after).to eq(original_yaml)
631+
expect(yaml_after).to include('classes:')
632+
expect(yaml_after).not_to include('class foo-bar {')
633+
end
634+
end
635+
618636
context 'when overriding config file options with command line options' do
619637
context 'and config file sets "--only-checks=variable_contains_dash"' do
620638
around(:context) do |example|

0 commit comments

Comments
 (0)