3 describe Facter::Util::Fact do
4 before { Facter.clear }
6 describe 'rabbitmq_nodename' do
7 context 'with value' do
9 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
10 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit1 ...' }
13 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit1')
17 context 'with dashes in hostname' do
19 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
20 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit-1 ...' }
23 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
27 context 'with dashes in nodename/hostname' do
29 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
30 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty-python@rabbit-1 ...' }
33 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty-python@rabbit-1')
37 context 'with quotes around node name' do
39 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
40 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node \'monty@rabbit-1\' ...' }
43 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
47 context 'without trailing points' do
49 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
50 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { 'Status of node monty@rabbit-1' }
53 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
57 context 'rabbitmq is not running' do
60 Status of node 'monty@rabbit-1' ...
61 Error: unable to connect to node 'monty@rabbit-1': nodedown
66 attempted to contact: ['monty@rabbit-1']
69 * connected to epmd (port 4369) on centos-7-x64
70 * epmd reports: node 'rabbit' not running at all
71 no other nodes on centos-7-x64
72 * suggestion: start the node
75 - node name: 'rabbitmq-cli-73@centos-7-x64'
76 - home dir: /var/lib/rabbitmq
77 - cookie hash: 6WdP0nl6d3HYqA5vTKMkIg==
80 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { true }
81 allow(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1') { error_string }
84 expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
88 context 'rabbitmqctl is not in path' do
90 allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { false }
93 expect(Facter.fact(:rabbitmq_nodename).value).to be_nil