f0ed3927221e06d3e14c62797b9946634d6902f0
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / spec / unit / facter / util / fact_rabbitmq_nodename_spec.rb
1 require 'spec_helper'
2
3 describe Facter::Util::Fact do
4   before { Facter.clear }
5
6   describe 'rabbitmq_nodename' do
7     context 'with value' do
8       before 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 ...' }
11       end
12       it do
13         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit1')
14       end
15     end
16
17     context 'with dashes in hostname' do
18       before 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 ...' }
21       end
22       it do
23         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
24       end
25     end
26
27     context 'with dashes in nodename/hostname' do
28       before 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 ...' }
31       end
32       it do
33         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty-python@rabbit-1')
34       end
35     end
36
37     context 'with quotes around node name' do
38       before 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\' ...' }
41       end
42       it do
43         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
44       end
45     end
46
47     context 'without trailing points' do
48       before 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' }
51       end
52       it do
53         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
54       end
55     end
56
57     context 'rabbitmq is not running' do
58       before do
59         error_string = <<-EOS
60 Status of node 'monty@rabbit-1' ...
61 Error: unable to connect to node 'monty@rabbit-1': nodedown
62
63 DIAGNOSTICS
64 ===========
65
66 attempted to contact: ['monty@rabbit-1']
67
68 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
73
74 current node details:
75 - node name: 'rabbitmq-cli-73@centos-7-x64'
76 - home dir: /var/lib/rabbitmq
77 - cookie hash: 6WdP0nl6d3HYqA5vTKMkIg==
78
79         EOS
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 }
82       end
83       it do
84         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
85       end
86     end
87
88     context 'rabbitmqctl is not in path' do
89       before do
90         allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { false }
91       end
92       it do
93         expect(Facter.fact(:rabbitmq_nodename).value).to be_nil
94       end
95     end
96   end
97 end