3 RSpec.configure do |config|
4 config.mock_with :rspec
7 describe Facter::Util::Fact do
8 before { Facter.clear }
10 describe 'rabbitmq_nodename' do
11 context 'with value' do
13 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
14 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit1 ...' }
17 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit1')
21 context 'with dashes in hostname' do
23 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
24 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit-1 ...' }
27 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
31 context 'with dashes in nodename/hostname' do
33 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
34 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty-python@rabbit-1 ...' }
37 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty-python@rabbit-1')
41 context 'with quotes around node name' do
43 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
44 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node \'monty@rabbit-1\' ...' }
47 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
51 context 'without trailing points' do
53 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
54 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit-1' }
57 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
61 context 'rabbitmq is not running' do
64 Status of node 'monty@rabbit-1' ...
65 Error: unable to connect to node 'monty@rabbit-1': nodedown
70 attempted to contact: ['monty@rabbit-1']
73 * connected to epmd (port 4369) on centos-7-x64
74 * epmd reports: node 'rabbit' not running at all
75 no other nodes on centos-7-x64
76 * suggestion: start the node
79 - node name: 'rabbitmq-cli-73@centos-7-x64'
80 - home dir: /var/lib/rabbitmq
81 - cookie hash: 6WdP0nl6d3HYqA5vTKMkIg==
84 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
85 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { error_string }
88 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
92 context 'rabbitmqctl is not in path' do
94 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { false }
97 expect(Facter.fact(:rabbitmq_nodename).value).to be_nil