Sha256: 10339465b93f6df50a25cb20ba8939e19e457238b2bfec5188c50bfc8edb8e57

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe Mongo::Cluster::Topology::Single do

  let(:address) do
    Mongo::Address.new('127.0.0.1:27017')
  end

  let(:topology) do
    described_class.new({})
  end

  describe '.servers' do

    let(:mongos) do
      Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
    end

    let(:standalone) do
      Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
    end

    let(:standalone_two) do
      Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
    end

    let(:replica_set) do
      Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
    end

    let(:mongos_description) do
      Mongo::Server::Description.new(address, { 'msg' => 'isdbgrid' })
    end

    let(:standalone_description) do
      Mongo::Server::Description.new(address, { 'ismaster' => true, 'ok' => 1 })
    end

    let(:replica_set_description) do
      Mongo::Server::Description.new(address, { 'ismaster' => true, 'setName' => 'testing' })
    end

    before do
      mongos.monitor.instance_variable_set(:@description, mongos_description)
      standalone.monitor.instance_variable_set(:@description, standalone_description)
      standalone_two.monitor.instance_variable_set(:@description, standalone_description)
      replica_set.monitor.instance_variable_set(:@description, replica_set_description)
    end

    let(:servers) do
      topology.servers([ mongos, standalone, standalone_two, replica_set ])
    end

    it 'returns only the first standalone server' do
      expect(servers).to eq([ standalone ])
    end
  end

  describe '.replica_set?' do

    it 'returns false' do
      expect(topology).to_not be_replica_set
    end
  end

  describe '.sharded?' do

    it 'returns false' do
      expect(topology).to_not be_sharded
    end
  end

  describe '.single?' do

    it 'returns true' do
      expect(topology).to be_single
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongo-2.0.5 spec/mongo/cluster/topology/single_spec.rb
mongo-2.0.4 spec/mongo/cluster/topology/single_spec.rb
mongo-2.0.3 spec/mongo/cluster/topology/single_spec.rb