File: command_log_subscriber_spec.rb

package info (click to toggle)
ruby-mongo 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,332 kB
  • sloc: ruby: 45,579; makefile: 5
file content (76 lines) | stat: -rw-r--r-- 1,616 bytes parent folder | download | duplicates (4)
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
require 'spec_helper'

describe Mongo::Monitoring::CommandLogSubscriber do

  describe '#started' do

    let(:filter) do
      (1...100).reduce({}) do |hash, i|
        hash[i] = i
        hash
      end
    end

    let(:command) do
      { find: 'users', filter: filter }
    end

    let(:event) do
      Mongo::Monitoring::Event::CommandStarted.new(
        'find',
        'users',
        Mongo::Address.new('127.0.0.1:27017'),
        12345,
        67890,
        command
      )
    end

    before do
      Mongo::Logger.level = Logger::DEBUG
    end

    after do
      Mongo::Logger.level = Logger::INFO
    end

    context 'when truncating the logs' do

      context 'when no option is provided' do

        let(:subscriber) do
          described_class.new
        end

        it 'truncates the logs at 250 characters' do
          expect(subscriber).to receive(:truncate).with(command).and_call_original
          subscriber.started(event)
        end
      end

      context 'when true option is provided' do

        let(:subscriber) do
          described_class.new(truncate_logs: true)
        end

        it 'truncates the logs at 250 characters' do
          expect(subscriber).to receive(:truncate).with(command).and_call_original
          subscriber.started(event)
        end
      end
    end

    context 'when not truncating the logs' do

      let(:subscriber) do
        described_class.new(truncate_logs: false)
      end

      it 'does not truncate the logs' do
        expect(subscriber).to_not receive(:truncate)
        subscriber.started(event)
      end
    end
  end
end