Skip to content

Commit 7fdf4a5

Browse files
authored
Merge pull request #416 from rwaffen/update_fact
Extend fact to not fail on debian packages
2 parents d161fc1 + a535c4d commit 7fdf4a5

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

lib/facter/puppetdb_version.rb

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
setcode do
55
output = Facter::Core::Execution.execute('puppetdb --version')
66
output.split(':').last.strip
7+
rescue Facter::Core::Execution::ExecutionFailure
8+
nil
79
end
810
end
+26-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
# frozen_string_literal: true
2-
3-
require 'spec_helper'
41
require 'facter'
52

63
describe 'puppetdb_version' do
7-
subject(:fact) { Facter.fact(:puppetdb_version) }
8-
94
before(:each) do
105
Facter.clear
116
end
127

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")
8+
context 'when puppetdb is available' do
9+
before(:each) do
10+
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb')
11+
end
12+
13+
context 'on a default system' do
14+
it 'returns the correct version from puppetdb --version' do
15+
expect(Facter::Core::Execution).to receive(:execute)
16+
.with('puppetdb --version')
17+
.and_return('puppetdb version: 7.19.0')
18+
19+
expect(Facter.fact(:puppetdb_version).value).to eq('7.19.0')
20+
end
21+
22+
it 'returns nil if the command execution fails' do
23+
allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_raise(Facter::Core::Execution::ExecutionFailure)
1624

17-
expect(Facter.fact(:puppetdb_version).value).to eq('7.18.0')
25+
expect(Facter.fact(:puppetdb_version).value).to be_nil
26+
end
27+
end
1828
end
1929

20-
it 'returns nil if puppetdb command is not available' do
21-
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil)
30+
context 'when puppetdb is not available' do
31+
before(:each) do
32+
allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil)
33+
end
2234

23-
expect(Facter.fact(:puppetdb_version).value).to be_nil
35+
it 'returns nil' do
36+
expect(Facter.fact(:puppetdb_version).value).to be_nil
37+
end
2438
end
2539
end

0 commit comments

Comments
 (0)