|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe Facts::Azurelinux::Os::Release do |
| 4 | + describe '#call_the_resolver' do |
| 5 | + subject(:fact) { Facts::Azurelinux::Os::Release.new } |
| 6 | + |
| 7 | + before do |
| 8 | + allow(Facter::Resolvers::SpecificReleaseFile).to receive(:resolve) |
| 9 | + .with(:release, { release_file: '/etc/azurelinux-release', |
| 10 | + regex: /AZURELINUX_BUILD_NUMBER=([0-9.]+)/ }) |
| 11 | + .and_return(value) |
| 12 | + end |
| 13 | + |
| 14 | + context 'when version is retrieved from specific file' do |
| 15 | + let(:value) { /AZURELINUX_BUILD_NUMBER=([0-9.]+)/.match('AZURELINUX_BUILD_NUMBER=3.0.20240401') } |
| 16 | + let(:release) { { 'full' => '3.0.20240401', 'major' => '3', 'minor' => '0' } } |
| 17 | + |
| 18 | + it 'returns operating system name fact' do |
| 19 | + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ |
| 20 | + contain_exactly(an_object_having_attributes(name: 'os.release', value: release), |
| 21 | + an_object_having_attributes(name: 'operatingsystemmajrelease', |
| 22 | + value: release['major'], type: :legacy), |
| 23 | + an_object_having_attributes(name: 'operatingsystemrelease', |
| 24 | + value: release['full'], type: :legacy)) |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + context 'when version is retrieved from os-release file' do |
| 29 | + let(:value) { nil } |
| 30 | + let(:os_release) { '3.0.20240401' } |
| 31 | + let(:release) { { 'full' => '3.0.20240401', 'major' => '3', 'minor' => '0' } } |
| 32 | + |
| 33 | + before do |
| 34 | + allow(Facter::Resolvers::OsRelease).to receive(:resolve).with(:version_id).and_return(os_release) |
| 35 | + end |
| 36 | + |
| 37 | + it 'returns operating system name fact' do |
| 38 | + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ |
| 39 | + contain_exactly(an_object_having_attributes(name: 'os.release', value: release), |
| 40 | + an_object_having_attributes(name: 'operatingsystemmajrelease', |
| 41 | + value: release['major'], type: :legacy), |
| 42 | + an_object_having_attributes(name: 'operatingsystemrelease', |
| 43 | + value: release['full'], type: :legacy)) |
| 44 | + end |
| 45 | + |
| 46 | + context 'when release can\'t be received' do |
| 47 | + let(:os_release) { nil } |
| 48 | + |
| 49 | + it 'returns operating system name fact' do |
| 50 | + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ |
| 51 | + have_attributes(name: 'os.release', value: nil) |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | +end |
0 commit comments