Sha256: 5cf66fb087e9dd974b5cf93e9de91d59fd5ed57479b8739ddb3620f407d94db0

Contents?: true

Size: 1.7 KB

Versions: 17

Compression:

Stored size: 1.7 KB

Contents

require 'test_helper'

class MongoTagCollectionTest < Test::Unit::TestCase
  def setup
    Fluent::Test.setup
    require 'fluent/plugin/out_mongo'
  end

  CONFIG = %[
    type mongo
    database fluent
    tag_mapped
    remove_tag_prefix should.remove.
  ]

  def create_driver(conf = CONFIG)
    Fluent::Test::BufferedOutputTestDriver.new(Fluent::MongoOutput) {
      def start
        super
      end

      def shutdown
        super
      end

      def operate(collection, records)
        [format_collection_name(collection), records]
      end

      def get_or_create_collection(collection_name)
        collection_name
      end

      def mongod_version
        "2.0.0"
      end
    }.configure(conf)
  end

  def test_configure
    d = create_driver(CONFIG)
    assert_equal(/^should\.remove\./, d.instance.instance_variable_get(:@remove_tag_prefix))
  end

  def emit_documents(d)
    time = Time.parse("2011-01-02 13:14:15 UTC").to_i
    d.emit({'a' => 1}, time)
    d.emit({'a' => 2}, time)
    time
  end

  def test_write
    skip('BufferedOutputTestDriver should support emit arguments(chain and key)')

    d = create_driver(CONFIG)
    d.tag = 'mytag'
    t = emit_documents(d)
    mock(d.instance).operate('mytag', [{'a' => 1, d.instance.time_key => Time.at(t)},
                                       {'a' => 2, d.instance.time_key => Time.at(t)}])
    d.run
  end

  def test_remove_prefix_collection
    d = create_driver(CONFIG)
    assert_equal('prefix', d.instance.__send__(:format_collection_name, 'should.remove.prefix'))
    assert_equal('test', d.instance.__send__(:format_collection_name, '..test..'))
    assert_equal('test.foo', d.instance.__send__(:format_collection_name, '..test.foo.'))
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fluent-plugin-mongo-0.7.10 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.9 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.8 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.7 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.6 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.5 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.4 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.3 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.2 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.1 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.7.0 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.6.13 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.6.12 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.6.11 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.6.10 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.6.9 test/plugin/out_mongo_tag_mapped.rb
fluent-plugin-mongo-0.6.8 test/plugin/out_mongo_tag_mapped.rb