|
149 | 149 | end |
150 | 150 | end |
151 | 151 | end |
| 152 | + |
| 153 | + describe '#labels' do |
| 154 | + context 'when the result is nil' do |
| 155 | + subject do |
| 156 | + described_class.new('not master (10107)', nil, |
| 157 | + :code => 10107, :code_name => 'NotMaster') |
| 158 | + end |
| 159 | + |
| 160 | + it 'has no labels' do |
| 161 | + expect(subject.labels).to eq([]) |
| 162 | + end |
| 163 | + end |
| 164 | + |
| 165 | + context 'when the result is not nil' do |
| 166 | + |
| 167 | + let(:reply_document) do |
| 168 | + { |
| 169 | + 'code' => 251, |
| 170 | + 'codeName' => 'NoSuchTransaction', |
| 171 | + 'errorLabels' => labels, |
| 172 | + } |
| 173 | + end |
| 174 | + |
| 175 | + let(:reply) do |
| 176 | + Mongo::Protocol::Reply.new.tap do |r| |
| 177 | + # Because this was not created by Mongo::Protocol::Reply::deserialze, we need to manually |
| 178 | + # initialize the fields. |
| 179 | + r.instance_variable_set(:@documents, [reply_document]) |
| 180 | + r.instance_variable_set(:@flags, []) |
| 181 | + end |
| 182 | + end |
| 183 | + |
| 184 | + let(:result) do |
| 185 | + Mongo::Operation::Result.new(reply) |
| 186 | + end |
| 187 | + |
| 188 | + subject do |
| 189 | + described_class.new('Transaction has been aborted', result, |
| 190 | + :code => 251, :code_name => 'NoSuchTransaction') |
| 191 | + end |
| 192 | + |
| 193 | + context 'when the error has no labels' do |
| 194 | + |
| 195 | + let(:labels) do |
| 196 | + [] |
| 197 | + end |
| 198 | + |
| 199 | + it 'has the correct labels' do |
| 200 | + expect(subject.labels).to eq(labels) |
| 201 | + end |
| 202 | + end |
| 203 | + |
| 204 | + |
| 205 | + context 'when the error has labels' do |
| 206 | + |
| 207 | + let(:labels) do |
| 208 | + [ Mongo::Error::TRANSIENT_TRANSACTION_ERROR_LABEL ] |
| 209 | + end |
| 210 | + |
| 211 | + it 'has the correct labels' do |
| 212 | + expect(subject.labels).to eq(labels) |
| 213 | + end |
| 214 | + end |
| 215 | + end |
| 216 | + end |
152 | 217 | end |
0 commit comments