class Fluent::Test::BufferedOutputTestDriver

Attributes

tag[RW]

Public Class Methods

new(klass, tag='test', &block) click to toggle source
Calls superclass method Fluent::Test::InputTestDriver.new
# File lib/fluent/test/output_test.rb, line 50
def initialize(klass, tag='test', &block)
  super(klass, &block)
  @entries = []
  @expected_buffer = nil
  @tag = tag
end

Public Instance Methods

emit(record, time=Time.now) click to toggle source
# File lib/fluent/test/output_test.rb, line 59
def emit(record, time=Time.now)
  @entries << [time.to_i, record]
  self
end
expect_format(str) click to toggle source
# File lib/fluent/test/output_test.rb, line 64
def expect_format(str)
  (@expected_buffer ||= '') << str
end
run(&block) click to toggle source
Calls superclass method Fluent::Test::InputTestDriver#run
# File lib/fluent/test/output_test.rb, line 68
def run(&block)
  result = nil
  super {
    es = ArrayEventStream.new(@entries)
    buffer = @instance.format_stream(@tag, es)

    block.call if block

    if @expected_buffer
      assert_equal(@expected_buffer, buffer)
    end

    key = ''
    if @instance.respond_to?(:time_slicer)
      # this block is only for test_out_file
      time, record = @entries.first
      key = @instance.time_slicer.call(time)
    end
    chunk = MemoryBufferChunk.new(key, buffer)
    result = @instance.write(chunk)
  }
  result
end