class Fluent::Test::Driver::BaseOwner

Constants

Emit
ErrorEvent

Public Class Methods

new(klass, opts: {}, &block) click to toggle source
Calls superclass method Fluent::Test::Driver::Base::new
# File lib/fluent/test/driver/base_owner.rb, line 24
def initialize(klass, opts: {}, &block)
  super

  if opts
    @instance.system_config_override(opts)
  end
  @instance.log = TestLogger.new
  @logs = @instance.log.out.logs

  @event_streams = nil
  @error_events = nil
end

Public Instance Methods

configure(conf, syntax: :v1) click to toggle source
# File lib/fluent/test/driver/base_owner.rb, line 37
def configure(conf, syntax: :v1)
  if conf.is_a?(Fluent::Config::Element)
    @config = conf
  else
    @config = Config.parse(conf, "(test)", "(test_dir)", syntax: syntax)
  end

  if @instance.respond_to?(:router=)
    @event_streams = []
    @error_events = []

    driver = self
    mojule = Module.new do
      define_method(:event_emitter_router) do |label_name|
        TestEventRouter.new(driver)
      end
    end
    @instance.singleton_class.prepend mojule
  end

  @instance.configure(@config)
  self
end
emit_count() click to toggle source
# File lib/fluent/test/driver/base_owner.rb, line 103
def emit_count
  @event_streams.size
end
emit_error_event(tag, time, record, error) click to toggle source
# File lib/fluent/test/driver/base_owner.rb, line 69
def emit_error_event(tag, time, record, error)
  @error_events << ErrorEvent.new(tag, time, record, error)
end
emit_event_stream(tag, es) click to toggle source

via TestEventRouter

# File lib/fluent/test/driver/base_owner.rb, line 65
def emit_event_stream(tag, es)
  @event_streams << Emit.new(tag, es)
end
error_events(tag: nil) { |tag, time, record, error| ... } click to toggle source
# File lib/fluent/test/driver/base_owner.rb, line 111
def error_events(tag: nil)
  selected = @error_events.select{|e| tag.nil? ? true : e.tag == tag }
  if block_given?
    selected.each do |e|
      yield e.tag, e.time, e.record, e.error
    end
  else
    selected.map{|e| [e.tag, e.time, e.record, e.error] }
  end
end
event_streams(tag: nil) { |tag, es| ... } click to toggle source
# File lib/fluent/test/driver/base_owner.rb, line 91
def event_streams(tag: nil)
  return [] if @event_streams.nil?
  selected = @event_streams.select{|e| tag.nil? ? true : e.tag == tag }
  if block_given?
    selected.each do |e|
      yield e.tag, e.es
    end
  else
    selected.map{|e| [e.tag, e.es] }
  end
end
events(tag: nil) { |t, time, record| ... } click to toggle source
# File lib/fluent/test/driver/base_owner.rb, line 73
def events(tag: nil)
  if block_given?
    event_streams(tag: tag) do |t, es|
      es.each do |time, record|
        yield t, time, record
      end
    end
  else
    list = []
    event_streams(tag: tag) do |t, es|
      es.each do |time, record|
        list << [t, time, record]
      end
    end
    list
  end
end
record_count() click to toggle source
# File lib/fluent/test/driver/base_owner.rb, line 107
def record_count
  @event_streams.reduce(0) {|a, e| a + e.es.size }
end
run(expect_emits: nil, expect_records: nil, timeout: nil, start: true, shutdown: true, &block) click to toggle source
Calls superclass method Fluent::Test::Driver::Base#run
# File lib/fluent/test/driver/base_owner.rb, line 122
def run(expect_emits: nil, expect_records: nil, timeout: nil, start: true, shutdown: true, &block)
  if expect_emits
    @run_post_conditions << ->(){ emit_count >= expect_emits }
  end
  if expect_records
    @run_post_conditions << ->(){ record_count >= expect_records }
  end

  super(timeout: timeout, start: start, shutdown: shutdown, &block)
end