diff --git a/lib/facter/consul_version.rb b/lib/facter/consul_version.rb new file mode 100644 index 00000000..9dd2b8b2 --- /dev/null +++ b/lib/facter/consul_version.rb @@ -0,0 +1,10 @@ +# consul_version.rb + +Facter.add(:consul_version) do + confine :kernel => 'Linux' + setcode do + version = Facter::Util::Resolution.exec('consul --version 2> /dev/null') + version = version.lines.first.split[1].tr('v','') + version + end +end diff --git a/spec/unit/facter/consul_version_spec.rb b/spec/unit/facter/consul_version_spec.rb new file mode 100644 index 00000000..d6db3497 --- /dev/null +++ b/spec/unit/facter/consul_version_spec.rb @@ -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