Sha256: 6b0f73505220fbe39ede61b95ae87b859ee54ced6092c934caa68f87b0e96734

Contents?: true

Size: 1.87 KB

Versions: 13

Compression:

Stored size: 1.87 KB

Contents

require 'spec_helper'

describe 'Direct connection with RS name' do
  before(:all) do
    # preload
    ClusterConfig.instance.replica_set_name
  end

  clean_slate_for_all

  shared_examples_for 'passes RS name to topology' do
    it 'passes RS name to topology' do
      expect(client.cluster.topology.replica_set_name).to eq(replica_set_name)
    end
  end

  let(:client) do
    new_local_client(
      [SpecConfig.instance.addresses.first],
      SpecConfig.instance.test_options.merge(
        replica_set: replica_set_name, connect: :direct))
  end

  context 'in replica set' do
    require_topology :replica_set

    context 'with correct RS name' do
      let(:replica_set_name) { ClusterConfig.instance.replica_set_name }

      it_behaves_like 'passes RS name to topology'

      it 'creates a working client' do
        expect do
          client.database.command(ismaster: 1)
        end.not_to raise_error
      end
    end

    context 'with wrong RS name' do
      let(:replica_set_name) { 'wrong' }

      it_behaves_like 'passes RS name to topology'

      it 'creates a client which raises on every operation' do
        expect do
          client.database.command(ismaster: 1)
        end.to raise_error(Mongo::Error::NoServerAvailable, "Cluster topology specifies replica set name wrong, but the server has replica set name #{ClusterConfig.instance.replica_set_name}")
      end
    end
  end

  context 'in standalone' do
    require_topology :single

    context 'with any RS name' do
      let(:replica_set_name) { 'any' }

      it_behaves_like 'passes RS name to topology'

      it 'creates a client which raises on every operation' do
        expect do
          client.database.command(ismaster: 1)
        end.to raise_error(Mongo::Error::NoServerAvailable, 'Cluster topology specifies replica set name any, but the server has replica set name <nil>')
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mongo-2.12.4 spec/integration/connect_single_rs_name_spec.rb
mongo-2.11.6 spec/integration/connect_single_rs_name_spec.rb
mongo-2.12.3 spec/integration/connect_single_rs_name_spec.rb
mongo-2.12.2 spec/integration/connect_single_rs_name_spec.rb
mongo-2.11.5 spec/integration/connect_single_rs_name_spec.rb
mongo-2.12.1 spec/integration/connect_single_rs_name_spec.rb
mongo-2.12.0.rc0 spec/integration/connect_single_rs_name_spec.rb
mongo-2.11.4 spec/integration/connect_single_rs_name_spec.rb
mongo-2.11.3 spec/integration/connect_single_rs_name_spec.rb
mongo-2.11.2 spec/integration/connect_single_rs_name_spec.rb
mongo-2.11.1 spec/integration/connect_single_rs_name_spec.rb
mongo-2.11.0 spec/integration/connect_single_rs_name_spec.rb
mongo-2.11.0.rc0 spec/integration/connect_single_rs_name_spec.rb