Sha256: 4cfc495e9ca69b2d46785572eba65a7eb760692a5595ca43ecd3b6f9872449f3

Contents?: true

Size: 1.38 KB

Versions: 17

Compression:

Stored size: 1.38 KB

Contents

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'rr'
require 'test/unit'
class Test::Unit::TestCase
  include RR::Adapters::TestUnit
end

if ENV['SIMPLE_COV']
  require 'simplecov'
  SimpleCov.start do 
    add_filter 'test/'
    add_filter 'pkg/'
    add_filter 'vendor/'
  end
end

require 'test/unit'
require 'fluent/test'

# for testing

def unused_port
  s = TCPServer.open(0)
  port = s.addr[1]
  s.close
  port
end

# for MongoDB

require 'mongo'

MONGO_DB_DB = 'fluent_test'
MONGO_DB_PATH = File.join(File.dirname(__FILE__), 'plugin', 'data')

module MongoTestHelper
  @@setup_count = 0

  def cleanup_mongod_env
    system("killall mongod")
    system("rm -rf #{MONGO_DB_PATH}")
    system("mkdir -p #{MONGO_DB_PATH}")
  end

  def setup_mongod
    unless defined?(@@current_mongo_test_class) and @@current_mongo_test_class == self.class
      cleanup_mongod_env

      @@current_mongo_test_class = self.class
      @@mongod_port = unused_port
      @@pid = spawn(ENV['mongod'], "--port=#{@@mongod_port}", "--dbpath=#{MONGO_DB_PATH}")
      sleep 3
    end

    @@setup_count += 1;
  end

  def teardown_mongod
    if defined?(@@current_mongo_test_class)
      Mongo::Connection.new('localhost', @@mongod_port).drop_database(MONGO_DB_DB)
    end
    if @@setup_count == self.class.methods.size
      cleanup_mongod_env
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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