Skip to content

Commit ccf1337

Browse files
committed
Add a fact for installed postgres version
There is sometimes a need to handle versions differently. This fact provides a basis for writing such code.
1 parent 0c66889 commit ccf1337

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/facter/postgres_version.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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

0 commit comments

Comments
 (0)