More tests. Fixed some db client bugs.
This commit is contained in:
parent
bc30e7239a
commit
acf5cc994b
|
@ -63,16 +63,18 @@ module XGen
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection(name)
|
def collection(name)
|
||||||
|
# We do not implement the Java driver's optional strict mode, which
|
||||||
|
# throws an exception if the collection does not exist.
|
||||||
create_collection(name)
|
create_collection(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def drop_collection(name)
|
def drop_collection(name)
|
||||||
coll = collection(name)
|
coll = collection(name)
|
||||||
return true if coll == nil
|
return true if coll == nil
|
||||||
col.drop_indexes
|
coll.drop_indexes # Mongo requires that we drop indexes manually
|
||||||
|
|
||||||
doc = db_command(:drop => name)
|
doc = db_command(:drop => name)
|
||||||
o = md['ok']
|
o = doc['ok']
|
||||||
return o.kind_of?(Numeric) && o.to_i == 1
|
return o.kind_of?(Numeric) && o.to_i == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,21 +9,21 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
@db = XGen::Mongo::Driver::Mongo.new.db('ruby-mongo-test')
|
@db = XGen::Mongo::Driver::Mongo.new.db('ruby-mongo-test')
|
||||||
@coll = @db.collection('test')
|
@coll = @db.collection('test')
|
||||||
@coll.clear
|
@coll.clear
|
||||||
|
@coll.insert('a' => 1) # collection not created until it's used
|
||||||
|
@coll_full_name = 'ruby-mongo-test.test'
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@coll.clear
|
@coll.clear unless @db.socket.closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_clear
|
def test_clear
|
||||||
@coll.insert('a' => 1)
|
|
||||||
assert_equal 1, @coll.count
|
assert_equal 1, @coll.count
|
||||||
@coll.clear
|
@coll.clear
|
||||||
assert_equal 0, @coll.count
|
assert_equal 0, @coll.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_insert
|
def test_insert
|
||||||
@coll.insert('a' => 1)
|
|
||||||
@coll.insert('a' => 2)
|
@coll.insert('a' => 2)
|
||||||
@coll.insert('b' => 3)
|
@coll.insert('b' => 3)
|
||||||
|
|
||||||
|
@ -34,4 +34,45 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
assert docs.include?('a' => 2)
|
assert docs.include?('a' => 2)
|
||||||
assert docs.include?('b' => 3)
|
assert docs.include?('b' => 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_close
|
||||||
|
@db.close
|
||||||
|
assert @db.socket.closed?
|
||||||
|
begin
|
||||||
|
@coll.insert('a' => 1)
|
||||||
|
fail "expected IOError exception"
|
||||||
|
rescue IOError => ex
|
||||||
|
assert_match /closed stream/, ex.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_drop_collection
|
||||||
|
assert @db.drop_collection(@coll.name), "drop of collection #{@coll.name} failed"
|
||||||
|
assert_equal 0, @db.collection_names.length
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_collection_names
|
||||||
|
names = @db.collection_names
|
||||||
|
assert_equal 1, names.length
|
||||||
|
assert_equal 'ruby-mongo-test.test', names[0]
|
||||||
|
|
||||||
|
coll2 = @db.collection('test2')
|
||||||
|
coll2.insert('a' => 1) # collection not created until it's used
|
||||||
|
names = @db.collection_names
|
||||||
|
assert_equal 2, names.length
|
||||||
|
assert names.include?('ruby-mongo-test.test')
|
||||||
|
assert names.include?('ruby-mongo-test.test2')
|
||||||
|
ensure
|
||||||
|
@db.drop_collection('test2')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_collections_info
|
||||||
|
cursor = @db.collections_info
|
||||||
|
rows = cursor.collect
|
||||||
|
assert_equal 1, rows.length
|
||||||
|
row = rows[0]
|
||||||
|
assert_equal @coll_full_name, row['name']
|
||||||
|
# Mongo bug: returns string with wrong length, so last byte of value is chopped off.
|
||||||
|
# assert_equal @coll.name, row['options']['create']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue