Sha256: 86035d678aba45af3cd8c632b5af8e82e624874492a3a8c9f1786323ba1c0af0

Contents?: true

Size: 1.77 KB

Versions: 6

Compression:

Stored size: 1.77 KB

Contents

require 'test_helper'

class CloudwatchLogsInputTest < Test::Unit::TestCase
  include CloudwatchLogsTestHelper

  def setup
    Fluent::Test.setup
    require 'fluent/plugin/in_cloudwatch_logs'

  end

  def teardown
    clear_log_group
  end

  def test_configure
    d = create_driver(<<-EOC)
      type cloudwatch_logs
      aws_key_id test_id
      aws_sec_key test_key
      region us-east-1
      tag test
      log_group_name group
      log_stream_name stream
      state_file /tmp/state
    EOC

    assert_equal('test_id', d.instance.aws_key_id)
    assert_equal('test_key', d.instance.aws_sec_key)
    assert_equal('us-east-1', d.instance.region)
    assert_equal('test', d.instance.tag)
    assert_equal('group', d.instance.log_group_name)
    assert_equal('stream', d.instance.log_stream_name)
    assert_equal('/tmp/state', d.instance.state_file)
  end

  def test_emit
    create_log_stream

    time_ms = (Time.now.to_f * 1000).floor
    put_log_events([
      {timestamp: time_ms, message: '{"cloudwatch":"logs1"}'},
      {timestamp: time_ms, message: '{"cloudwatch":"logs2"}'},
    ])

    sleep 5

    d = create_driver
    d.run do
      sleep 5
    end

    emits = d.emits
    assert_equal(2, emits.size)
    assert_equal(['test', (time_ms / 1000).floor, {'cloudwatch' => 'logs1'}], emits[0])
    assert_equal(['test', (time_ms / 1000).floor, {'cloudwatch' => 'logs2'}], emits[1])
  end

  private
  def default_config
    <<-EOC
      tag test
      type cloudwatch_logs
      log_group_name #{log_group_name}
      log_stream_name #{log_stream_name}
      state_file /tmp/state
      #{aws_key_id}
      #{aws_sec_key}
      #{region}
    EOC
  end

  def create_driver(conf = default_config)
    Fluent::Test::InputTestDriver.new(Fluent::CloudwatchLogsInput).configure(conf)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fluent-plugin-cloudwatch-logs-0.0.7 test/plugin/test_in_cloudwatch_logs.rb
fluent-plugin-cloudwatch-logs-0.0.6 test/plugin/test_in_cloudwatch_logs.rb
fluent-plugin-cloudwatch-logs-0.0.5 test/plugin/test_in_cloudwatch_logs.rb
fluent-plugin-cloudwatch-logs-0.0.4 test/plugin/test_in_cloudwatch_logs.rb
fluent-plugin-cloudwatch-logs-0.0.3 test/plugin/test_in_cloudwatch_logs.rb
fluent-plugin-cloudwatch-logs-0.0.2 test/plugin/test_in_cloudwatch_logs.rb