-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from rwaffen/add_version_fact
Add a `puppetdb_version` fact with PuppetDB version
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Facter.add(:puppetdb_version) do | ||
confine { Facter::Util::Resolution.which('puppetdb') } | ||
|
||
setcode do | ||
output = Facter::Core::Execution.execute('puppetdb --version') | ||
output.split(':').last.strip | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 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 'returns the correct puppetdb version' do | ||
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 'returns nil if puppetdb command is not available' do | ||
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil) | ||
|
||
expect(Facter.fact(:puppetdb_version).value).to be_nil | ||
end | ||
end |