File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments