Sha256: bbb5b994741270552a5021f8e7f832920d3e8cf2e0ab3c097d40893810001bab

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'fluent/test'
require 'fluent/plugin/out_unit_time_filter'
require 'tempfile'
require 'time'

RSpec.configure do |config|
  config.before(:all) do
    Fluent::Test.setup
  end
end

def tempfile(content)
  Tempfile.open("#{File.basename __FILE__}.#{$$}") do |f|
    f << content
    f.flush
    f.rewind
    yield(f)
  end
end

def run_driver(options = {})
  options = options.dup

  filter = options[:filter] || (<<-EOS)
proc {|rs|
  {
    'count'   => rs.count,
    'inspect' => rs.inspect
  }
}
  EOS

  option_keys = [
    :unit_sec,
    :prefix,
    :emit_each_tag,
    :pass_hash_row,
    :hash_row_time_key,
    :hash_row_tag_key,
  ]

  additional_options = option_keys.map {|key|
    if options[key]
      "#{key} #{options[key]}"
    end
  }.join("\n")

  tag = options[:tag] || 'test.default'

  tempfile(filter) do |f|
    fluentd_conf = <<-EOS
type unit_time_filter
filter_path #{f.path}
#{additional_options}
    EOS

    driver = Fluent::Test::OutputTestDriver.new(Fluent::UnitTimeFilterOutput, tag).configure(fluentd_conf)

    driver.run do
      yield(driver)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-unit-time-filter-0.1.0 spec/spec_helper.rb