Sha256: ea122b1d4f5731c847ecf6f773070112b111c189432a0195bd25b5360cf5d557

Contents?: true

Size: 1.71 KB

Versions: 15

Compression:

Stored size: 1.71 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
require 'new_relic/agent/memory_logger'

class MemoryLoggerTest < Minitest::Test
  LEVELS = [:fatal, :error, :warn, :info, :debug]

  def setup
    @logger = NewRelic::Agent::MemoryLogger.new
  end

  def test_proxies_messages_to_real_logger_on_dump
    LEVELS.each do |level|
      @logger.send(level, "message at #{level}")
    end

    real_logger = mock

    # This is needed for the expectation on #warn (also defined in Kernel) to
    # work with old versions of Mocha.
    def real_logger.warn(*); end

    real_logger.expects(:fatal).with("message at fatal")
    real_logger.expects(:error).with("message at error")
    real_logger.expects(:warn).with("message at warn")
    real_logger.expects(:info).with("message at info")
    real_logger.expects(:debug).with("message at debug")

    @logger.dump(real_logger)
  end

  def test_proxies_multiple_messages_with_a_single_call
    @logger.info('a', 'b', 'c')

    real_logger = stub
    real_logger.expects(:info).with('a', 'b', 'c')

    @logger.dump(real_logger)
  end

  def test_proxies_message_blocks
    called = false
    @logger.info do
      called = true
      'a'
    end

    real_logger = stub
    real_logger.expects(:info).yields()

    @logger.dump(real_logger)
    assert called
  end

  def test_proxies_through_calls_to_log_exception
    e = Exception.new
    @logger.log_exception(:fatal, e, :error)

    real_logger = stub
    real_logger.expects(:log_exception).with(:fatal, e, :error)

    @logger.dump(real_logger)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
newrelic_rpm-3.12.0.288 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.11.2.286 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.11.1.284 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.11.0.283 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.10.0.279 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.9.275 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.8.273 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.7.266 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.6.257 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.5.251 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.4.245 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.3.241 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.2.239 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.1.236 test/new_relic/agent/memory_logger_test.rb
newrelic_rpm-3.9.0.229 test/new_relic/agent/memory_logger_test.rb