Sha256: 9bc974ee32915123608aae61b9f94c8d905e7a86bcff18ff76f7c362493003a6

Contents?: true

Size: 969 Bytes

Versions: 3

Compression:

Stored size: 969 Bytes

Contents

require_relative '../test_helper'

module Appender
  class KafkaTest < Minitest::Test
    describe SemanticLogger::Appender::Kafka do
      before do
        @appender = SemanticLogger::Appender::Kafka.new(
          seed_brokers: ['http://localhost:9092']
        )
        @message  = 'AppenderKafkaTest log message'
      end

      after do
        @appender.close if @appender
      end

      it 'sends log messages in JSON format' do
        message = nil
        options = nil
        ::Kafka::Producer.stub_any_instance(:produce, -> value, **opts { message = value; options = opts }) do
          @appender.info(@message)
          @appender.flush
        end

        h = JSON.parse(message)
        assert_equal 'info', h['level']
        assert_equal @message, h['message']
        assert_equal "SemanticLogger::Appender::Kafka", h['name']
        assert_equal $$, h['pid']

        assert_equal 'log_messages', options[:topic]
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
semantic_logger-4.2.0 test/appender/kafka_test.rb
semantic_logger-4.1.1 test/appender/kafka_test.rb
semantic_logger-4.1.0 test/appender/kafka_test.rb