Merge pull request #753 from jyaworski/add_nginx_version_fact
Add nginx_version fact
This commit is contained in:
commit
f544dfec0a
2 changed files with 27 additions and 0 deletions
8
lib/facter/nginx_version.rb
Normal file
8
lib/facter/nginx_version.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Facter.add(:nginx_version) do
|
||||||
|
setcode do
|
||||||
|
if Facter::Core::Execution.which('nginx')
|
||||||
|
nginx_version = Facter::Core::Execution.execute('nginx -v 2>&1')
|
||||||
|
%r{^nginx version: nginx\/([\w\.]+)}.match(nginx_version)[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
19
spec/unit/nginx_version_spec.rb
Normal file
19
spec/unit/nginx_version_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe Facter::Util::Fact do
|
||||||
|
before {
|
||||||
|
Facter.clear
|
||||||
|
}
|
||||||
|
|
||||||
|
describe "nginx_version" do
|
||||||
|
context 'with value' do
|
||||||
|
before :each do
|
||||||
|
Facter::Core::Execution.stubs(:which).with('nginx').returns(true)
|
||||||
|
Facter::Core::Execution.stubs(:execute).with('nginx -v 2>&1').returns('nginx version: nginx/1.8.1')
|
||||||
|
end
|
||||||
|
it {
|
||||||
|
expect(Facter.fact(:nginx_version).value).to eq('1.8.1')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue