|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Facter::Util::Fact do |
| 4 | + before do |
| 5 | + Facter.clear |
| 6 | + end |
| 7 | + |
| 8 | + describe 'rabbitmq_clusternam' do |
| 9 | + context 'with value' do |
| 10 | + it do |
| 11 | + Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true) |
| 12 | + Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns(' {cluster_name,<<"monty">>},') |
| 13 | + expect(Facter.fact(:rabbitmq_clustername).value).to eq('monty') |
| 14 | + end |
| 15 | + end |
| 16 | + |
| 17 | + context 'with dashes in hostname' do |
| 18 | + it do |
| 19 | + Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true) |
| 20 | + Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns('Cluster name: rabbit-1') |
| 21 | + expect(Facter.fact(:rabbitmq_clustername).value).to eq('rabbit-1') |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + context 'with dashes in clustername/hostname' do |
| 26 | + it do |
| 27 | + Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true) |
| 28 | + Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns(' {cluster_name,<<"monty-python@rabbit-1">>},') |
| 29 | + expect(Facter.fact(:rabbitmq_clustername).value).to eq('monty-python@rabbit-1') |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context 'with quotes around node name' do |
| 34 | + it do |
| 35 | + Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true) |
| 36 | + Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns("monty\npython\nCluster name: 'monty@rabbit-1'\nend\nof\nfile") |
| 37 | + expect(Facter.fact(:rabbitmq_clustername).value).to eq("'monty@rabbit-1'") |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + context 'rabbitmq is not running' do |
| 42 | + it do |
| 43 | + error_string = <<-EOS |
| 44 | +Status of node 'monty@rabbit-1' ... |
| 45 | +Error: unable to connect to node 'monty@rabbit-1': nodedown |
| 46 | +
|
| 47 | +DIAGNOSTICS |
| 48 | +=========== |
| 49 | +
|
| 50 | +attempted to contact: ['monty@rabbit-1'] |
| 51 | +
|
| 52 | +monty@rabbit-1: |
| 53 | + * connected to epmd (port 4369) on centos-7-x64 |
| 54 | + * epmd reports: node 'rabbit' not running at all |
| 55 | + no other nodes on centos-7-x64 |
| 56 | + * suggestion: start the node |
| 57 | +
|
| 58 | +current node details: |
| 59 | +- node name: 'rabbitmq-cli-73@centos-7-x64' |
| 60 | +- home dir: /var/lib/rabbitmq |
| 61 | +- cookie hash: 6WdP0nl6d3HYqA5vTKMkIg== |
| 62 | +
|
| 63 | + EOS |
| 64 | + Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true) |
| 65 | + Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns(error_string) |
| 66 | + expect(Facter.fact(:rabbitmq_clustername).value).to be_nil |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + context 'rabbitmqctl is not in path' do |
| 71 | + it do |
| 72 | + Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(false) |
| 73 | + expect(Facter.fact(:rabbitmq_clustername).value).to be_nil |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | +end |
0 commit comments