Sha256: 3b60013c412613f82fb3cf85e853653cf34dbbd0435dd383eceff7168d6a30d3

Contents?: true

Size: 1.58 KB

Versions: 81

Compression:

Stored size: 1.58 KB

Contents

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

Version data entries

81 entries across 78 versions & 3 rubygems

Version Path
mongo-2.13.3 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.14.1 spec/mongo/monitoring/command_log_subscriber_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongo-2.8.0/spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.15.0.alpha spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.13.2 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.14.0 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.14.0.rc1 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.13.1 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.12.4 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.11.6 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.13.0 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.12.3 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.13.0.rc1 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.12.2 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.10.5 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.11.5 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.13.0.beta1 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.12.1 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.12.0.rc0 spec/mongo/monitoring/command_log_subscriber_spec.rb
mongo-2.11.4 spec/mongo/monitoring/command_log_subscriber_spec.rb