Skip to content

Commit

Permalink
Add proxysql_version fact
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjfisher committed May 18, 2019
1 parent 747421d commit 9da4477
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/facter/proxysql_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Facter.add(:proxysql_version) do
confine kernel: 'Linux'
setcode do
if Facter::Util::Resolution.which('proxysql')
proxysql_version = Facter::Util::Resolution.exec('proxysql --version 2>&1')
%r{ProxySQL version (\d+\.\d+\.\d+.*),}.match(proxysql_version)[1]
end
end
end
17 changes: 17 additions & 0 deletions spec/unit/facter/proxysql_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe Facter::Util::Fact.to_s do
before do
Facter.clear
end

describe 'proxysql_version' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('proxysql').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('proxysql --version 2>&1').and_return('ProxySQL version 2.0.4-116-g7d371cf2, codename Truls')
end
it {
expect(Facter.fact(:proxysql_version).value).to eq('2.0.4-116-g7d371cf2')
}
end
end

0 comments on commit 9da4477

Please sign in to comment.