Skip to content

Commit e24e65d

Browse files
authored
Merge pull request #2063 from puppetlabs/FACT-2777
(FACT-2777) Fix lsbdist facts on ubuntu
2 parents 4d0541a + 5291c57 commit e24e65d

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module Facts
4+
module Ubuntu
5+
class Lsbdistrelease
6+
FACT_NAME = 'lsbdistrelease'
7+
ALIASES = %w[lsbmajdistrelease lsbminordistrelease].freeze
8+
TYPE = :legacy
9+
10+
def call_the_resolver
11+
fact_value = Facter::Resolvers::LsbRelease.resolve(:release)
12+
13+
return Facter::ResolvedFact.new(FACT_NAME, nil, :legacy) unless fact_value
14+
15+
version = fact_value.split('.')
16+
17+
[Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy),
18+
Facter::ResolvedFact.new(ALIASES[0], version[0], :legacy),
19+
Facter::ResolvedFact.new(ALIASES[1], version[1], :legacy)]
20+
end
21+
end
22+
end
23+
end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# frozen_string_literal: true
2+
3+
describe Facts::Ubuntu::Lsbdistrelease do
4+
describe '#call_the_resolver' do
5+
subject(:fact) { Facts::Ubuntu::Lsbdistrelease.new }
6+
7+
context 'when lsb-release is installed' do
8+
before do
9+
allow(Facter::Resolvers::LsbRelease).to receive(:resolve).with(:release).and_return(value)
10+
end
11+
12+
context 'when version_id is retrieved successful' do
13+
let(:value) { '18.04' }
14+
let(:value_final) { { 'full' => '18.04', 'major' => '18', 'minor' => '04' } }
15+
16+
it 'calls Facter::Resolvers::LsbRelease with :name' do
17+
fact.call_the_resolver
18+
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:release)
19+
end
20+
21+
it 'returns release fact' do
22+
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \
23+
contain_exactly(an_object_having_attributes(name: 'lsbdistrelease', value: value, type: :legacy),
24+
an_object_having_attributes(name: 'lsbmajdistrelease',
25+
value: value_final['major'], type: :legacy),
26+
an_object_having_attributes(name: 'lsbminordistrelease',
27+
value: value_final['minor'], type: :legacy))
28+
end
29+
end
30+
31+
context 'when Debian 10' do
32+
let(:value) { '10' }
33+
let(:value_final) { { 'full' => '10', 'major' => '10', 'minor' => nil } }
34+
35+
it 'calls Facter::Resolvers::LsbRelease with :name' do
36+
fact.call_the_resolver
37+
expect(Facter::Resolvers::LsbRelease).to have_received(:resolve).with(:release)
38+
end
39+
40+
it 'returns release fact' do
41+
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \
42+
contain_exactly(an_object_having_attributes(name: 'lsbdistrelease', value: value, type: :legacy),
43+
an_object_having_attributes(name: 'lsbmajdistrelease',
44+
value: value_final['major'], type: :legacy),
45+
an_object_having_attributes(name: 'lsbminordistrelease',
46+
value: value_final['minor'], type: :legacy))
47+
end
48+
end
49+
50+
context 'when lsb-release is not installed' do
51+
let(:value) { nil }
52+
53+
it 'returns release fact as nil' do
54+
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
55+
have_attributes(name: 'lsbdistrelease', value: value, type: :legacy)
56+
end
57+
end
58+
end
59+
end
60+
end

0 commit comments

Comments
 (0)