|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Mongo::Cluster::Topology::Unknown do |
| 4 | + |
| 5 | + let(:topology) do |
| 6 | + described_class.new({}) |
| 7 | + end |
| 8 | + |
| 9 | + describe '.servers' do |
| 10 | + |
| 11 | + let(:servers) do |
| 12 | + topology.servers([ double('mongos'), double('standalone') ]) |
| 13 | + end |
| 14 | + |
| 15 | + it 'returns an empty array' do |
| 16 | + expect(servers).to eq([ ]) |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + describe '.replica_set?' do |
| 21 | + |
| 22 | + it 'returns false' do |
| 23 | + expect(topology).to_not be_replica_set |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + describe '.sharded?' do |
| 28 | + |
| 29 | + it 'returns false' do |
| 30 | + expect(topology).not_to be_sharded |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + describe '.single?' do |
| 35 | + |
| 36 | + it 'returns false' do |
| 37 | + expect(topology).not_to be_single |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + describe '.unknown?' do |
| 42 | + |
| 43 | + it 'returns true' do |
| 44 | + expect(topology.unknown?).to be(true) |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + describe '#add_hosts?' do |
| 49 | + |
| 50 | + context 'when the description is from an unknown server' do |
| 51 | + |
| 52 | + let(:description) do |
| 53 | + double('description').tap do |d| |
| 54 | + allow(d).to receive(:unknown?).and_return(true) |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + it 'returns false' do |
| 59 | + expect(topology.add_hosts?(description, [])).to be(false) |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + context 'when the description is from a ghost server' do |
| 64 | + |
| 65 | + let(:description) do |
| 66 | + double('description').tap do |d| |
| 67 | + allow(d).to receive(:unknown?).and_return(false) |
| 68 | + allow(d).to receive(:ghost?).and_return(true) |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + it 'returns false' do |
| 73 | + expect(topology.add_hosts?(description, [])).to be(false) |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + context 'when the description is not from an unknown or ghost' do |
| 78 | + |
| 79 | + let(:description) do |
| 80 | + double('description').tap do |d| |
| 81 | + allow(d).to receive(:unknown?).and_return(false) |
| 82 | + allow(d).to receive(:ghost?).and_return(false) |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + it 'returns true' do |
| 87 | + expect(topology.add_hosts?(description, [])).to be(true) |
| 88 | + end |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + describe '#remove_hosts?' do |
| 93 | + |
| 94 | + context 'when the description is from a standalone' do |
| 95 | + |
| 96 | + let(:description) do |
| 97 | + double('description').tap do |d| |
| 98 | + allow(d).to receive(:standalone?).and_return(true) |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + it 'returns true' do |
| 103 | + expect(topology.remove_hosts?(description)).to be(true) |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + context 'when the description is not from a standalone' do |
| 108 | + |
| 109 | + let(:description) do |
| 110 | + double('description').tap do |d| |
| 111 | + allow(d).to receive(:standalone?).and_return(false) |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + it 'returns true' do |
| 116 | + expect(topology.remove_hosts?(description)).to be(false) |
| 117 | + end |
| 118 | + end |
| 119 | + end |
| 120 | + |
| 121 | + describe '#remove_server?' do |
| 122 | + |
| 123 | + context 'when the description is from a standalone' do |
| 124 | + |
| 125 | + let(:description) do |
| 126 | + double('description').tap do |d| |
| 127 | + allow(d).to receive(:standalone?).and_return(true) |
| 128 | + allow(d).to receive(:is_server?).and_return(true) |
| 129 | + end |
| 130 | + end |
| 131 | + |
| 132 | + context 'when the description is from the server in question' do |
| 133 | + |
| 134 | + it 'returns true' do |
| 135 | + expect(topology.remove_server?(description, double('server'))).to be(true) |
| 136 | + end |
| 137 | + end |
| 138 | + |
| 139 | + context 'when the description is not from the server in question' do |
| 140 | + |
| 141 | + let(:description) do |
| 142 | + double('description').tap do |d| |
| 143 | + allow(d).to receive(:standalone?).and_return(true) |
| 144 | + allow(d).to receive(:is_server?).and_return(false) |
| 145 | + end |
| 146 | + end |
| 147 | + |
| 148 | + it 'returns false' do |
| 149 | + expect(topology.remove_server?(description, double('server'))).to be(false) |
| 150 | + end |
| 151 | + end |
| 152 | + end |
| 153 | + |
| 154 | + context 'when the description is not from a standalone' do |
| 155 | + |
| 156 | + let(:description) do |
| 157 | + double('description').tap do |d| |
| 158 | + allow(d).to receive(:standalone?).and_return(false) |
| 159 | + end |
| 160 | + end |
| 161 | + |
| 162 | + it 'returns false' do |
| 163 | + expect(topology.remove_server?(description, double('server'))).to be(false) |
| 164 | + end |
| 165 | + end |
| 166 | + end |
| 167 | +end |
0 commit comments