Sha256: 1b1c74a02661ba660fe83b01ee1715939262122e77923f3880bda32a702275de

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# So that the NewRelic appender will load the mock
$LOAD_PATH.unshift File.dirname(__FILE__)
require_relative '../test_helper'

# Unit Test for SemanticLogger::Appender::NewRelic
module Metric
  class NewRelicTest < Minitest::Test
    describe SemanticLogger::Appender::NewRelic do

      before do
        @appender = SemanticLogger::Metric::NewRelic.new
        @message  = 'AppenderNewRelicTest log message'
      end

      it 'logs counter metric' do
        name = amount = nil
        NewRelic::Agent.stub(:increment_metric, -> name_, amount_ { name = name_, amount = amount_ }) do
          @appender.info(message: @message, metric: 'User/authenticated')
        end
        assert_equal 'Custom/User/authenticated', name.first
        assert_equal 1, amount
      end

      it 'logs duration metric' do
        name = duration = nil
        NewRelic::Agent.stub(:record_metric, -> name_, duration_ { name = name_, duration = duration_ }) do
          @appender.measure_info(message: @message, metric: 'User/authenticate') do
            sleep 0.001
          end
        end
        assert_equal 'Custom/User/authenticate', name.first
        assert duration
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
semantic_logger-4.2.0 test/metric/new_relic_test.rb