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

Add a custom fact for rabbitmq's plugins folder. #778

Merged
merged 1 commit into from
Feb 14, 2019
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
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