Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consul Version Fact #209

Merged
merged 13 commits into from
Feb 2, 2016
10 changes: 10 additions & 0 deletions lib/facter/consul_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# consul_version.rb

Facter.add(:consul_version) do
confine :kernel => 'Linux'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty for using confine

setcode do
version = Facter::Util::Resolution.exec('consul --version 2> /dev/null')
version = version.lines.first.split[1].tr('v','')
version
end
end
24 changes: 24 additions & 0 deletions spec/unit/facter/consul_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "spec_helper"

describe Facter::Util::Fact do
before {
Facter.clear
}

describe "consul_version" do

context 'Returns consul version on Linux'
it do
consul_version_output = <<-EOS
Consul v0.6.0
Consul Protocol: 3 (Understands back to: 1)
EOS
allow(Facter.fact(:kernel)).to receive(:value).and_return("Linux")
allow(Facter::Util::Resolution).to receive(:exec).with('consul --version 2> /dev/null').
and_return(consul_version_output)
expect(Facter.fact(:consul_version).value).to match('0.6.0')
end

end

end