Skip to content

Commit

Permalink
Merge pull request #2055 from oanatmaria/FACT-2754
Browse files Browse the repository at this point in the history
(FACT-2754) Add os.distro release legacy facts
  • Loading branch information
Bogdan Irimie authored Sep 1, 2020
2 parents ab19001 + ce0e263 commit 7863203
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/facter/facts/debian/os/distro/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ module Os
module Distro
class Release
FACT_NAME = 'os.distro.release'
ALIASES = %w[lsbdistrelease lsbmajdistrelease lsbminordistrelease].freeze

def call_the_resolver
fact_value = determine_release_for_os
return Facter::ResolvedFact.new(FACT_NAME, nil) unless fact_value

Facter::ResolvedFact.new(FACT_NAME, fact_value)
[Facter::ResolvedFact.new(FACT_NAME, fact_value),
Facter::ResolvedFact.new(ALIASES[0], fact_value['full'], :legacy),
Facter::ResolvedFact.new(ALIASES[1], fact_value['major'], :legacy),
Facter::ResolvedFact.new(ALIASES[2], fact_value['minor'], :legacy)]
end

private
Expand Down
14 changes: 11 additions & 3 deletions spec/facter/facts/debian/os/distro/release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

shared_examples 'returns distro release fact' do
it 'returns release fact' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'os.distro.release', value: fact_value)
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \
contain_exactly(an_object_having_attributes(name: 'os.distro.release', value: fact_value),
an_object_having_attributes(name: 'lsbdistrelease', value: fact_value['full'], type: :legacy),
an_object_having_attributes(name: 'lsbmajdistrelease', value: fact_value['major'],
type: :legacy),
an_object_having_attributes(name: 'lsbminordistrelease', value: fact_value['minor'],
type: :legacy))
end
end

Expand All @@ -31,7 +36,10 @@
let(:os_release_value) { nil }
let(:fact_value) { nil }

it_behaves_like 'returns distro release fact'
it 'returns release fact' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'os.distro.release', value: fact_value)
end
end

context 'when version has no minor' do
Expand Down

0 comments on commit 7863203

Please sign in to comment.