-
Notifications
You must be signed in to change notification settings - Fork 237
Add a puppetdb_version
fact with PuppetDB version
#404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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 |
Uh oh!
There was an error while loading. Please reload this page.