1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
require 'spec_helper'
describe 'DNS Seedlist Discovery' do
if test_connecting_externally?
include Mongo::ConnectionString
before(:all) do
module Mongo
class Server
# The constructor keeps the same API, but does not instantiate a
# monitor and run it.
alias :original_initialize :initialize
def initialize(address, cluster, monitoring, event_listeners, options = {})
@address = address
@cluster = cluster
@monitoring = monitoring
@options = options.freeze
@monitor = Monitor.new(address, event_listeners, options)
end
# Disconnect simply needs to return true since we have no monitor and
# no connection.
alias :original_disconnect! :disconnect!
def disconnect!;
true;
end
end
end
end
after(:all) do
module Mongo
class Server
alias :initialize :original_initialize
remove_method(:original_initialize)
alias :disconnect! :original_disconnect!
remove_method(:original_disconnect!)
end
end
end
DNS_SEEDLIST_DISCOVERY_TESTS.each do |file_name|
file = File.new(file_name)
spec = YAML.load(ERB.new(file.read).result)
file.close
test = Mongo::ConnectionString::Test.new(spec)
context(File.basename(file_name), if: test_connecting_externally?) do
context 'when the uri is invalid', if: test.raise_error? do
let(:valid_errors) do
[
Mongo::Error::InvalidTXTRecord,
Mongo::Error::NoSRVRecords,
Mongo::Error::InvalidURI,
Mongo::Error::MismatchedDomain,
]
end
let(:error) do
e = nil
begin; test.uri; rescue => ex; e = ex; end
e
end
it 'raises an error' do
expect(valid_errors).to include(error.class)
end
end
context 'when the uri is valid', unless: test.raise_error? do
it 'does not raise an exception' do
expect(test.uri).to be_a(Mongo::URI::SRVProtocol)
end
it 'creates a client with the correct hosts' do
expect(test.client).to have_hosts(test)
end
it 'creates a client with the correct options' do
expect(test.client).to match_options(test)
end
end
end
end
end
end
|