Skip to content

Commit 3afd693

Browse files
authored
Merge pull request #404 from rwaffen/add_version_fact
Add a `puppetdb_version` fact with PuppetDB version
2 parents 99cbeea + d2db654 commit 3afd693

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/facter/puppetdb_version.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Facter.add(:puppetdb_version) do
2+
confine { Facter::Util::Resolution.which('puppetdb') }
3+
4+
setcode do
5+
output = Facter::Core::Execution.execute('puppetdb --version')
6+
output.split(':').last.strip
7+
end
8+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'facter'
5+
6+
describe 'puppetdb_version' do
7+
subject(:fact) { Facter.fact(:puppetdb_version) }
8+
9+
before(:each) do
10+
Facter.clear
11+
end
12+
13+
it 'returns the correct puppetdb version' do
14+
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb')
15+
allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_return("puppetdb version: 7.18.0\n")
16+
17+
expect(Facter.fact(:puppetdb_version).value).to eq('7.18.0')
18+
end
19+
20+
it 'returns nil if puppetdb command is not available' do
21+
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil)
22+
23+
expect(Facter.fact(:puppetdb_version).value).to be_nil
24+
end
25+
end

0 commit comments

Comments
 (0)