File: command_failed_spec.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (87 lines) | stat: -rw-r--r-- 2,128 bytes parent folder | download
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
# frozen_string_literal: true
# rubocop:todo all

require 'lite_spec_helper'

describe Mongo::Monitoring::Event::CommandFailed do

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

  let(:failure) do
    BSON::Document.new(test: 'value')
  end

  describe '#initialize' do
    context 'when the failure should be redacted' do
      context 'sensitive command' do
        let(:started_event) do
          double.tap do |evt|
            expect(evt).to receive(:sensitive).and_return(false)
          end
        end

        let(:event) do
          described_class.new(
            'copydb', 'admin', address, 1, 2, "msg", failure, 0.5, started_event: started_event
          )
        end

        it 'sets the failure to an empty document' do
          expect(event.failure).to be_empty
        end
      end

      context 'sensitive started event' do
        let(:started_event) do
          double.tap do |evt|
            expect(evt).to receive(:sensitive).and_return(true)
          end
        end

        let(:event) do
          described_class.new(
            'find', 'admin', address, 1, 2, "msg", failure, 0.5, started_event: started_event
          )
        end

        it 'sets the failure to an empty document' do
          expect(event.failure).to be_empty
        end
      end
    end
  end

  describe '#command_name' do
    let(:started_event) do
      double.tap do |evt|
        expect(evt).to receive(:sensitive).and_return(false)
      end
    end

    context 'when command_name is given as a string' do
      let(:event) do
        described_class.new(
          'find', 'admin', address, 1, 2, 'Uh oh', nil, 0.5, started_event: started_event
        )
      end

      it 'is a string' do
        expect(event.command_name).to eql('find')
      end
    end

    context 'when command_name is given as a symbol' do
      let(:event) do
        described_class.new(
          :find, 'admin', address, 1, 2, 'Uh oh', nil, 0.5, started_event: started_event
        )
      end

      it 'is a string' do
        expect(event.command_name).to eql('find')
      end
    end
  end
end