1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
require 'spec_helper'
describe Facter::Util::Fact do
before { Facter.clear }
describe 'rabbitmq_nodename' do
context 'with value' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit1 ...')
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit1')
end
end
context 'with dashes in hostname' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit-1 ...')
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
end
end
context 'with dashes in nodename/hostname' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty-python@rabbit-1 ...')
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty-python@rabbit-1')
end
end
context 'with quotes around node name' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node \'monty@rabbit-1\' ...')
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
end
end
context 'without trailing points' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit-1')
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
end
end
context 'rabbitmq is not running' do
it 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
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns(error_string)
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
end
end
context 'rabbitmqctl is not in path' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(false)
expect(Facter.fact(:rabbitmq_nodename).value).to be_nil
end
end
end
end
|