2009-12-01 18:49:57 +00:00
|
|
|
require 'test/test_helper'
|
2009-01-07 20:36:12 +00:00
|
|
|
|
|
|
|
# NOTE: assumes Mongo is running
|
|
|
|
class AdminTest < Test::Unit::TestCase
|
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
include Mongo
|
2009-01-07 20:36:12 +00:00
|
|
|
|
2009-08-20 22:48:09 +00:00
|
|
|
@@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
|
|
|
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
2009-02-05 15:10:41 +00:00
|
|
|
@@coll = @@db.collection('test')
|
|
|
|
|
2009-01-07 20:36:12 +00:00
|
|
|
def setup
|
|
|
|
# Insert some data to make sure the database itself exists.
|
2009-10-20 15:31:07 +00:00
|
|
|
@@coll.remove
|
2009-02-05 15:10:41 +00:00
|
|
|
@r1 = @@coll.insert('a' => 1) # collection not created until it's used
|
|
|
|
@@coll_full_name = 'ruby-mongo-test.test'
|
|
|
|
@admin = @@db.admin
|
2009-01-07 20:36:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2009-02-05 15:10:41 +00:00
|
|
|
@admin.profiling_level = :off
|
2009-10-20 15:31:07 +00:00
|
|
|
@@coll.remove if @@coll
|
2009-03-13 21:09:19 +00:00
|
|
|
@@db.error
|
2009-01-07 20:36:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_profiling_level
|
|
|
|
assert_equal :off, @admin.profiling_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_change_profiling_level
|
|
|
|
@admin.profiling_level = :slow_only
|
|
|
|
assert_equal :slow_only, @admin.profiling_level
|
|
|
|
@admin.profiling_level = :off
|
|
|
|
assert_equal :off, @admin.profiling_level
|
2009-03-02 15:49:27 +00:00
|
|
|
@admin.profiling_level = :all
|
|
|
|
assert_equal :all, @admin.profiling_level
|
|
|
|
begin
|
|
|
|
@admin.profiling_level = :medium
|
|
|
|
fail "shouldn't be able to do this"
|
|
|
|
rescue
|
|
|
|
end
|
2009-01-07 20:36:12 +00:00
|
|
|
end
|
|
|
|
|
2009-01-07 20:58:54 +00:00
|
|
|
def test_profiling_info
|
|
|
|
# Perform at least one query while profiling so we have something to see.
|
|
|
|
@admin.profiling_level = :all
|
2009-02-05 15:10:41 +00:00
|
|
|
@@coll.find()
|
2009-01-08 11:49:26 +00:00
|
|
|
@admin.profiling_level = :off
|
2009-01-07 20:58:54 +00:00
|
|
|
|
|
|
|
info = @admin.profiling_info
|
|
|
|
assert_kind_of Array, info
|
|
|
|
assert info.length >= 1
|
|
|
|
first = info.first
|
|
|
|
assert_kind_of String, first['info']
|
|
|
|
assert_kind_of Time, first['ts']
|
|
|
|
assert_kind_of Numeric, first['millis']
|
|
|
|
end
|
|
|
|
|
2009-01-07 21:12:01 +00:00
|
|
|
def test_validate_collection
|
2009-02-05 15:10:41 +00:00
|
|
|
doc = @admin.validate_collection(@@coll.name)
|
2009-02-03 17:31:08 +00:00
|
|
|
assert_not_nil doc
|
|
|
|
result = doc['result']
|
|
|
|
assert_not_nil result
|
|
|
|
assert_match /firstExtent/, result
|
2009-01-07 21:12:01 +00:00
|
|
|
end
|
|
|
|
|
2009-01-07 20:36:12 +00:00
|
|
|
end
|