Skip to content

Commit

Permalink
Return empty hash if yaml file is empty. (#104)
Browse files Browse the repository at this point in the history
Fixes #103
  • Loading branch information
oneiros committed Nov 8, 2022
1 parent 19e382f commit f54beeb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/hiera_data/yaml_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def keys

def content
return nil unless exist?
@content ||= YAML.load(File.read(path))
@content ||= (YAML.load(File.read(path)) || {})
end

def [](key)
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions test/models/hiera_data/yaml_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class HieraData::YamlFileTest < ActiveSupport::TestCase
assert_equal expected_keys, file.keys
end

test "#content returns empty hash when file is empty" do
file = HieraData::YamlFile.new(path: config_dir.join("nodes/empty.yaml"))

assert_equal({}, file.content)
end

test "#content_for_key returns nil for unknown file and key" do
file = HieraData::YamlFile.new(path: config_dir.join("role/hdm_test-development.yaml"))
assert_nil file.content_for_key('noop_mode')
Expand Down

0 comments on commit f54beeb

Please sign in to comment.