Sha256: d04973046a6a4ce3335c3f4fabb42f80fe984ec13d59e52c0fa3fa517986ebd7

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'helper'

require 'webmock/test_unit'
WebMock.disable_net_connect!

class EC2MetadataOutputTest < Test::Unit::TestCase

  CONFIG = %[
    output_tag ${instance_id}.${tag}
    aws_key_id aws_key
    aws_sec_key aws_sec
    <record>
      name ${tagset_name}
      instance_id ${instance_id}
      az ${availability_zone}
    </record>
  ]

  def setup
    Fluent::Test.setup
    @time = Fluent::Engine.now
  end

  def create_driver(conf=CONFIG, tag='test')
    Fluent::Test::OutputTestDriver.new(Fluent::EC2MetadataOutput, tag).configure(conf)
  end

  test 'configure' do
    VCR.use_cassette('ec2') do
      d = create_driver
      assert_equal("${instance_id}.${tag}", d.instance.output_tag)
      assert_equal("aws_key", d.instance.aws_key_id)
      assert_equal("aws_sec", d.instance.aws_sec_key)
    end
  end

  test 'emit' do
    VCR.use_cassette('ec2') do
      d = create_driver

      d.run do
        d.emit("a" => 1)
        d.emit("a" => 2)
      end

      # tag
      assert_equal "i-0c0c0000.test", d.emits[0][0]
      assert_equal "i-0c0c0000.test", d.emits[1][0]

      # record
      mapped = { 'instance_id' => 'i-0c0c0000', 'az' => 'ap-northeast-1b', 'name' => 'instance-name' }
      assert_equal [
        {"a" => 1}.merge(mapped),
        {"a" => 2}.merge(mapped),
      ], d.records
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-ec2-metadata-0.0.9 test/plugin/test_out_ec2_metadata.rb