Update rabbitmq module
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / spec / unit / facter / util / fact_rabbitmq_nodename_spec.rb
1 require 'spec_helper'
2
3 RSpec.configure do |config|
4   config.mock_with :rspec
5 end
6
7 describe Facter::Util::Fact do
8   before { Facter.clear }
9
10   describe 'rabbitmq_nodename' do
11     context 'with value' do
12       before 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 ...' }
15       end
16       it do
17         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit1')
18       end
19     end
20
21     context 'with dashes in hostname' do
22       before 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 ...' }
25       end
26       it do
27         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
28       end
29     end
30
31     context 'with dashes in nodename/hostname' do
32       before 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 ...' }
35       end
36       it do
37         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty-python@rabbit-1')
38       end
39     end
40
41     context 'with quotes around node name' do
42       before 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\' ...' }
45       end
46       it do
47         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
48       end
49     end
50
51     context 'without trailing points' do
52       before 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' }
55       end
56       it do
57         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
58       end
59     end
60
61     context 'rabbitmq is not running' do
62       before do
63         error_string = <<-EOS
64 Status of node 'monty@rabbit-1' ...
65 Error: unable to connect to node 'monty@rabbit-1': nodedown
66
67 DIAGNOSTICS
68 ===========
69
70 attempted to contact: ['monty@rabbit-1']
71
72 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
77
78 current node details:
79 - node name: 'rabbitmq-cli-73@centos-7-x64'
80 - home dir: /var/lib/rabbitmq
81 - cookie hash: 6WdP0nl6d3HYqA5vTKMkIg==
82
83         EOS
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 }
86       end
87       it do
88         expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
89       end
90     end
91
92     context 'rabbitmqctl is not in path' do
93       before do
94         allow(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl') { false }
95       end
96       it do
97         expect(Facter.fact(:rabbitmq_nodename).value).to be_nil
98       end
99     end
100   end
101 end