Skip to content

Commit 2c8483e

Browse files
committed
RUBY-900 Test not adding servers to the cluster with Single topology
1 parent 56ae9ba commit 2c8483e

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

spec/mongo/cluster/topology_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
it 'returns a single topology' do
2525
expect(topology).to be_a(Mongo::Cluster::Topology::Single)
2626
end
27+
28+
it 'sets the seed on the topology' do
29+
expect(topology.seed).to eq('a')
30+
end
2731
end
2832

2933
context 'when provided a sharded option' do

spec/mongo/cluster_spec.rb

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
describe Mongo::Cluster do
44

5-
describe '#==' do
5+
let(:cluster) do
6+
described_class.new(ADDRESSES)
7+
end
68

7-
let(:cluster) do
8-
described_class.new([ '127.0.0.1:27017' ])
9-
end
9+
describe '#==' do
1010

1111
context 'when the other is a cluster' do
1212

@@ -61,10 +61,6 @@
6161
Mongo::ServerSelector.get
6262
end
6363

64-
let(:cluster) do
65-
described_class.new([ '127.0.0.1:27017' ])
66-
end
67-
6864
it 'displays the cluster seeds and topology' do
6965
expect(cluster.inspect).to include('topology')
7066
expect(cluster.inspect).to include('servers')
@@ -78,13 +74,13 @@
7874
end
7975

8076
let(:cluster) do
81-
described_class.new([ '127.0.0.1:27017' ], :replica_set => 'testing')
77+
described_class.new(ADDRESSES, :replica_set => 'testing')
8278
end
8379

8480
context 'when the option is provided' do
8581

8682
let(:cluster) do
87-
described_class.new([ '127.0.0.1:27017' ], :replica_set => 'testing')
83+
described_class.new(ADDRESSES, :replica_set => 'testing')
8884
end
8985

9086
it 'returns the name' do
@@ -95,7 +91,7 @@
9591
context 'when the option is not provided' do
9692

9793
let(:cluster) do
98-
described_class.new([ '127.0.0.1:27017' ])
94+
described_class.new(ADDRESSES)
9995
end
10096

10197
it 'returns nil' do
@@ -110,10 +106,6 @@
110106
Mongo::ServerSelector.get
111107
end
112108

113-
let(:cluster) do
114-
described_class.new([ '127.0.0.1:27017' ])
115-
end
116-
117109
let(:known_servers) do
118110
cluster.instance_variable_get(:@servers)
119111
end
@@ -131,10 +123,6 @@
131123

132124
context 'when topology is single', if: single_seed? do
133125

134-
let(:cluster) do
135-
described_class.new(ADDRESSES)
136-
end
137-
138126
context 'when the server is a mongos', if: single_mongos? do
139127

140128
it 'returns the mongos' do
@@ -152,10 +140,6 @@
152140

153141
context 'when the cluster has no servers' do
154142

155-
let(:cluster) do
156-
described_class.new(ADDRESSES)
157-
end
158-
159143
let(:servers) do
160144
[nil]
161145
end
@@ -210,4 +194,22 @@
210194
end
211195
end
212196
end
197+
198+
describe '#add' do
199+
200+
context 'when topology is Single' do
201+
202+
let(:topology) do
203+
Mongo::Cluster::Topology::Single.new({})
204+
end
205+
206+
before do
207+
cluster.add('a')
208+
end
209+
210+
it 'does not add discovered servers to the cluster' do
211+
expect(cluster.servers[0].address.seed).to_not eq('a')
212+
end
213+
end
214+
end
213215
end

0 commit comments

Comments
 (0)