(maint) - Add a fact for capturing the mysql version installed

- Add spec test for mysql_version fact
- Add `mysql_version` fact to README
This commit is contained in:
Travis Fields 2015-05-07 13:29:16 -07:00
parent dd129d5e52
commit 3ce8ad3799
3 changed files with 33 additions and 1 deletions

View file

@ -784,7 +784,11 @@ The library file name.
###Facts
####`mysql_server_id`
#### `mysql_version`
Determines the MySql version by parsing the output from `mysql --version`
#### `mysql_server_id`
Generates a unique id, based on the node's MAC address, which can be used as
`server_id`. This fact will *always* return `0` on all nodes which only have

View file

@ -0,0 +1,8 @@
Facter.add("mysql_version") do
setcode do
mysql_ver = Facter::Util::Resolution.exec('mysql --version')
if mysql_ver
mysql_ver.match(/\d+\.\d+\.\d+/)[0]
end
end
end

View file

@ -0,0 +1,20 @@
require "spec_helper"
describe Facter::Util::Fact do
before {
Facter.clear
}
describe "mysql_version" do
context 'with value' do
before :each do
Facter::Util::Resolution.stubs(:exec).with('mysql --version').returns('mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1')
end
it {
expect(Facter.fact(:mysql_version).value).to eq('5.0.95')
}
end
end
end