Skip to content

Commit

Permalink
Merge pull request #778 from vrtdev/feature/plugins_fact
Browse files Browse the repository at this point in the history
Add a custom fact for rabbitmq's plugins folder.
  • Loading branch information
wyardley authored Feb 14, 2019
2 parents 5283ed8 + 902d9b4 commit fc76d78
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/facter/rabbitmq_plugins_dirs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Facter.add(:rabbitmq_plugins_dirs) do
setcode do
if Facter::Util::Resolution.which('rabbitmqctl')
rabbitmq_pluginsdirs_env = Facter::Core::Execution.execute("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'")
rabbitmq_plugins_dirs = %r{^\{ok\,\"(\/.+\/\w+)}.match(rabbitmq_pluginsdirs_env)[1]
rabbitmq_plugins_dirs.split(':')
end
end
end
39 changes: 39 additions & 0 deletions spec/unit/facter/util/fact_rabbitmq_plugins_dirs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'spec_helper'

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

describe 'rabbitmq_plugins_dirs' do
context 'with multiple plugins dirs' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'").returns('{ok,"/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/plugins"}')
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to match_array(
[
'/usr/lib/rabbitmq/plugins',
'/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/plugins'
]
)
end
end

context 'with only 1 plugins dir' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'").returns('{ok,"/usr/lib/rabbitmq/lib/rabbitmq_server-0.0.0/plugins"}')
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to match_array(
[
'/usr/lib/rabbitmq/lib/rabbitmq_server-0.0.0/plugins'
]
)
end
end

context 'rabbitmqctl is not in path' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(false)
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to be_nil
end
end
end
end

0 comments on commit fc76d78

Please sign in to comment.