X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Frabbitmq%2Fspec%2Funit%2Ffacter%2Futil%2Ffact_rabbitmq_nodename_spec.rb;fp=3rdparty%2Fmodules%2Frabbitmq%2Fspec%2Funit%2Ffacter%2Futil%2Ffact_rabbitmq_nodename_spec.rb;h=869cf7af9d8fc72e8ebe8d965d215ce543ed4c40;hb=94a8783f522bbf2996cb8a59b977dea583e8b0c7;hp=0000000000000000000000000000000000000000;hpb=e107504bce7d9b21cc301124fc7c39fdb0762374;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/rabbitmq/spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb b/3rdparty/modules/rabbitmq/spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb new file mode 100644 index 000000000..869cf7af9 --- /dev/null +++ b/3rdparty/modules/rabbitmq/spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb @@ -0,0 +1,101 @@ +require 'spec_helper' + +RSpec.configure do |config| + config.mock_with :rspec +end + +describe Facter::Util::Fact do + before { Facter.clear } + + describe 'rabbitmq_nodename' do + context 'with value' do + before do + allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true } + allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit1 ...' } + end + it do + expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit1') + end + end + + context 'with dashes in hostname' do + before do + allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true } + allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit-1 ...' } + end + it do + expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1') + end + end + + context 'with dashes in nodename/hostname' do + before do + allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true } + allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty-python@rabbit-1 ...' } + end + it do + expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty-python@rabbit-1') + end + end + + context 'with quotes around node name' do + before do + allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true } + allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node \'monty@rabbit-1\' ...' } + end + it do + expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1') + end + end + + context 'without trailing points' do + before do + allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true } + allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit-1' } + end + it do + expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1') + end + end + + context 'rabbitmq is not running' do + before do + error_string = <<-EOS +Status of node 'monty@rabbit-1' ... +Error: unable to connect to node 'monty@rabbit-1': nodedown + +DIAGNOSTICS +=========== + +attempted to contact: ['monty@rabbit-1'] + +monty@rabbit-1: + * connected to epmd (port 4369) on centos-7-x64 + * epmd reports: node 'rabbit' not running at all + no other nodes on centos-7-x64 + * suggestion: start the node + +current node details: +- node name: 'rabbitmq-cli-73@centos-7-x64' +- home dir: /var/lib/rabbitmq +- cookie hash: 6WdP0nl6d3HYqA5vTKMkIg== + + EOS + allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true } + allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { error_string } + end + it do + expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1') + end + end + + context 'rabbitmqctl is not in path' do + before do + allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { false } + end + it do + expect(Facter.fact(:rabbitmq_nodename).value).to be_nil + end + end + end +end