Skip to content

Commit

Permalink
(FACT-2699) Detect augeas from gem if augparse is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanIrimie committed Jul 28, 2020
1 parent 03c1223 commit 9e9e76c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/facter/resolvers/augeas_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def read_augeas_from_cli
def read_augeas_from_gem
require 'augeas'

return ::Augeas.create { |aug| aug.get('/augeas/version') } if ::Augeas.respond_to?(:create)
return ::Augeas.create { |aug| aug.get('/augeas/version') } if ::Augeas.singleton_method(:create)

# it is used for legacy augeas <= 0.5.0
return ::Augeas.open { |aug| aug.get('/augeas/version') } if ::Augeas.respond_to?(:open)
::Augeas.open { |aug| aug.get('/augeas/version') }
rescue StandardError => e
log.debug('ruby-augeas not available')
log.debug('coudl not read version from ruby-augeas')
log.log_exception(e)
nil
end
Expand Down
13 changes: 3 additions & 10 deletions spec/facter/resolvers/augeas_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

before do
augeas.instance_variable_set(:@log, log_spy)
allow(Facter::Resolvers::Augeas).to receive(:require).with('augeas')
end

after do
Expand All @@ -33,11 +34,7 @@
end

context 'when augeas gem > 0.5.0 is installed' do
let(:augeas_mock) { instance_spy(Augeas) }

before do
allow(Augeas).to receive(:respond_to?).with(:create).and_return(true)
allow(Augeas).to receive(:respond_to?).with(:create, true).and_return(true)
allow(Augeas).to receive(:create).and_return('1.12.0')
end

Expand All @@ -47,12 +44,8 @@
end

context 'when augeas gem <= 0.5.0 is installed' do
let(:augeas_mock) { instance_spy(Augeas) }

before do
allow(Augeas).to receive(:respond_to?).with(:create).and_return(false)
allow(Augeas).to receive(:respond_to?).with(:open).and_return(true)
allow(Augeas).to receive(:respond_to?).with(:open, true).and_return(true)
allow(Augeas).to receive(:singleton_method).with(:create).and_return(false)
allow(Augeas).to receive(:open).and_return('1.12.0')
end

Expand All @@ -75,7 +68,7 @@
it 'logs a debug message' do
augeas.resolve(:augeas_version)

expect(log_spy).to have_received(:debug).with('ruby-augeas not available')
expect(log_spy).to have_received(:debug).with('coudl not read version from ruby-augeas')
end

it 'logs an exception' do
Expand Down

0 comments on commit 9e9e76c

Please sign in to comment.