Skip to content

Commit

Permalink
Fix confinement facts
Browse files Browse the repository at this point in the history
* Convert dotted fact names into hash keys
* Fix rspec tests
  • Loading branch information
silug committed Oct 30, 2024
1 parent 82398f0 commit 59fcb70
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
16 changes: 15 additions & 1 deletion lib/scelint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,21 @@ def normalize_confinement(confine)
end
end

normalized
# Step 3, convert dotted fact names into a facts hash
normalized.map do |c|
c.each_with_object({}) do |(key, value), result|
current = result
parts = key.split('.')
parts.each_with_index do |part, i|
if i == parts.length - 1
current[part] = value
else
current[part] ||= {}
current = current[part]
end
end
end
end
end

def confines
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
version: 2.0.0
ce:
11_ce1:
controls:
11_control1: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
version: 2.0.0
checks:
11_check1:
type: puppet-class-parameter
settings:
parameter: test_module_11::test_param
value: a string
ces:
- 11_ce1
11_check2:
type: puppet-class-parameter
settings:
parameter: test_module_11::test_param2
value: another string
ces:
- 11_ce1
6 changes: 3 additions & 3 deletions spec/unit/scelint/lint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
require 'spec_helper'

RSpec.describe Scelint::Lint do
# Each test assumes 3 files, no errors, no warnings.
# Each test assumes 3 files, no errors, no warnings, no notes.
# Exceptions are listed below.
let(:lint_files) { { '04' => 37 } }
let(:lint_files) { { '04' => 37, '11' => 2 } }
let(:lint_errors) { {} }
let(:lint_warnings) { { '04' => 17 } }
let(:lint_notes) { { '01' => 1, '02' => 3, '05' => 1 } }
let(:lint_notes) { { '11' => 1 } }

test_modules = Dir.glob(File.join(File.expand_path('../../fixtures', __dir__), 'modules', 'test_module_*'))
test_modules.each do |test_module|
Expand Down

0 comments on commit 59fcb70

Please sign in to comment.