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 99 100 101 102 103 104
|
require 'spec_helper'
describe Mongo::Cluster::AppMetadata do
let(:app_metadata) do
described_class.new(cluster)
end
let(:cluster) do
authorized_client.cluster
end
describe '#initialize' do
context 'when the cluster has an app name option set' do
let(:cluster) do
authorized_client.with(app_name: :reports).cluster
end
it 'sets the app name' do
expect(app_metadata.send(:full_client_document)[:application][:name]).to eq(:reports)
end
context 'when the app name exceeds the max length of 128' do
let(:cluster) do
authorized_client.with(app_name: "\u3042"*43).cluster
end
it 'raises an error' do
expect {
app_metadata.send(:validate!)
}.to raise_exception(Mongo::Error::InvalidApplicationName)
end
end
end
context 'when the cluster does not have an app name option set' do
it 'does not set the app name' do
expect(app_metadata.send(:full_client_document)[:application]).to be(nil)
end
end
context 'when the client document exceeds the max of 512 bytes' do
context 'when the os.type length is too long' do
before do
allow(app_metadata).to receive(:type).and_return('x'*500)
end
it 'truncates the document' do
expect(app_metadata.send(:ismaster_bytes)).to be_a(String)
end
end
context 'when the os.name length is too long' do
before do
allow(app_metadata).to receive(:name).and_return('x'*500)
end
it 'truncates the document' do
expect(app_metadata.send(:ismaster_bytes)).to be_a(String)
end
end
context 'when the os.architecture length is too long' do
before do
allow(app_metadata).to receive(:architecture).and_return('x'*500)
end
it 'truncates the document' do
expect(app_metadata.send(:ismaster_bytes)).to be_a(String)
end
end
context 'when the platform length is too long' do
before do
allow(app_metadata).to receive(:platform).and_return('x'*500)
end
it 'truncates the document to be just an ismaster command' do
expect(app_metadata.send(:ismaster_bytes)).to be_a(String)
end
end
context 'when the driver info is too long' do
before do
allow(app_metadata).to receive(:driver_doc).and_return('x'*500)
end
it 'truncates the document to be just an ismaster command and the compressors', unless: compression_enabled? do
expect(app_metadata.ismaster_bytes.length).to eq(Mongo::Server::Monitor::Connection::ISMASTER_BYTES.length + 26)
end
end
end
end
end
|