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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
# frozen_string_literal: true
# rubocop:todo all
require 'lite_spec_helper'
require 'support/shared/protocol'
describe Mongo::Protocol::KillCursors do
let(:opcode) { 2007 }
let(:cursor_ids) { [123, 456, 789] }
let(:id_count) { cursor_ids.size }
let(:collection_name) { 'protocol-test' }
let(:database) { SpecConfig.instance.test_db }
let(:message) do
described_class.new(collection_name, database, cursor_ids)
end
describe '#initialize' do
it 'sets the cursor ids' do
expect(message.cursor_ids).to eq(cursor_ids)
end
it 'sets the count' do
expect(message.id_count).to eq(id_count)
end
end
describe '#==' do
context 'when the other is a killcursors' do
context 'when the cursor ids are equal' do
let(:other) do
described_class.new(collection_name, database, cursor_ids)
end
it 'returns true' do
expect(message).to eq(other)
end
end
context 'when the cursor ids are not equal' do
let(:other) do
described_class.new(collection_name, database, [123, 456])
end
it 'returns false' do
expect(message).not_to eq(other)
end
end
end
context 'when the other is not a killcursors' do
let(:other) do
expect(message).not_to eq('test')
end
end
end
describe '#hash' do
let(:values) do
message.send(:fields).map do |field|
message.instance_variable_get(field[:name])
end
end
it 'returns a hash of the field values' do
expect(message.hash).to eq(values.hash)
end
end
describe '#replyable?' do
it 'returns false' do
expect(message).to_not be_replyable
end
end
describe '#serialize' do
let(:bytes) { message.serialize }
include_examples 'message with a header'
describe 'zero' do
let(:field) { bytes.to_s[16..19] }
it 'serializes a zero' do
expect(field).to be_int32(0)
end
end
describe 'number of cursors' do
let(:field) { bytes.to_s[20..23] }
it 'serializes the cursor count' do
expect(field).to be_int32(id_count)
end
end
describe 'cursor ids' do
let(:field) { bytes.to_s[24..-1] }
it 'serializes the selector' do
expect(field).to be_int64_sequence(cursor_ids)
end
end
end
describe '#registry' do
context 'when the class is loaded' do
it 'registers the op code in the Protocol Registry' do
expect(Mongo::Protocol::Registry.get(described_class::OP_CODE)).to be(described_class)
end
it 'creates an #op_code instance method' do
expect(message.op_code).to eq(described_class::OP_CODE)
end
end
end
end
|