Sha256: 43230152bb12e42bb97165dbff259b7af8775a001a6fc3cd61cf67ea8cfa9b88

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

require 'helper'

class EC2MetadataOutputTest < Test::Unit::TestCase
  def setup
    Fluent::Test.setup
  end

  CONFIG = %[
    output_tag ${instance_id}.${tag}
    <record>
      instance_id ${instance_id}
    </record>
  ]

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

  def get_instance_id
    Net::HTTP.get_response('169.254.169.254', '/latest/meta-data/instance-id').body
  end

  def test_emit
    d = create_driver(CONFIG, 'foo.bar')

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

    instance_id = get_instance_id

    # tag
    assert_equal "#{instance_id}.foo.bar", d.emits[0][0]
    assert_equal "#{instance_id}.foo.bar", d.emits[1][0]

    # record
    mapped = { 'instance_id' => instance_id }
    assert_equal [
      {"a" => 1}.merge(mapped),
      {"a" => 2}.merge(mapped),
    ], d.records
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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