Skip to content

Commit

Permalink
raise error if hiera.yaml is specified but does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tw1r3 committed Feb 7, 2024
1 parent 6d80e2c commit b6ef365
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/puppet-lint/plugins/check_ghostbuster_hiera_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ def load_data(path, content)

PuppetLint.new_check(:ghostbuster_hiera_files) do
def hiera
@hiera ||= [ENV.fetch('HIERA_YAML_PATH', nil), '/etc/puppetlabs/puppetlabs/hiera.yaml'].filter_map do |hiera_file|
YAML.load_file(hiera_file) if hiera_file && File.exist?(hiera_file)
end
@hiera[0]
@hiera ||= if (hiera_file = ENV.fetch('HIERA_YAML_PATH', false))
YAML.load_file(hiera_file)
else
hiera = ['/etc/puppetlabs/puppet/hiera.yaml'].filter_map do |hf|
YAML.load_file(hf) if hf && File.exist?(hf)
end
hiera[0]
end
end

def default_datadir
Expand Down
9 changes: 9 additions & 0 deletions spec/puppet-lint/plugins/ghostbuster_hiera_files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,14 @@
expect(problems.size).to eq(0)
}
end

context 'when HIERA_YAML_PATH is set but does not exist' do
let(:path) { './data/domain/example.com.yaml' }

it {
ENV['HIERA_YAML_PATH'] = './spec/fixtures/j.yaml'
expect { problems }.to raise_error(Errno::ENOENT)
}
end
end
end

0 comments on commit b6ef365

Please sign in to comment.