-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
The code changes add a new Facter fact called `puppetdb_version` that retrieves the version of PuppetDB installed on the system. It uses the `puppetdb --version` command to fetch the version and returns it as a fact value.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Facter.add(:puppetdb_version) do | ||
confine { Facter::Util::Resolution.which('puppetdb') } | ||
|
||
setcode do | ||
output = Facter::Core::Execution.execute('puppetdb --version') | ||
|
||
if output.nil? | ||
nil | ||
else | ||
output.split(':').last.strip | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'facter' | ||
|
||
describe 'puppetdb_version' do | ||
subject(:fact) { Facter.fact(:puppetdb_version) } | ||
|
||
before(:each) do | ||
Facter.clear | ||
end | ||
|
||
it 'should return the correct puppetdb version' do | ||
Check failure on line 13 in spec/unit/facter/puppetdb_version_spec.rb
|
||
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb') | ||
allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_return("puppetdb version: 7.18.0\n") | ||
|
||
expect(Facter.fact(:puppetdb_version).value).to eq('7.18.0') | ||
end | ||
|
||
it 'should return nil if puppetdb command is not available' do | ||
Check failure on line 20 in spec/unit/facter/puppetdb_version_spec.rb
|
||
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil) | ||
|
||
expect(Facter.fact(:puppetdb_version).value).to be_nil | ||
end | ||
|
||
it 'should return nil if puppetdb version output is nil' do | ||
Check failure on line 26 in spec/unit/facter/puppetdb_version_spec.rb
|
||
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb') | ||
allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_return(nil) | ||
|
||
expect(Facter.fact(:puppetdb_version).value).to be_nil | ||
end | ||
end |