File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ Facter . add ( 'postgres_version' ) do
4
+ confine { Facter ::Core ::Execution . which ( 'postgres' ) }
5
+ setcode do
6
+ version = Facter ::Core ::Execution . execute ( 'postgres -V 2>/dev/null' )
7
+ version . match ( %r{\d +\. \d +$} ) [ 0 ] if version
8
+ end
9
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Facter ::Util ::Fact . to_s do
4
+ before ( :each ) do
5
+ Facter . clear
6
+ end
7
+
8
+ describe 'postgres_version' do
9
+ context 'with value' do
10
+ before :each do
11
+ allow ( Facter ::Core ::Execution ) . to receive ( :which ) . and_return ( '/usr/bin/postgres' )
12
+ allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( 'postgres -V 2>/dev/null' ) . and_return ( 'postgres (PostgreSQL) 10.0' )
13
+ end
14
+
15
+ it 'postgres_version' do
16
+ expect ( Facter . fact ( :postgres_version ) . value ) . to eq ( '10.0' )
17
+ end
18
+ end
19
+ end
20
+ end
You can’t perform that action at this time.
0 commit comments