Sha256: 0119dee8cd32837c39ba810edb1fe36d84bec860efa9aeeb69bb1a4598f0e51b

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

# encoding: UTF-8
require_relative 'spec_helper'
require 'fluent/plugin/out_stdout'

# Capture the log output of the block given
def capture_log(&block)
  tmp = $log
  $log = StringIO.new
  yield
  return $log.string
ensure
  $log = tmp
end

describe Fluent::DebugInput do
  before { Fluent::Test.setup }

  def create_driver(conf=%[])
    Fluent::Test::InputTestDriver.new(Fluent::DebugInput).configure(conf)
  end

  describe 'test configure' do
    it { expect { create_driver }.not_to raise_error }
    it { expect { create_driver(%[debug_all true]) }.not_to raise_error }
  end
end

describe "debug_all" do
  # There is not suitable test driver ...
end

describe "extends Fluent::StdoutOutput" do
  before { Fluent::Test.setup }

  def create_driver(conf=CONFIG, tag = 'test')
    Fluent::Test::OutputTestDriver.new(Fluent::StdoutOutput, tag).configure(conf)
  end
  let(:driver) { create_driver(config) }

  describe 'test configure' do
    let(:config) { %[debug true] }
    let(:subject) { driver.instance }
    its(:debug) { should == true }
  end

  describe 'test emit' do
    let(:config) { %[debug true] }

    before {
      time = Fluent::Engine.now
      Fluent::Engine.stub(:now).and_return(time)
    }

    it 'should flush' do
      d = driver.instance
      out = capture_log do
        chain = Fluent::NullOutputChain.instance
        d.emit('tag', Fluent::OneEventStream.new(0, {'a'=>1}), chain)
      end
      debug_stdout, out_stdout = out.split("\n")
      debug_stdout.should_not be_nil
      debug_stdout.should == out_stdout
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fluent-plugin-debug-0.0.3 spec/in_debug_spec.rb
fluent-plugin-debug-0.0.2 spec/in_debug_spec.rb
fluent-plugin-debug-0.0.1 spec/in_debug_spec.rb