Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
(FACT-2555) Fix os hierarchy for intermediary nodes. Add tests for in…
Browse files Browse the repository at this point in the history
…termediary and root nodes.
  • Loading branch information
Bogdan Irimie committed Apr 28, 2020
1 parent 0b220cd commit 228b42f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/framework/detector/os_hierarchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module Facter
class OsHierarchy
@searched_path = []

def initialize
json_file = Util::FileHelper.safe_read('os_hierarchy.json')
@json_data = JSON.parse(json_file)
Expand Down Expand Up @@ -33,6 +31,8 @@ def search(json_data, searched_element, path)
next unless tree_node.is_a?(Hash)

tree_node.each do |k, v|
return @searched_path = path.dup << k if k == searched_element

search(v, searched_element, path << k)
path.pop
end
Expand Down
16 changes: 16 additions & 0 deletions spec/framework/detector/os_hierarchy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
end
end

context 'when searched_os is debian' do
it 'constructs hierarchy' do
hierarchy = os_hierarchy.construct_hierarchy(:debian)

expect(hierarchy).to eq(%w[Linux Debian])
end
end

context 'when searched_os is linux' do
it 'constructs hierarchy' do
hierarchy = os_hierarchy.construct_hierarchy(:linux)

expect(hierarchy).to eq(%w[Linux])
end
end

context 'when searched_os is nil' do
it 'constructs hierarchy' do
hierarchy = os_hierarchy.construct_hierarchy(nil)
Expand Down

0 comments on commit 228b42f

Please sign in to comment.