Sha256: a9a4d79e06437628e592de69a92eab784c8a70c20befe3e5e69fa06b63e5d13b

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

require 'helper'

class RewriteTagFilterOutputTest < Test::Unit::TestCase
  def setup
    Fluent::Test.setup
  end
  
  CONFIG = %[
    rewriterule1 domain ^www\.google\.com$ site.Google
    rewriterule2 domain ^news\.google\.com$ site.GoogleNews
    rewriterule3 agent "Mac OS X" agent.MacOSX
  ]

  def create_driver(conf=CONFIG,tag='test')
    Fluent::Test::OutputTestDriver.new(Fluent::RewriteTagFilterOutput, tag).configure(conf)
  end

  def test_configure
    assert_raise(Fluent::ConfigError) {
      d = create_driver('')
    }
    d = create_driver %[
      rewriterule1 domain ^www.google.com$ site.Google
      rewriterule2 domain ^news.google.com$ site.GoogleNews
    ]
    d.instance.inspect
    assert_equal 'domain ^www.google.com$ site.Google', d.instance.rewriterule1
    assert_equal 'domain ^news.google.com$ site.GoogleNews', d.instance.rewriterule2
  end

  def test_emit
    d1 = create_driver(CONFIG, 'input.access')
    time = Time.parse("2012-01-02 13:14:15").to_i
    d1.run do
      d1.emit({'domain' => 'www.google.com', 'path' => '/foo/bar?key=value', 'agent' => 'Googlebot', 'response_time' => 1000000})
      d1.emit({'domain' => 'news.google.com', 'path' => '/', 'agent' => 'Googlebot-Mobile', 'response_time' => 900000})
      d1.emit({'domain' => 'map.google.com', 'path' => '/', 'agent' => 'Macintosh; Intel Mac OS X 10_7_4', 'response_time' => 900000})
    end
    emits = d1.emits
    assert_equal 3, emits.length
    assert_equal 'site.Google', emits[0][0] # tag
    assert_equal 'site.GoogleNews', emits[1][0] # tag
    assert_equal 'news.google.com', emits[1][2]['domain']
    assert_equal 'agent.MacOSX', emits[2][0] #tag
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fluent-plugin-rewrite-tag-filter-0.0.7 test/plugin/test_out_rewrite_tag_filter.rb
fluent-plugin-rewrite-tag-filter-0.0.6 test/plugin/test_out_rewrite_tag_filter.rb
fluent-plugin-rewrite-tag-filter-0.0.5 test/plugin/test_out_rewrite_tag_filter.rb