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

Fix PR #392 + added rundeck_commitid fact #402

Merged
merged 6 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
AllCops:
Exclude:
- files/**/*
spec/spec_helper.rb:
mock_with: ':rspec'

24 changes: 12 additions & 12 deletions lib/facter/rundeck_version.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Fact: rundeck_version
# Facts: rundeck_version, rundeck_commitid
#
# Purpose: Retrieve rundeck version if installed
# Purpose: Retrieve rundeck version and commitid if installed
#
# Resolution:
#
# Caveats: not well tested
#
Facter.add(:rundeck_version) do
setcode do
if Facter::Util::Resolution.which('rd-acl')
rd_acl_help = Facter::Util::Resolution.exec('rd-acl -h')
%r{^\[RUNDECK version ([\w\.]+) \(([\w]+)\)\]}.match(rd_acl_help)[1]
end

if Facter::Util::Resolution.which('rd-acl')

rd_acl_help = Facter::Util::Resolution.exec('rd-acl -h')
pattern = %r{^\[RUNDECK version (?<rd_ver>[\w\.]+)\-?(?<rd_commitid>[\w]*) \(([\w]+)\)\]}

pattern.match(rd_acl_help) do |m|
Facter.add('rundeck_version') { setcode { m[:rd_ver] } }
Facter.add('rundeck_commitid') { setcode { m[:rd_commitid] } }
end

end
35 changes: 35 additions & 0 deletions spec/facter/fact_rundeck_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

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

context 'no rundeck installed | no rd-acl in path' do
before { allow(Facter::Util::Resolution).to receive('which').with('rd-acl') { false } }
it { expect(Facter.fact('rundeck_version')).to eq(nil) }
it { expect(Facter.fact('rundeck_commitid')).to eq(nil) }
end

context 'rundeck installed | rd-acl in path with current output format' do
before do
allow(Facter::Util::Resolution).to receive('which').with('rd-acl') { true }
allow(Facter::Util::Resolution).to receive('exec').with('rd-acl -h') do
'[RUNDECK version 3.0.6-20180917 (0)]'
end
end

it { expect(Facter.fact('rundeck_version').value).to eq('3.0.6') }
it { expect(Facter.fact('rundeck_commitid').value).to eq('20180917') }
end

context 'rundeck installed | rd-acl in path with old output format' do
before do
allow(Facter::Util::Resolution).to receive('which').with('rd-acl') { true }
allow(Facter::Util::Resolution).to receive('exec').with('rd-acl -h') do
'[RUNDECK version 2.0.0 (0)]'
end
end

it { expect(Facter.fact('rundeck_version').value).to eq('2.0.0') }
it { expect(Facter.fact('rundeck_commitid').value).to eq('') }
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
c.default_facts = default_facts
c.mock_with :rspec
end

# vim: syntax=ruby