class Fluent::Helper::PluginSpec::Driver

Attributes

instance[R]

Public Class Methods

new(plugin_klass, conf) click to toggle source
# File lib/fluent/helper/plugin_spec.rb, line 48
def initialize(plugin_klass, conf)
  @plugin_klass = plugin_klass
  Fluent::Helper::PluginEmitStub.register_target(plugin_klass)

  plugin = plugin_klass.new
  unless plugin.is_a?(Fluent::Input) || plugin.is_a?(Fluent::Output)
    raise ArgumentError, "unknown class as plugin #{plugin.class}"
  end

  logger = TestLogger.new

  conf = Fluent::Config.parse(conf, '[test config]')
  plugin.configure(conf)

  plugin_loglevel = plugin.instance_variable_get(:@log_level)
  if plugin_loglevel
    logger.log_level = plugin_loglevel
  end
  plugin.log = logger

  @instance = plugin
end

Public Instance Methods

events() click to toggle source
# File lib/fluent/helper/plugin_spec.rb, line 106
def events
  Fluent::Helper::PluginEmitStub.stored(@plugin_klass)
end
pitch(tag, time, record) click to toggle source
# File lib/fluent/helper/plugin_spec.rb, line 71
def pitch(tag, time, record)
  @instance.emit(tag, time, record)
end
pitches(tag, es) click to toggle source
# File lib/fluent/helper/plugin_spec.rb, line 75
def pitches(tag, es)
  @instance.emits(tag, es)
end
run() { |self| ... } click to toggle source
# File lib/fluent/helper/plugin_spec.rb, line 99
def run
  raise ArgumentError unless block_given?
  @instance.start
  yield self
  @instance.shutdown
end
with(tag, time=Time.now.to_i) { |batch_pitcher| ... } click to toggle source
# File lib/fluent/helper/plugin_spec.rb, line 94
def with(tag, time=Time.now.to_i)
  raise ArgumentError unless block_given?
  yield BatchPitcher.new(self, tag, time)
end