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

Ensure version fact does not throw an error for invalid match #705

Merged
merged 2 commits into from
Jun 25, 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
2 changes: 1 addition & 1 deletion lib/facter/rabbitmq_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
setcode do
if Facter::Util::Resolution.which('rabbitmqadmin')
rabbitmq_version = Facter::Core::Execution.execute('rabbitmqadmin --version 2>&1')
%r{^rabbitmqadmin ([\w\.]+)}.match(rabbitmq_version)[1]
%r{^rabbitmqadmin ([\w\.]+)}.match(rabbitmq_version).to_a[1]
end
end
end
9 changes: 9 additions & 0 deletions spec/unit/facter/util/fact_rabbitmq_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
expect(Facter.fact(:rabbitmq_version).value).to eq('3.6.0')
end
end
context 'with invalid value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqadmin') { true }
allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqadmin --version 2>&1') { 'rabbitmqadmin %%VSN%%' }
end
it do
expect(Facter.fact(:rabbitmq_version).value).to be_nil
end
end
context 'rabbitmqadmin is not in path' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqadmin') { false }
Expand Down