Sha256: a7fdf5ec8f4f1eddc3df7ffb2fd24f185ff8df4a2051b4b524d8cb765d61edca

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

# encoding: UTF-8
require_relative 'spec_helper'

describe Fluent::RecordReformerOutput do
  before { Fluent::Test.setup }
  CONFIG = %[
    type reformed
    output_tag reformed.${tag}

    hostname ${hostname}
    tag ${tag}
    time ${time.strftime('%S')}
    message ${hostname} ${tags.last} ${message}
  ]
  let(:tag) { 'test.tag' }
  let(:tags) { tag.split('.') }
  let(:hostname) { Socket.gethostname.chomp }
  let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::RecordReformerOutput, tag).configure(config) }

  describe 'test configure' do
    describe 'good configuration' do
      subject { driver.instance }

      context "check default" do
        let(:config) { CONFIG }
      end
    end
  end

  describe 'test emit' do
    let(:time) { Time.now }
    let(:emit) do
      driver.run do
        driver.emit({'foo'=>'bar', 'message' => 1}, time.to_i)
        driver.emit({'foo'=>'bar', 'message' => 2}, time.to_i)
      end
    end

    let(:config) { CONFIG }
    before do
      Fluent::Engine.stub(:now).and_return(time)
      Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
        'foo' => 'bar',
        'hostname' => hostname,
        'tag' => tag,
        'time' => time.strftime('%S'),
        'message' => "#{hostname} #{tags.last} 1",
      })
      Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
        'foo' => 'bar',
        'hostname' => hostname,
        'tag' => tag,
        'time' => time.strftime('%S'),
        'message' => "#{hostname} #{tags.last} 2",
      })
    end
    it { emit }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluent-plugin-record-reformer-0.1.0 spec/out_record_reformer_spec.rb
fluent-plugin-record-reformer-0.0.3 spec/out_record_reformer_spec.rb